OverlayFS

Sun Jan 19, 2025

Instead of having a read-only (ro) filesystem like pi-star, or foregoing the concept altogether like WPSD, I decided to use an overlayfs like OpenWRT on your router.

This means we have a safe, untouched root partition, but it behaves as if it’s fully read-write (rw) because all changes get stored in /overlay.

This gives us a nice capability in that we can, more easily than WPSD or other systems:

  • at a glance, know what’s been changed from stock
  • ‘factory reset’ with no effort whatsoever (just delete everything in /overlay/upper and reboot)
  • limited-factory reset, preserving configs while resetting everything else

All this at no real cost to the user.

It might also simplify OS upgrades, but for now I don’t handle those - upgrading as normal will put all the OS files on /overlay. At worst, this costs us 400MB of wasted disk space.

How does it work? The kernel boots to partition 2 as normal, and then loads /sbin/preinit as the init command line parameter.

preinit mounts partition 3 to /overlay, does some housekeeping (like extending partition 3 to use the rest of the disk), sets up the overlay mount, and then pivot_roots and calls the real /sbin/init.

I leaned heavily on the OpenWRT source and kernel docs to get this going.

I really like it!