Whilst an operating system is running the programs it runs will occasionally write data to the file system. If power is removed from the Raspberry Pi (or any computer for that matter) whilst it is running, it is possible that the file systems in use by the operating system may become corrupted. In addition SD cards have a limited life span in terms of the number of writes they can perform.
To protect our SD card from corruption and to maximise its lifespan we can use
overlayfs to create a writeable “layer” for the OS to use (in memory) on top of the actual file system which is mounted read-only.
To make Arch Linux packages you must run the
makepkg command as a non-root user.
Install required packages:
pacman -S fakeroot sudo git arch-install-scripts
Build package and install package:
su - neil git clone https://github.com/nils-werner/raspi-overlayroot cd raspi-overlayroot makepkg exit pacman -S ~neil/raspi-overlayroot/overlayroot-0.2-1-any.pkg.tar.xz
/etc/mkinitcpio.conf and add overlayroot to HOOKS array:
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck overlayroot)
/etc/fstab to make
/boot read-only at next boot:
/dev/mmcblk0p1 /boot vfat defaults,ro 0 0
overlayroot to the end of
/boot/cmdline.txt and mount
root=/dev/mmcblk0p2 ro rootwait console=ttyAMA0,115200 console=tty1 selinux=0 plymouth.enable=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 kgdboc=ttyAMA0,115200 elevator=noop overlayroot
When you login you will now see a warning that any changes the file system will be non-persistent. You can use the
rwrootfs command to remount all file systems as read-write inside a chroot shell. After exiting the shell, the file systems will remain read-write until you next reboot.
For system upgrades it is recommended that you make the root and
/boot file systems read-write in
To do so, run the
rwrootfs command perform the following file edits:
/boot/cmdline: remove overlayroot and change
rw` for ``/boot
Then reboot. The root and
/boot file systems will now be mounted read/write once more.