-
- Posts: 2
- Joined: Sat Nov 10, 2012 5:20 pm
How to make Raspbian read only?
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?
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?
Re: How to make Raspbian read only?
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
edit /etc/fstab
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
4) fix 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
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
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
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
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"
Code: Select all
sudo rm /etc/mtab
sudo ln -s /proc/self/mounts /etc/mtab
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"; };
};
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
-
- Posts: 2
- Joined: Sat Nov 10, 2012 5:20 pm
Re: How to make Raspbian read only?
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...
Re: How to make Raspbian read only?
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?
-
- Posts: 93
- Joined: Tue Oct 02, 2012 5:35 pm
- Location: Neumarkt in der Oberpfalz
Re: How to make Raspbian read only?
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
Re: How to make Raspbian read only?
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 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.
-
- Posts: 93
- Joined: Tue Oct 02, 2012 5:35 pm
- Location: Neumarkt in der Oberpfalz
Re: How to make Raspbian read only?
Well to be fair the foundation themselves you just pull the plug to switch it off.Burngate wrote: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 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.
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
Re: How to make Raspbian read only?
... After you've shut downmunklefish wrote:Well to be fair the foundation themselves you just pull the plug to switch it off.
Just 'cos you've had no problem yet doesn't mean nobody willmunklefish wrote:Also why be an idiot????? If you dont think my opinion is valid, keep it to yourself or say something constructive.
Is that constructive enough?
Re: How to make Raspbian read only?
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.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.
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?
-
- Posts: 93
- Joined: Tue Oct 02, 2012 5:35 pm
- Location: Neumarkt in der Oberpfalz
Re: How to make Raspbian read only?
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
Re: How to make Raspbian read only?
No it won't.munklefish wrote:True but a fast card would help reduce the risk.
Common sense? A basic understanding of how computers and storage works?munklefish wrote:And how are we so sure the plug pulling is the cause????
Re: How to make Raspbian read only?
Hi,
I just posted a different method for read only root filesystem on raspbian. You may find it interesting.
Cheers
I just posted a different method for read only root filesystem on raspbian. You may find it interesting.
Cheers
Re: How to make Raspbian read only?
Ooops, I forgot to add the link!
Here is the thing: http://www.raspberrypi.org/phpBB3/viewt ... 29&t=23154
Here is the thing: http://www.raspberrypi.org/phpBB3/viewt ... 29&t=23154
-
- Posts: 4277
- Joined: Sun Jan 15, 2012 1:11 pm
Re: How to make Raspbian read only?
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, ...).micerinos wrote:Ooops, I forgot to add the link!
Here is the thing: http://www.raspberrypi.org/phpBB3/viewt ... 29&t=23154
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)
(One of the best lines I've seen on this board lately)
Re: How to make Raspbian read only?
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

http://www.raspberrypi.org/phpBB3/viewt ... 57#p217757
Cheers
-
- Posts: 4277
- Joined: Sun Jan 15, 2012 1:11 pm
Re: How to make Raspbian read only?
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)
(One of the best lines I've seen on this board lately)
Re: How to make Raspbian read only?
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. Thankschuckhendo 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?
Re: How to make Raspbian read only?
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
Maybe you'll figure it all out on your way
And realize that it's all still so very far away
Re: How to make Raspbian read only?
Correct.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?
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
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
Re: How to make Raspbian read only?
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.
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.
Re: How to make Raspbian read only?
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
Maybe you'll figure it all out on your way
And realize that it's all still so very far away
Re: How to make Raspbian read only?
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
I just added /var/lib/lightdm/ as another tempfs type entry in fstab and it is now launching.
Dan
Re: How to make Raspbian read only?
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).
Re: How to make Raspbian read only?
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.
How can I get back to original read/write boot mode, after I made it read only?
Should I flash the SD card.
Thanks.
Re: How to make Raspbian read only?
You can remount the filesystem read-write the same way dpkg does it:
and to set it back to read only:
So to make the root filesystem writable: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"; };
};
Code: Select all
mount -o remount,rw /
Code: Select all
mount -o remount,ro /