Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save atlury/59acd6bdf73237faa469 to your computer and use it in GitHub Desktop.
Save atlury/59acd6bdf73237faa469 to your computer and use it in GitHub Desktop.
Set up Arch Linux ARM on Raspberry Pi to boot from and use a read-only file-system

##Read-only FS on Arch Linux ARM

Unlike your typical computer where you usually shutdown properly, I cannot rely on this during the use of my Raspberry Pi. If the Raspberry Pi is improperly shutdown too many times, data corruption in the file system leading to unbootable SD card may result. So we should use a read-only file system.

Full instructions and explanations are obtained from this link but you can run these commands directly. I modified some of the instructions for personal convenience.

#Update everything first, remove cache then reboot to detect problems
pacman -Syu  
#May be needed if the pacman version has changed during the update
pacman-db-upgrade
#Optional if you want to clear the cache
pacman -Sc
reboot

#Change timezone (optional)
rm /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Singapore /etc/localtime

#Relocate DNS cache (This step causes DNS problems on the latest Arch Linux ARM kernels so skip this)
#rm /etc/resolv.conf
#ln -s /tmp/resolv.conf /etc/resolv.conf

#Adjust /etc/fstab, add/modify to the following hashed lines. Mount certain directories to RAM disk.
nano /etc/fstab
#Add the following lines up to the #end. Include the first commented line in case you have to set to write enabled next time.
#/dev/mmcblk0p1  /boot           vfat    defaults        0       0
/dev/mmcblk0p1  /boot   vfat    defaults,ro,errors=remount-ro        0       0
tmpfs   /var/log    tmpfs   nodev,nosuid    0   0
tmpfs   /var/tmp    tmpfs   nodev,nosuid    0   0
#end

#To mount / partition as read-only
nano /boot/cmdline.txt
#Replace the "rw" flag with the "ro" flag right after the root= parameter.

#Disable systemd services
systemctl disable systemd-readahead-collect
systemctl disable systemd-random-seed
systemctl disable ntpd

#Put shortcut shell scripts to re-enable read-write temporarily if needed
printf "mount -o remount,rw /" > writeenable.sh
printf "mount -o remount,ro /" > readonly.sh
chmod 500 writeenable.sh
chmod 500 readonly.sh

#Change your password if needed (Optional)
passwd

#Remove history
history -c -w

reboot

To enable read-write temporarily to do say an update, just run ./writeenable.sh.

References

  1. Read-only file system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment