Posts: 39
Joined: Wed Feb 08, 2012 6:55 pm

Readonly rootfs

Tue Mar 05, 2013 3:32 am

What is the best way to mount root as readonly? Will everything (openbox, etc) even function with a RO filesystem?

It seems I can modify /etc/fstab and add the ro flag to / and that should do it. However, can I then remount root manually to make it writable if necessary, or am I then stuck and the only recourse is to mount the SD card in another linux box and edit /etc/fstab back?


Posts: 39
Joined: Wed Feb 08, 2012 6:55 pm

Re: Readonly rootfs

Tue Mar 05, 2013 5:33 am

To answer a couple of my questions, yes that modification to /etc/fstab does mount rootfs as read only.

And yes, it can be remounted as writable in order to make changes if necessary:

Code: Select all

sudo mount -n -o remount,rw /
However, neither Openbox nor Apache are starting up with the read-only filesystem. So the trick will be configuring them to work in that way.

Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Readonly rootfs

Tue Mar 05, 2013 5:42 am

You'll probably want to mount /var/run and /var/log as a ramdisk
They need write access to those 2 directories at least.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

Posts: 37
Joined: Thu Feb 28, 2013 6:07 am

Re: Readonly rootfs

Wed Mar 06, 2013 12:27 am

Run a 'find' command to find which files are being written, then you'll have an idea what to tweak. The 'ofiles' command may help as well.

Investigate and see if you can boot linux so that it's booting off a ram disk, then when the plug is pulled nothing important is lost. On the next boot it uses the sd card again for the ram disk image. Solaris did this for the os install; it ran off a ram disk while installing the os from a cd/dvd to the hd.

Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Readonly rootfs

Wed Mar 06, 2013 8:18 am

I would use the "lsof" command instead, to see what files are open when something is running. grep for the package in question, to just view the output for the files being accessed by it.

Makes sense that dynamic applications cannot run if you deprive them of a place to write their logs and caches.
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

Posts: 917
Joined: Sun Jul 29, 2012 9:06 pm

Re: Readonly rootfs

Thu Mar 07, 2013 7:21 am

Some files have to remain writable. Some modules also expect the logfiles in /var/log to exist.
You can create a tarrball of those folders. At boot, you can create a ramdisk and create a symlink to that for the files and folders that needs rw access. Next you untar the tarball into that ramdisk. Also disable the swap option as it became useless. You can use an usb stick instead of a ramdisk if you need to examine the logfiles after a reboot. Temporary mounting rw is great to alter settings.

Return to “Advanced users”