How to make Raspbian read-only

How to set up a Raspbian system as a read-only system in a couple of easy steps.

The filesystem on the Raspberry Pi’s SD card, as every filesystem on every computer, can be corrupted if you disconnect the power suply. Once you make the filesystem read-only (all changes go to a RAM-Disk), you will be able to disconnect the power supply whenever you want.

I have been using this guide from the pi3g blog when creating my Ambilight project and it works pretty well! If you are using a Raspberry Pi for any kind of project and want to be able to turn it on and off quickly without damaging the SD card, this it the guide is for you.

Backup your SD card

Before attempting this tutorial, I recommend that you make a backup of your SD card using Win32 Disk Imager or a similar tool. Just download and run the tool, specify a location and click read to make a backup to disk.

How to make Raspbian read-only

First of all we want to disable swapping by running the following commands:

Next we’re going to install UnionFS which is an overlaying filesystem (you can mount from several different locations into the same folder). In case of collisions, UnionFS uses priorities for the filesystems. If you run into issues installing the package (404 Not Found) you should take a look at this blog post for a temporarily workaround.

Create the script used for mounting UnionFS:

and add the following content to the file:

Once you’ve saved the file you’ll need to make it executable:

Next we have to update fstab using nano /etc/fstab and make sure it looks like this:

Now it’s a good time to create the required directories:

Before rebooting the system we’ll create one last file. This script will be used to make the system temporarily writable again in case you need to make any changes to it:

and add the following content to the file:

Once you’ve saved the file you’ll need to make it executable:

Finally reboot and the system should be read-only:


How to remount the system as writable

If you need to install packages or make other changes to the image you can easily make it writable again using:

When all changes are made simply reboot the system and the system should be read-only again.


Share this:

4 comments, add yours.


Thanks for this guide,
i’ve to changed “UsePrivilegeSeparation no”
in file

to have ssh working.
don’t know why, just have info from here


Great work! Thank You!


How I Can install pacages in rw mode?
rw mode is in chroot, i got errors. How I can enable rw mode for installing packages?
Thank You!

Adelia Schuetze

magnificent submit, very informative. I’m wondering why
the opposite experts of this sector don’t realize this.You must continue
your writing. I’m confident, you’ve a great readers’ bbase already!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.