Read-Only Raspberry Pi - Never Corrupt your Micro-SD Card

Updated 16 February 2023

Here is a solution so you can turn your Raspberry Pi handheld computer on and off from the power plug (power cycle it) just like any other appliance in your home! And it can all be done through only one setting.

With a normally set-up Raspberry Pi, power cycling can cause your Micro-SD card to become corrupted. Thus, Safely Shutting via the operating system or a safe shutdown button is crucial. Lets be clear, when you Safely Shut down the Raspberry Pi it will first check that it has completely stopped writing new information to the Micro-SD card, and once the Pi is sure, it will then stop supplying power to it’s circuit board. There are situations however where it is inconvenient to turn the device off safely every time (be it due to location or time constraints).

So, knowing that Micro-SD card corruption only occur when you turn off the Raspberry Pi in the instant that it is writing new information to the Micro-SD card, lets completely stop the ability for the Raspberry Pi to write new files to the Micro-SD card. Then corruption will never occur and you can be free to power cycle it whenever you desire!

In this guide, we are making our Raspberry Pi Palm-Sized Computer Read-Only. Note that this is also a reversible process. Below are the contents of this guide.

What You Need
Overview of Process
- Demonstration
How to Revert Process
Situations Where This Is Perfect

This set-up is perfect for kiosks, multi-use work terminals, educators managing a classroom worth of Raspberry Pi boards, and completely finished projects that you want the ease of power cycling. With no concern of corruption, your Micro-SD card will be able to run its natural life, which should be 10+ years. 

There are going to be some concessions. Once you have turned your Raspberry Pi into Read-Only no changes (be it creating new code, changing files, deleting directories) will be remembered next time you turn on the Raspberry Pi). For instance, if you create a directory on the desktop of a Read-Only Raspberry Pi when it restarts that folder will have disappeared. This is because we have completely disabled the write function of the Raspberry Pi. All these created files on a Read-Only Raspberry Pi are going to be temporarily stored in the RAM. This means if you create or try to download files larger than the RAM available the system OS won't allow it (or be able to do it).

Data can be pulled from a Read-Only Raspberry Pi via USB Drive or in any other normal manner. Crontab (a method of getting the software to run on boot) and time synchronisation (pulling the time information from the internet) will also work perfectly fine with a Read-Only Raspberry Pi.

As always if you have any questions, queries, or things to add please let us know your thoughts!


What You Need

Below is everything you need to set up your Raspberry Pi to be Write-Only. No soldering or extra hardware to make a safe power cycling Raspberry Pi. This process can also be done headless meaning you wouldn't need to use peripheries, check this guide on how.

-      Raspberry Pi Palm-Sized Computer (this process will work with all varieties)
-      Micro SD Card flashed with most recent Raspberry Pi OS (a quick how-to linked here)
-      Power Supply 
-      Monitor
-      HDMI Cord 
-      Mouse and Keyboard


Overview of Process

So, with your Raspberry Pi set up with all your settings and data exactly how you want to let's effectively take a permanent snapshot of this moment (which the system will revert back to whenever it is rebooted) by turning the Raspberry Pi to Read-Only. The steps are as follows (but first for real, back up your Micro-SD card, super really, back up that card).

With Raspberry Pi OS displaying like normal, open up a new terminal using the black button at the top left of the screen. The method demonstrated from here on out will be the exact same process if you are accessing the Raspberry Pi Headlessly or directly.

In this new terminal type and enter the following below line. This will open up the configuration menu of the Raspberry Pi. See further below for an image of this line written into the terminal. This line starts with | sudo | which means it will run the following with admin privileges.

sudo raspi-config

sudo raspi-config type into terminal

 

The menu will look like the image below, you can navigate this space using your keyboard and select options by pressing enter. Old school graphics but super incredible and useful. Navigate down to Performance Options and press enter.

Configuration Menu

After pressing enter on that option it will look like the image below, presenting a couple of other options. In this page you are going to navigate down to the | Overlay File System |. This is where you are going to enable or disable the Read-Only file system. Press enter on this setting.
Overlay File System Setting

 
Having done this you will see two things happen after each other. First it will bounce back to the Black Terminal for less than 30 seconds to update the normal root files. As it is doing that the terminal will display exactly like the image below. 

Bounces back to Terminal for <30 Seconds

 

Then it will jump back to the configuration menu and display the below screen and present the message to the user | The overlay file system is enabled |. This step can be seen in the image below.

Overlay system is enabled

 
Then after pressing enter on that screen it will show a new message which can be seen in the below image. Make sure to say Yes here as this will make the boot partition (the Micro-SD Card) be write-protected. If the disk is write-protected, then it is Read-Only and that is exactly what we want to have happen.

Boot partition to be Write Protected

 
Thus having pressed enter on Yes it having done this it displayed the below page. Then on rebooting the system my Raspberry Pi 4 Model B is completely in Read-Only Mode. Thus no new permanent information can be written to the Micro-SD card ever.

Partition (Micro-SD card) is not Read-Only! Yay


Demonstration

I’ve created a new directory on the desktop (called in this example ‘New Annoying Folder’). See below in the image for this happening. To double clarify, I am creating this new folder on the desktop after I have rebooted the Raspberry Pi OS. So right now the Micro-SD card is Read-only. Just because it is Read-only doesn't mean you can't alter and create new files, they just will not be saved upon reboot.

New Annoying Folder

 
Now, this has happened let's reboot the system. Knowing that the setup is Read-Only we would expect after a reboot that file would have disappeared. As we can see in the image below this is exactly what has happened!

Snapshot has been locked in


How to Revert the Process

You can reverse this process nicely and easily but it will require two reboots.  Simply, you can go through the same process to revert your Raspberry Pi from Read-only back to the default Read and Write. The setting | Overlay File System | acts as a toggle so once navigating back to this setting using the Raspberry Pi Configuration Menu like before you can simply toggle Write On and Off. Remember though it will take a reboot to disable the overlay file system and then another reboot for the boot partition to become enabled. Each reboot will give the setting a chance to stick (so don't do any important work until you do make your system Read and Write lest your data is lost). See the images below for each step of reverting the process, each option highlighted is the one to do. This process has been compressed into a single image as it is just very similar to before (right click and open image in a new window if the writing is too small to see).

All the information in one table

Part of the reason why the naming is a little confusing and two reboots are required (I believe) is it is done on purpose to prevent young nefarious agents reverting it back to normal Read and Write and then causing mischief. Worth noting, another method to turn the Raspberry Pi OS to read and write is simply done by re-flashing the Raspberry Pi 4 Model B Micro-SD Card. 


Situation Where This Is Perfect

Kiosk Applications and Digital Signage are often not properly shut down but instead simply unplugged at the end of the day. The same goes for Video Looping Machines. Repeating this increases the risk of file system corruption.

Educator at work (And Im sure these nice fellows are not up to mischief)This is also very valuable for educators. Say you have pre-loaded files and settings on a whole bunch of Raspberry Pis. That way when your students come in and do the course work they do not need to jump through the preliminary process of doing those settings and installing the files for the course. Thus, when the students arrive they can get right into the content that the educator wants to teach. But the fear of every straight-edged educator (and rightfully so) is those curious students will start downloading all kinds of things, mess around with the settings, download games, remove the course work, and cause all kinds of mischief.

Then, after the lesson, damage control would need to occur. You would then need to go through the process of wiping the micro-SD card, fixing the settings, and re-installing the desired coursework ready for the next class. For each of the Raspberry Pi Boards. And that can become a series investment of time for 20+ Micro-SD Cards (we know this and even created a Mass SD Card Image Writer to make this task faster).

What if instead each time you power cycled your Raspberry Pi the data reverted back to that point at the start of the class. All that mischief and setting changes will be forgotten and you’ll be back at your original custom set-up. And that is exactly what a Read-Only Raspberry Pi can do for you.

Another scenario where you would want this is when you have fully completed a project and you want to turn it on and off from the wall switch or via an external timer. By converting the Raspberry Pi into Read-Only, it will never corrupt and your system will work perfectly (or at least until the natural lifespan of an SD-card which is around 10 years).

Also, say you are operating in an environment with intermittent power and the power shuts down on you unawares (and you haven’t got a brilliant UPS hat like the one from PiJuice) then those lingering half-written files can render the SD card completely unbootable. There are apparently methods to perhaps patch up the corruption but sometimes there is no recourse but to whip out the card reinstall everything.

And to those who say My Project doesn't even write any data. It may be true that your application or program does not write any data but your operating system (Raspberry Pi OS) or GUI (such as Chromium or Firefox browser) certainly is. Constantly during operation, they will be writing temporary files, log files, cache files, etc. There is a lot going on under the hood and this is what eventually causes your SD card to corrupt in the mid-to-long run of not safely shutting down. So why not prevent it all together.

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.