Make the mount points of the overlayfs visible via config option #193
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Considering that the Performance option of
raspi-config
allows a minimal configuration of the Overlay File System, this is a proof of concept for making the mount points of the OverlayFS visible via configuration option, based on the idea in this thread. A new step in the wizard is added for this; the default is to make the mount points invisible, as per the current setting; when they are visible, their root directory is /run, like the following (referring to a Raspberry Pi Zero W):This configuration is still safe because the physical mount point (lower) is in read-only mode.
The
/run/upper
mount point allows inspection of the changes, for instance, to monitor their growth (viadu
or standard commands). Any changes here are not persistent, as the/run/upper
filesystem is a tempfs in RAM. The/run/lower
mount point is a read-only filesystem, so any possible access is safe for the SD card.The new step in the wizard is the following:
If No is selected (default), the output (after the reboot) is the standard overlay mode, with no visible mount points:
The following command will monitor the growth of the upper filesystem (e.g., files changed after a reboot) by listing the first 10 largest directories:
This PR also includes some improvements to the batch (command line) mode:
If status is missing, a usage summary is printed.
(Notice that best practices suggest that the whole SD card is in read-only mode, including the boot partition, as physically consumer SD cards have no partition concept (and no fault tolerance), so any write inconsistency (also to the boot partition) can drive an SD corruption if not appropriately completed.)
Even if all preliminary tests of this patch appear to be fine, long-term stability needs monitoring for some additional time.
Usage notes
Formally, OverlayFS does not support merging changes from an upper filesystem to a lower filesystem and changes to the lower filesystem are not allowed. This premised, empirically I succeeded in mounting the lower filesystem in read-write via the following command:
Then I could make permanent changes to the SD card by copying (
cp -p
) files from the upper part to the lover part; if a file is changed in the lower part, it persists to a reboot. After making changes, I could return back to read-only mode with the following command:Also, I could change the
/run/upper
filesystem, provided that after the changes the overlayfs is remounted throughInteresting to note that an adequate application of changes to the
/run/upper
filesystem followed by the remount of the OverlayFS allows reverting changes.Example:
Notice that the above methods have been empirically tested; they appear to work, even if the official documentation does not report them.
Maintenance notes
By periodically monitoring /run/upper with
df -h|sort -k5 -h
,cd /run/upper/data&&sudo du -h|sort -hr|head -
andsudo tree -dh /run/upper
I noticed that the growth of two resources have to be controlled: packagekit and journald: when the OverlayFS is active, the first one need to be stopped and disabled, while the second one might benefit from a configuration to limit its size.The following script can be added to crontab
@reboot
:As per the journald service, in the hypothesis that only user-1000 (pi) and system user ids are used, the script should result in making journald produce up to 10 files under /var/log/journal/ (including rotated files), where each one has size of 6,3 MB, with a total consumption of max 63 MB.
More generally, it is necessary to avoid the memory full condition of the OverlayFS by periodically monitoring the “/run/upper” usage size. Typical elements to check are:
On a Raspberry Pi Zero W, the max size of /run/upper will be about 215 MB.
Notice that when the usage size reaches 100%, a crash might occur; on a Raspberry Pi Zero W, this can be detected by monitoring the ACT led, intercepting when it repeatedly blinks with the following pattern: about 200 short blinks within 0.5 secs + 0.5 sec blink (constantly repeated).
To avoid the OverlayFS saturation condition, a periodic reboot can be issued when the OverlayFS usage exceeds 90% via the following script, which can be added to crontab, to be run every day (e.g.,
0 2 * * * /home/pi/OverlayFSMonitor
):When the growth of the previously mentioned resources is correctly maintained, the above memory full condition in the script (producing the reboot) should occur very rarely, for example after many months of uninterrupted operation.