Working with OverlayFS
OverlayFS stacks filesystems on top of each other - it can turn e.g. a SquashFS filesystem along with an ext4 filesystem into what appears to be writable SquashFS (the writes happen on the ext4 filesystem, unmodified data comes from SquashFS).
Upstream overlayfs documentation is here.
The general idea is
mount -t overlay overlay -olowerdir=/lower,upperdir=/upper,workdir=/work /merged
Where /lower is a read-only directory (e.g. on squashfs), upperdir is an overlayed directory on a writable filesystem, and workdir is a working directory on the same partition as upperdir where the changes will be stored. /merged is the mount point for what will become the pseudo-writable squashfs.
In the context of an Android init.rc, mounting overlayfs can look like this:
mount squashfs /dev/block/mmcblk0p3 /system-ro ro
mount ext4 /dev/block/mmcblk0p4 /system-rw
mount overlay overlay /system lowerdir=/system-ro,upperdir=/system-rw/system,workdir=/system-rw/work
The filesystem on /system-rw in this context has to be an ext4 filesystem with /system and /work directories in it. The contents of /system will be overlayed on top of the squashfs /system-ro.
OverlayFs (last modified 2017-04-03 07:47:05)