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.
https://www.domoticz.com/wiki/Setting_up_overlayFS_on_Raspberry_Pi
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: GitHub - hansrune/domoticz-contrib: Contribution / added files for Domoticz home automation 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:
- /var
- /etc
- /root
- /home
The following is mounted RO, but is not an overlayFS:
- /boot
Start with a fresh image
https://os.zynthian.org/2019-05-17-zynthianos-stretch-lite-1.0.0.zip
Full Installer - one script to do the whole install
(Working as of 2019-05-18T04:00:00Z)
>cd /tmp
>wget https://github.com/smiths73v3/overlayFS/raw/master/scripts/full_install.sh
>chmod a+rx full_install.sh
>./full_install.sh
>reboot
Step by step instructions (Working as of 2019-05-18T04:00:00Z)
Disable Swap
>dphys-swapfile swapoff
>dphys-swapfile uninstall
>systemctl disable dphys-swapfile
Install packages
>apt-get install fuse lsof
Get the fetch utility and fetch required files:
>cd /tmp
>wget https://github.com/smiths73v3/overlayFS/raw/master/scripts/get_files.sh
>chmod a+rx get_files.sh
>./get_files.sh
Run the Installer
>./install_parts.sh
Enable the service
>systemctl daemon-reload
>systemctl enable syncoverlayfs.service
Change the boot commandline
>sed -i.bak -e “s/$/ noswap fastboot ro/” /boot/cmdline.txt
Update fstab
>./fixup_fstab.sh
Prepare the overlays directories
This can take a LONG time to complete, at least 20 minutes on a fast SD card.
>./movefs.sh
REBOOT, and enjoy
>reboot
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
>rootrw
To return to read-only mode:
>rootro
To check that ram-swap is disabled:
>free -m | grep Swap
Swap: 0 0 0