overlayfs for Jetson

Just after I wrote the above, I’ve figured it out myself, thanks to some hints in this repo GitHub - JetsonHacksNano/rootOnUSB: Set rootfs to be on a USB drive! So here it goes:

I found that the scripts from this project here, developed for the Raspberry Pi, works perfectly for the Nano: GitHub - JasperE84/root-ro: Read-only root filesystem for Raspbian Stretch (using overlay)

The only thing that’s different is the installation procedure, so don’t run the install.sh script on the Nano:

sudo -i # root shell

# Change a few things in /etc/initramfs-tools so that overlayfs is used on startup to mount a ready-only root
echo overlay >> /etc/initramfs-tools/modules
wget https://raw.githubusercontent.com/JasperE84/root-ro/master/etc/initramfs-tools/hooks/root-ro -O /etc/initramfs-tools/hooks/root-ro
wget https://raw.githubusercontent.com/JasperE84/root-ro/master/etc/initramfs-tools/scripts/init-bottom/root-ro -O /etc/initramfs-tools/scripts/init-bottom/root-ro
chmod +x /etc/initramfs-tools/hooks/root-ro
chmod +x /etc/initramfs-tools/scripts/init-bottom/root-ro

# Update the initrd file
update-initramfs -u

# Now, the file /boot/initrd.img-4.9.140-tegra contains the above modifications.
# There is also the symbolic link in /boot/initrd.img pointing to it, but this doesn't
# actually get loaded on startup. By default /boot/initrd (without extension) is loaded.
# So change /boot/extlinux/extlinux.conf so that it actually gets loaded:
# Search for `INITRD /boot/initrd` and replace it with `INITRD /boot/initrd.img`:
if ! grep -q "INITRD /boot/initrd.img" /boot/extlinux/extlinux.conf; then sed -i "s/INITRD \/boot\/initrd/INITRD \/boot\/initrd.img/" /boot/extlinux/extlinux.conf; fi

# Before rebooting, also add the helper scripts from JasperE84/root-ro:
wget https://raw.githubusercontent.com/JasperE84/root-ro/master/reboot-to-readonly-mode.sh -O /root/reboot-ro
wget https://raw.githubusercontent.com/JasperE84/root-ro/master/reboot-to-writable-mode.sh -O /root/reboot-rw
chmod +x /root/reboot-ro
chmod +x /root/reboot-rw

Now you should be able to run sudo /root/reboot-ro to boot into RO mode, and sudo /root/reboot-rw to boot back into RW mode.

4 Likes