In order to make Zynthian more “Live Friendly” and tolerant of unexpected power down, I am looking into what is required to bring overlayFS into Zynthian.
OverlayFS provides a shadow filesystem so that the root filesystem can be mounted as read-only. When a reboot or normal shutdown is performed, a sync operation occurs and the root file system is mounted as read-write, and the modified files are copied to the SD card and then the filesystem is returned to read-only status before final shutdown.
I started by following the instructions above. I found that I needed to add /root to the list of directories and filesystem that are used as overlayFS.
I forked the domoticz repo on github: https://github.com/hansrune/domoticz-contrib and I am making the changes for Zynthian specific. This will simlify the instructions below as I make improvements.
The first time the sync operations are run, it takes a really long time (minutes) to shutdown/sync the filesystem, so patience is required.
These are the overlayFS directories:
The following is mounted RO, but is not an overlayFS:
Start with a fresh image
Full Installer - one script to do the whole install
(Working as of 2019-05-18T04:00:00Z)
>chmod a+rx full_install.sh
Step by step instructions (Working as of 2019-05-18T04:00:00Z)
>systemctl disable dphys-swapfile
>apt-get install fuse lsof
Get the fetch utility and fetch required files:
>chmod a+rx get_files.sh
Run the Installer
Enable the service
>systemctl enable syncoverlayfs.service
Change the boot commandline
>sed -i.bak -e “s/$/ noswap fastboot ro/” /boot/cmdline.txt
Prepare the overlays directories
This can take a LONG time to complete, at least 20 minutes on a fast SD card.
REBOOT, and enjoy
Extra Credit, verify
>mount -v “overlay”
overlay on /root type overlay (rw,relatime,lowerdir=/root_org,upperdir=/root_rw/upper,workdir=/root_rw/work)
overlay on /home type overlay (rw,relatime,lowerdir=/home_org,upperdir=/home_rw/upper,workdir=/home_rw/work)
overlay on /var type overlay (rw,relatime,lowerdir=/var_org,upperdir=/var_rw/upper,workdir=/var_rw/work)
overlay on /etc type overlay (rw,relatime,lowerdir=/etc_org,upperdir=/etc_rw/upper,workdir=/etc_rw/work)
Check for Read Only
> mount -v | grep “^/”
/dev/mmcblk0p2 on / type ext4 (ro,noatime,data=ordered)
/dev/mmcblk0p1 on /boot type vfat (ro,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
The / and /boot filesystems should be ro for read-only. To make changes to /boot, or make changes from the webconf, use the following command to make /boot and / read-write
To return to read-only mode:
To check that ram-swap is disabled:
>free -m | grep Swap
Swap: 0 0 0