How-to: Raspbian read-only root-fs

> Wiki Home > Raspberry Pi > How-to: Raspbian read-only root-fs

The following instructions will convert your Raspbian to R/O

Source: http://blog.gegg.us/2014/03/a-raspbian-read-only-root-fs-howto/ 

 

Remove some stuff which is not needed or unsuitable for readonly operation:

sudo su
apt-get remove --purge  logrotate dphys-swapfile
apt-get autoremove --purge

Install busybox syslog instead of rsyslog:

The reason for doing this is because we do not want logfiles, but we want to be able to do some debugging (read logfiles). busybox-syslogd does not write logfiles but logs to a ring-buffer in memory which can be displayed using the logread command:

apt-get install busybox-syslogd
dpkg --purge rsyslog

The following steps are important, because we do not want any filesystem checks on our headless system at all!

Comment do_start in /etc/init.d/checkroot.sh
Comment do_start in /etc/init.d/checkfs.sh

...
case "$1" in
start|"")
#do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
# No-op
;;
*)
echo "Usage: checkfs.sh [start|stop]" >&2
exit 3
;;
esac
...

Comment the highlighted operations in /etc/init.d/checkroot-bootclean.sh

...
case "$1" in
start|"")
# Clean /tmp, /lib/init/rw, /run and /run/lock. Remove the
# .clean files to force initial cleaning. This is intended
# to
# allow cleaning of directories masked by mounts while the
# system was previously running, which would otherwise
# prevent
# them being cleaned.
#rm -f /tmp/.clean /lib/init/rw/.clean /run/.clean /run/lock/.clean

#clean_all
exit $?
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
# No-op
;;
*)
echo "Usage: checkroot-bootclean.sh [start|stop]" >&2
exit 3
;;
esac
...

Comment swaponagain ‘swapfile’ in /etc/init.d/mountall.sh

Remove a couple of startup scripts:

insserv -r bootlogs
insserv -r fake-hwclock

Change /etc/fstab as follows:

proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults,ro 0 2
/dev/mmcblk0p2 / ext4 defaults,ro 0 1
tmpfs /tmp tmpfs defaults 0 0

append ro in /boot/cmdline.txt:
… elevator=deadline rootwait ro
Make dhclient write its leases file to /tmp instead of /var/lib/dhcp/:

rm -rf /var/lib/dhcp/
ln -s /tmp /var/lib/dhcp

That’s it!

To quickly flip back to R/W mode, lets create a script:

sudo nano /usr/local/bin/rw

With the following content:

#!/usr/bin/env bash
sudo mount / -o remount,rw

Make it executable:

chmod +x /usr/local/bin/rw

..and another one to flip it back to r/o mode

sudo nano /usr/local/bin/ro

With the following content:

#!/usr/bin/env bash
sudo mount / -o remount,ro

Make it executable:

chmod +x /usr/local/bin/ro

To switch to R/W mode just type “rw”, go back to R/O y typing in “ro”

Page views: 1410