ecdye / zram-config

A complete zram-config utility for swap, directories, and logs to reduce SD, NAND and eMMC block wear.
MIT License
412 stars 53 forks source link

doesn't sync on reboot #41

Closed mstormi closed 3 years ago

mstormi commented 3 years ago

I have a problem of zram data sometimes to disappear on reboot. It's an intermittent problem.

I've debugged an instance where the lazy unmount apparent didn't work and the routine returned without calling mergeOverlay() On another occasion, it called mergeOverlay() but it didn't have files to sync although I create a date file before reboot in both cases. Now as the shutdown sequence proceeded, data was lost.

Is it intentional to regularly/lazy unmount BEFORE mergeOverlay() ?

StuartIanNaylor commented 3 years ago

Its a race condition that MergeOverlay should always be run unmounted, so MergeOverlay says. I have waiting patiently for OverLayFS official tools, but nothing happening.

Its going to be a catch 22 if not unmounted then data could be lost as it will be written after. It will not be merged down because we could not unmount prob due file access.

I didn't write MergeOverlay maybe you can ask which is worst / best scenario

mstormi commented 3 years ago

While the mergeOverlay problem may still exist or not (there were recent changes on the overlayfs-tools), it wasn't the problem here.

The problem was that the upper FS actually can get unmounted on shutdown BEFORE zram-config.service stop gets executed. I've setup a script to store / restore zram dir contents on start(boot) / stop (reboot) of the zram-sync service but it didn't sync upper FS contents to a permanent storage on disk. Reason being that the zram dirs get (or actually can get) unmounted before store ... on reboot/final.target, systemd sends a stop to ALL running services and it's coincidence whether that happens before or after zram-config/stop . I didn't find out which service is the culprit but I found a way around. The key is to insert RequireMountsFor=/opt/zram/zram1/upper or similar into zram-config.service Will provide a patch once I can confirm it's working.