Skip to content

Instantly share code, notes, and snippets.

@eusoubrasileiro
Last active June 10, 2022 13:14
Show Gist options
  • Save eusoubrasileiro/630c1ffa77d682d0520c737962b22cfe to your computer and use it in GitHub Desktop.
Save eusoubrasileiro/630c1ffa77d682d0520c737962b22cfe to your computer and use it in GitHub Desktop.
jetson nano overlay read only filesystem (example /var folder)
# To prevent SD card corruption due powercuts etc. without /boot/inird
# this code can be used to protect any directory on your filesystem
# directory you know has lots of I/O
# Overlay mounts a union filesystem (or directory tree) where upper directory is protected
# This is an example for /var folder making it read only
# rw is done only on RAM (/dev/shm) hence logs etc. are lost on reboot
# create folders needed by overlay filesystem on /dev/shm (RAM)
mkdir -p /dev/shm/var_upper /dev/shm/var_workdir /dev/shm/var_overlay
mkdir -p /var_
# since /var will be 'hidden' by overlay mouting 'over' it
# we need it 'visible' somewhere to be usable as lowerdir
# mount --bind does that to /var_
mount --bind /var /var_
sudo mount -t overlay overlay -o lowerdir=/var_,upperdir=/dev/shm/var_upper,workdir=/dev/shm/var_workdir /var
# This code is safe for reboot since unbind will be done automatically
# and everything will got back to its default
# can be replicated to any other folder that needs read-only protection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment