How to make rootfs read-only?

I try to make my rootfs read-only. I thought that I better use overlay filesystem for this purpose (I don't have other alternatives now).

Yet, after many trials and changing fstab, I can't manage to find any fstab which manage to start ubuntu with rootfs as readonly. I also googled itm but found no examples. This is what I tried, and I also tried many variations (options column), but still get error in overlay mount.

As you can see, the main changes are adding "ro" to the rootfs, and adding overlay for /etc /var and /home.

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
UUID=075d905c-5c56-4eae-9402-5a880d108a8c / ext4 ro,errors=remount-ro 0 1
/dev/sdb /media/store ext4 defaults 1 1
# swap was on /dev/sda5 during installation
UUID=e190d8d1-5490-4ef5-9547-a38aefa44b3e none swap sw 0 0
/root/myswapfile swap swap defaults 0 0
overlay /var overlay rw,noatime,lowerdir=/var,upperdir=/media/store /1,workdir=/media/store /11 0 2
overlay /etc overlay rw,noatime,lowerdir=/etc,upperdir=/media/store /2,workdir=/media/store /22 0 2
overlay /home overlay rw,noatime,lowerdir=/home,upperdir=/media/store /3,workdir=/media/store /33 0 2

Overlay is supported in my kernel, and things does works if I change my rootfs option in ftab from ro to writebale, but I need it read-only!

Thanks for any idea,

ranran

1 Answer

Check out the Protecting the Root Filesystem on Ubuntu with Overlayroot article about the creation of a read-only root FS.

It seems that you are running in the recurse issue with the temp fs.

Try booting the system with the / mounted read-only (no overlays!). This will lead to too many errors during the startup, but the system will boot. Then login as root and manually try to mount the overlays.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like