Read-only Root-FS for most Linux distributions using OverlayFS. Just like the package overlayroot
in Ubuntu but it will work on almost all distributions.
Forked from: https://wiki.psuter.ch/doku.php?id=solve_raspbian_sd_card_corruption_issues_with_read-only_mounted_root_partition
chmod +x /sbin/overlayRoot.sh
init=/sbin/init
to init=/sbin/overlayRoot.sh
.In general, the script will mount a OverlayFS over the original root file system using tmpfs as upper layer.
/etc/fstab
./mnt/overlay
, create /mnt/overlay/upper
, /mnt/overlay/work
, /mnt/overlay/newroot
./mnt/lower
./mnt/lower
as lower, /mnt/overlay/upper
and /mnt/overlay/work
as upper and work directory, /mnt/overlay/newroot
as merged destination.pivot_root
to /mnt/overlay/newroot
and put old root to /mnt
./mnt/mnt/lower
(the original /mnt/lower
) to /lower
, /mnt/mnt/overlay
(the original /mnt/overlay
) to /overlay
./mnt
(the original root file system)./sbin/init
and continue the init process.The upstream project is only compatible with Raspbian and has not been updated for years. Thus I add some patches to make it work on almost all Linux distributions.
noOverlayRoot
to your kernel parameter./etc/fstab
, this script will get rootfs mount point information from it. only UUID, PARTUUID, LABLE and raw device is supported but use PARTUUID remain not recommended./sbin/init
.
FIX: Simply replace all
/sbin/init
in this script to the value of your distribution use (for example:sed -i 's|/sbin/init|/init|g' overlayRoot.sh
).
/etc/fstab
or doesn't have it during the very early stage of init.
FIX: Manually add rootfs mount information in your
/etc/fstab
.
FIX: Use another kernel. Change distribution. etc...
FIX: Move this script to initramfs.
Ask me on Issues or Discussions.