Specifications
This is easy. Let's assume "/" is the read-only root file system and /dev/mtdblock5 contains a small JFFS2
flash partition that shall be used to store modifications made by application "/usr/bin/autoPilot":
# mount -t jffs2 /dev/mtdblock5 /tmp/sto
# insmod mini_fo.o
# mount -t mini_fo -o base=/,sto=/tmp/sto/ / /mnt/mini_fo/
# cd /mnt/mini_fo/
# chroot . /usr/bin/autoPilot
The mini_fo file system is mounted with "/" as base directory, "/tmp/sto/" as storage directory to the mount
point "/mnt/mini_fo". After that, chroot(1) is used to start the application with the new file system root
"/mnt/mini_fo". All modifications made by the application will be stored to the JFFS2 file system in /tmp/sto.
Starting the whole system system in chrooted overlayed environment
This is more interesting, and a bit trickier, as mounting needs to be done during system startup after the root
file system has been mounted, but before init is started. The best way to do this is to have a script that mounts
the mini_fo file system on top of root and then starts init in the chrooted overlayed environment. For example
assume the following script "overlay_init", stored in /sbin/:
#!/bin/bash
#
# mount mini_fo overlay file system and execute init
#
# make sure these exist in the read-only file system
STORAGE=/tmp/sto
MOUNT_POINT=/mnt/mini_fo/
# mount tmpfs as storage file system with a maximum size of 32MB
mount -t tmpfs -o rw,size=32M none $STORAGE
/sbin/modprobe mini_fo
mount -t mini_fo -o base=/,sto=$STORAGE / $MOUNT_POINT
exec /usr/sbin/chroot $MOUNT_POINT /sbin/init
echo "exec chroot failed, bad!"
exec /bin/sh
exit 1
Now its easy to choose between a mini_fo overlayed and the regular non overlayed system just by setting
the "init" kernel parameter in the boot loader to "init=/sbin/overlay_init".
Tips
pivot_root(1) can be used with chroot if there is need to access the original non overlayed root
file system from the chrooted overlayed environment.
•
Performance overhead
The mini_fo file system is inserted as an additional layer between the VFS and the native file system, and
thus creates some overhead that varies strongly depending of the operation performed.
modifying a regular file for the first time
This results in a copy of the original file beeing created in the storage directory, that is then modified.
Overhead depends on the size of the modified file.
1.
Starting a single application in a chrooted overlayed environment 128