chuckhendo
Posts: 2
Joined: Sat Nov 10, 2012 5:20 pm

How to make Raspbian read only?

Sat Nov 10, 2012 7:16 pm

I am using Raspbian installed on an SD card in a kiosk like environment. I want it so that the Pi can be unplugged without a shutdown. However, often times it won't boot after this happens.

I was thinking setting the file system up as read only would fix this. However, if I mount root as ro it won't boot; I'm assuming because it's trying to write. How should I go about fixing this?

micerinos
Posts: 74
Joined: Fri Nov 09, 2012 11:15 am
Location: Madrid, Spain

Re: How to make Raspbian read only?

Sun Nov 11, 2012 10:49 pm

Hi chuckhendo,
you can find good information here: http://wiki.debian.org/ReadonlyRoot. To summarize:

1) mount /var/log and /tmp in ram (here 30MB per each):
edit /etc/default/rcS

Code: Select all

RAMTMP=yes
edit /etc/fstab

Code: Select all

        tmpfs           /tmp            tmpfs   nodev,nosuid,size=30M,mode=1777    0    0
        tmpfs           /var/log        tmpfs   nodev,nosuid,size=30M,mode=1777    0    0
        /dev/mmcblk0p2  /               ext2    defaults,ro,noatime,errors=remount-ro  0       1
        /dev/mmcblk0p3  /home       ext4    defaults,noatime                              0       1
It is good to have a rw home partition, or desktop session will fail to start. With this configuration you won't be able to upgrade packages, as apt and dpkg need /var/lib and /var/cache writable. Consider using a rw /var or per-subdirectory configuration.

2) edit /etc/init.d/hwclock.sh
in line 60 (the first of start case) change "-f" to "-L"

3) edit /etc/environment

Code: Select all

BLKID_FILE="/var/local/blkid.tab"
4) fix mtab

Code: Select all

    sudo rm /etc/mtab
    sudo ln -s /proc/self/mounts /etc/mtab
5) If you use apache, edit /etc/init.d/apache2 to create /var/log/apache2 on start.

6) If you have writable /var, there's a nice trick to update your system. Edit file /etc/apt/apt.conf

Code: Select all

DPkg {
    // Auto re-mounting of a readonly /
    Pre-Invoke { "mount -o remount,rw /"; };
    Post-Invoke { "test ${NO_APT_REMOUNT:-no} = yes || mount -o remount,ro / || true"; };
};
And apt-get will remount as rw before calling dpkg and remount as ro afterwards. If you set the variable NO_APT_REMOUNT to -no it won't do the ro remount, so you can configure the recently installed packages.

This configuration works for me. Right now, I'm trying to boot from a unionfs root filesystem with a ro ext2 and rw ext4. The plan is to have a cron script that each hour remounts rw, syncs the important directories (/etc, /bin, /sbin, /usr, /opt, /lib, /var, /srv) between the ro and rw filesystems, and remounts ro. I'm trying to minimize problems due to power sortage.

Cheers

chuckhendo
Posts: 2
Joined: Sat Nov 10, 2012 5:20 pm

Re: How to make Raspbian read only?

Tue Nov 13, 2012 7:11 pm

Very valuable information, thank you! I have heard that there are some issues with SD card write leveling causing corruption unrelated to file system writes. Have you had any issues with this? My Pi is currently not booting and I'm beginning to wonder if it's a defective card...

micerinos
Posts: 74
Joined: Fri Nov 09, 2012 11:15 am
Location: Madrid, Spain

Re: How to make Raspbian read only?

Tue Nov 13, 2012 9:36 pm

I received my raspi one week ago, so I cannot tell. In general, I don't think physical damage due to incorrect wear levelling is a dramatic problem. Not sure if rpi has a specific hardware problem with SDs, though. What I did experienced was a usb drive fried after a power outage (it entered an eternal and irreversible Write Protect state: you can read it, but not write... almost metaphysical stuff!). However, I cannot be sure whether it was rpi's fault or usb's. It was a sandisk cruzer fit, and It's a very common problem with those units. In your case, is the card physically broken, or only unbootable?

munklefish
Posts: 93
Joined: Tue Oct 02, 2012 5:35 pm
Location: Neumarkt in der Oberpfalz

Re: How to make Raspbian read only?

Wed Nov 14, 2012 3:27 pm

I strongly suggest good quality SD cards. I never shutdown my pi properly, i just pull the plug and Ive never had a corruption issue. So, that would make me think your pulling of the plug is coincidental to your corrupt data issue.
http://www.codeclinic.de

User avatar
Burngate
Posts: 6553
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore

Re: How to make Raspbian read only?

Wed Nov 14, 2012 5:00 pm

munklefish wrote:I strongly suggest good quality SD cards. I never shutdown my pi properly, i just pull the plug and Ive never had a corruption issue. So, that would make me think your pulling of the plug is coincidental to your corrupt data issue.
I cross the road outside my house without looking every day, and I've never been knocked down. So, that would make me think your crossing the road without looking is coincidental to your being knocked down issue.

munklefish
Posts: 93
Joined: Tue Oct 02, 2012 5:35 pm
Location: Neumarkt in der Oberpfalz

Re: How to make Raspbian read only?

Wed Nov 14, 2012 5:05 pm

Burngate wrote:
munklefish wrote:I strongly suggest good quality SD cards. I never shutdown my pi properly, i just pull the plug and Ive never had a corruption issue. So, that would make me think your pulling of the plug is coincidental to your corrupt data issue.
I cross the road outside my house without looking every day, and I've never been knocked down. So, that would make me think your crossing the road without looking is coincidental to your being knocked down issue.
Well to be fair the foundation themselves you just pull the plug to switch it off.

Also why be an idiot????? If you dont think my opinion is valid, keep it to yourself or say something constructive.
http://www.codeclinic.de

User avatar
Burngate
Posts: 6553
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore

Re: How to make Raspbian read only?

Wed Nov 14, 2012 5:49 pm

munklefish wrote:Well to be fair the foundation themselves you just pull the plug to switch it off.
... After you've shut down
munklefish wrote:Also why be an idiot????? If you dont think my opinion is valid, keep it to yourself or say something constructive.
Just 'cos you've had no problem yet doesn't mean nobody will
Is that constructive enough?

varesa
Posts: 5
Joined: Fri Jul 13, 2012 11:36 am

Re: How to make Raspbian read only?

Fri Nov 16, 2012 8:54 pm

munklefish wrote:
I strongly suggest good quality SD cards. I never shutdown my pi properly, i just pull the plug and Ive never had a corruption issue. So, that would make me think your pulling of the plug is coincidental to your corrupt data issue.
It's not really about the card quality. Think what might happen if the OS has a file transfer in the middle of writing a file in the background as you pull out the card, or if an application is doing something on a set of files.

The next time you start the OS, there will be broken and half-written files, which can cause applications to crash if they try to read them.

Do you shutdown your desktop computer the same way, by holding down the power button / pulling the cord?

munklefish
Posts: 93
Joined: Tue Oct 02, 2012 5:35 pm
Location: Neumarkt in der Oberpfalz

Re: How to make Raspbian read only?

Fri Nov 16, 2012 9:29 pm

True but a fast card would help reduce the risk. And how are we so sure the plug pulling is the cause????
http://www.codeclinic.de

milhouse
Posts: 642
Joined: Mon Jan 16, 2012 12:59 pm

Re: How to make Raspbian read only?

Fri Nov 16, 2012 11:33 pm

munklefish wrote:True but a fast card would help reduce the risk.
No it won't.
munklefish wrote:And how are we so sure the plug pulling is the cause????
Common sense? A basic understanding of how computers and storage works?

micerinos
Posts: 74
Joined: Fri Nov 09, 2012 11:15 am
Location: Madrid, Spain

Re: How to make Raspbian read only?

Sun Nov 18, 2012 10:50 am

Hi,
I just posted a different method for read only root filesystem on raspbian. You may find it interesting.
Cheers

micerinos
Posts: 74
Joined: Fri Nov 09, 2012 11:15 am
Location: Madrid, Spain

Re: How to make Raspbian read only?

Sun Nov 18, 2012 10:51 am

Ooops, I forgot to add the link!
Here is the thing: http://www.raspberrypi.org/phpBB3/viewt ... 29&t=23154

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to make Raspbian read only?

Sun Nov 18, 2012 12:08 pm

micerinos wrote:Ooops, I forgot to add the link!
Here is the thing: http://www.raspberrypi.org/phpBB3/viewt ... 29&t=23154
That's very interesting, but I doubt most people are going to be able to go through all those hoops (downloading this and that, patching this and that, compiling that, installing this, ...).

Do you have a "ready-to-go" downloadable version of it?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

micerinos
Posts: 74
Joined: Fri Nov 09, 2012 11:15 am
Location: Madrid, Spain

Re: How to make Raspbian read only?

Tue Nov 20, 2012 12:28 am

Yes, you are right. I forgot about the prêt-à-porter version ;) You can find it here with some brief instructions to make it work:
http://www.raspberrypi.org/phpBB3/viewt ... 57#p217757

Cheers

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to make Raspbian read only?

Tue Nov 20, 2012 8:08 am

Thanks.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

KMM
Posts: 3
Joined: Sat Aug 17, 2013 4:17 am

Re: How to make Raspbian read only?

Sat Aug 17, 2013 4:54 pm

chuckhendo wrote:I am using Raspbian installed on an SD card in a kiosk like environment. I want it so that the Pi can be unplugged without a shutdown. However, often times it won't boot after this happens.

I was thinking of setting the file system up as read only would fix this. However, if I mount root as ro it won't boot; I'm assuming because it's trying to write. How should I go about fixing this?
Dear Mr. micerinos, I followed your post for making R-Pi read only. It is wonderful but if I make /dev/mmcblk0p2 as 'ro' I cannot get into the desktop. I read the other blog of unionfs but it appears very complicated. Can you please simplify the unionfs type approach for all. Thanks

User avatar
Torched_
Posts: 11
Joined: Sat Aug 17, 2013 12:29 pm

Re: How to make Raspbian read only?

Sat Aug 17, 2013 5:23 pm

I might give up 100 IQ points here, but... Don't all SD-cards have a little switch that allows you to set them to read-only?
Pi model B, 512 MB Ram
Maybe you'll figure it all out on your way
And realize that it's all still so very far away

User avatar
DeeJay
Posts: 2026
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: How to make Raspbian read only?

Sat Aug 17, 2013 5:27 pm

Torched_ wrote:I might give up 100 IQ points here, but... Don't all SD-cards have a little switch that allows you to set them to read-only?
Correct.

But not all SD-card READERS have detectors or circuitry that monitors and honours the setting of that switch. The RPi is one example that does not.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

User avatar
Burngate
Posts: 6553
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore

Re: How to make Raspbian read only?

Sun Aug 18, 2013 8:50 am

My understanding is that "switch" is just a bit of plastic, somewhat similar to the notch on a 5¼" floppy ...
You've never heard of a floppy?

Well in the days of Alfred the Great, before usb sticks, there were things called floppy discs, which weren't floppy but were called that because before that, at the time of Hadrian there were similar things that were flexible. They were the size of a dinner plate and could hold almost 100kB.
And they had a notch in the cover that, if you stuck a bit of paper over it, told the disc controller chip not to write to it.

Ain't History wonderful?
Ok, maybe it isn't.

User avatar
Torched_
Posts: 11
Joined: Sat Aug 17, 2013 12:29 pm

Re: How to make Raspbian read only?

Sun Aug 18, 2013 9:36 am

Floppy discs and the flexible things indeed are before my time, but I do have a number of floppy discs lying around, and my uncle has shown me one of those 100kb HDDs. Personally, I find it amazing to see, and also to realize how much we've improved technology in the past 25 years.
Pi model B, 512 MB Ram
Maybe you'll figure it all out on your way
And realize that it's all still so very far away

daneast
Posts: 41
Joined: Wed Feb 08, 2012 6:55 pm

Re: How to make Raspbian read only?

Sun Dec 15, 2013 3:57 am

Regarding the desktop not starting up with a read-only filesystem: lightdm-gtk-greeter is trying to write to the file /var/lib/lightdm/.Xauthority
I just added /var/lib/lightdm/ as another tempfs type entry in fstab and it is now launching.

Dan

Havinit
Posts: 53
Joined: Sat Feb 09, 2013 12:34 pm

Re: How to make Raspbian read only?

Wed Dec 18, 2013 8:51 pm

I just got through doing this myself - all went nicely thanks to the Debian wiki page, in fact it is a wee bit out of date (or maybe there are some differences in Raspbian) as some of the things there are already done in the default install (/etc/mtab for example).

nausicaa
Posts: 2
Joined: Fri Jan 17, 2014 9:26 pm

Re: How to make Raspbian read only?

Fri Jan 17, 2014 9:38 pm

I am a noob in RPi.
How can I get back to original read/write boot mode, after I made it read only?
Should I flash the SD card.
Thanks.

Enslaver
Posts: 1
Joined: Mon Jan 20, 2014 12:43 am

Re: How to make Raspbian read only?

Mon Jan 20, 2014 12:45 am

You can remount the filesystem read-write the same way dpkg does it:
DPkg {
// Auto re-mounting of a readonly /
Pre-Invoke { "mount -o remount,rw /"; };
Post-Invoke { "test ${NO_APT_REMOUNT:-no} = yes || mount -o remount,ro / || true"; };
};
So to make the root filesystem writable:

Code: Select all

mount -o remount,rw /
and to set it back to read only:

Code: Select all

mount -o remount,ro /

Return to “Advanced users”