Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay: Add option for /persistent directory to survive reboots #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mariusmarais
Copy link

This adds an optional persistent directory that will survive reboots.

A user opts in by creating a /persistent directory before enabling the overlay.

During boot, if the /persistent directory exists, it will be mounted in read/write mode, making its content survive reboots.

But why?
Persist some data across reboots while still keeping 99.9% of the system read-only.

Anything written there will survive reboots, including via symlinks from the rest of the system.
(The symlinks should normally be created before enabling the overlay, otherwise they won't survive the reboot themselves.)

After enabling:

pi@raspberrypi:~ $ mount
overlay on / type overlay (rw,noatime,lowerdir=/lower,upperdir=/upper/data,workdir=/upper/work)
/dev/mmcblk0p2 on /persistent type ext4 (rw,relatime)
/dev/mmcblk0p1 on /boot type vfat (ro,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
...

Note: Only /persistent is available, not the entire root partition.

If `/persistent` directory exists, it will be remounted over the overlay, allowing its content to survive reboots.
The `/persistent` directory must be created before the enabling the overlay.
@Ircama
Copy link

Ircama commented May 12, 2022

As far as I know, the SD card should be considered safe (e.g., against power failures) if its whole data is in read-only mode (consumer SD cards do not physically map logical filesystem partitions). In your case, if one is writing to /persistent while a power failure occurs, the SD card might risk becoming corrupted.

@mariusmarais
Copy link
Author

Sure, if that is your concern. Otherwise it is a probability thing: (a) power failure exactly when you're writing to a specific location, or (b) at any point really as things are generally running and writing.

If you put a live MySQL DB in there all bets are off.

The original reasoning was actually not to protect against SD card failure -- I used this while booting from USB in any case. I wanted a 99.9% immutable system since that's easier to manage and script. But this was clearly the wrong place to contribute 😄

@Ircama
Copy link

Ircama commented May 12, 2022

Ah, ok. I was considering this because of the rw remount. Your usage of mount --bind just after the overlay mount, on a resource which is going to be hidden, is interesting.

@mariusmarais
Copy link
Author

mariusmarais commented May 13, 2022

Looking at it now, I can't actually recall exactly why it's done like that anymore, but I think it was partly to make the script diff easier to understand. Also, not taking wildly different branches for this feature, but rather just adding a little something. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants