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

I’ve just created a new tutorial "Read-Only Raspberry Pi - Never Corrupt your Micro-SD Card"

The final touch on a project, video loopers, kiosks, multi-use terminals and educators managing a classroom full of Raspberry Pi boards are all perfect scenarios for Read-Only system. This solution means you can turn any generation of 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.

All these created files on a Read-Only Raspberry Pi are going to be temporarily stored in the RAM. Data can be pulled from a Read-Only Raspberry Pi via USB Drive or in any other normal manner. With no concern of corruption, your Micro-SD card will be able to run its natural life, which should be 10+ years.

Read more

5 Likes

Thank you. Great tutorial. I did not realise how easy this is to enable.
Kind regards, John

3 Likes

Hello,
I just tried it. But I have an issue I can’t fix.
When I reboot my RPI after activate the overlays, seems my configuration of the dhcpcd.conf is ignored. He ignore my static ip adress and ask for a DHCP Ip adress who is receiving from my rooter.
This is what i wrote in dhcpcd.conf:
# Example static IP configuration:
interface eth0
static ip_address=192.168.1.25/24
static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8 fd51:42f8:caae:d92e::1
`
Without activating the overlays it works perfectly. :frowning:

Have you heard about that issue? How to fix it?

Thanks a lot for your answer

4 Likes

Hey mate, I’ve just learned about this today but I believe I have found a solution to this exact problem on the Raspberry Pi Forums. Have a quick look over the process in the two links I have below. The solution involves adding a second entry in the interfaces file for the new name works for configuring a static IP but it is much better explain in the posts.

https://forums.raspberrypi.com/viewtopic.php?t=285076
https://forums.raspberrypi.com/viewtopic.php?t=302385

4 Likes

Thank you so much for your help. I did some researches but I didn’t found these links. Maybe my bad english was the reason! Lol :wink: But your links were realy helpfull and it works now. Thank you so much :slight_smile:

Olivier

4 Likes

Brilliant mate :slight_smile: thanks for getting back to us with your success!

4 Likes

Very useful! I just had a SD card trashed to an unexpected power thing.
I havent tried it yet, but suppose I started the system and then mounted a USB drive - could I read/write to it? Or would it come under “root” and decide its also read only?

2 Likes

Very sorry to hear that but you will definitely be able to write to a connected USB no problem even if it is a Read-Only Raspberry Pi.

1 Like

Thank you, and yes I now have it mounting the volume, doing what it has to do, and later unmounting nicely in a script before powering down by your timer module. Works a treat. I now have the main file system read-only and no more trashed SD cards. To repair it I ended up plugging it into a windows machine and manipulating the partitions before re-imaging.

2 Likes

Sounds like a brilliant combo of hardware :slight_smile: would love to see more of it, perhaps show it off as a project!

1 Like

Thank you for the very interesting article!

I’m wondering if there’s a way to check if the system is in ReadOnly or not using the terminal.

I mean, I would prefer to check if the system is in read only mode without creating, say, a new dummy file on the desktop and power cycling the pi to see if the file is still there…

Is it possible?
Thank you so much.

1 Like

Try Start Menu, Accessories, Raspberry Pi Diagnostics. Run it and see if it gives a read and write speed before Read-Only mode and compare if it gives a write speed after the initiation of the Read-Only mode.

I do not have RO mode initiated on my system. I use a SSD.

2 Likes

Thank you @G177630 for your reply,
I’ve made some tests with the diagnostic tool and I’ve found something I cannot understand.

When I have my SO in R&W mode, the interface of the diagnostic tool shows me a FAIL message

and its log is showing me this:

Raspberry Pi Diagnostics - version 0.9
Fri Jan 28 13:53:23 2022

Test : SD Card Speed Test
Run 1
prepare-file;0;0;6260;12
seq-write;0;0;11477;22
rand-4k-write;0;0;669;167
rand-4k-read;8721;2180;0;0
Sequential write speed 11477 KB/sec (target 10000) - PASS
Random write speed 167 IOPS (target 500) - FAIL
Random read speed 2180 IOPS (target 1500) - PASS
Run 2
prepare-file;0;0;10825;21
seq-write;0;0;14375;28
rand-4k-write;0;0;1127;281
rand-4k-read;8815;2203;0;0
Sequential write speed 14375 KB/sec (target 10000) - PASS
Random write speed 281 IOPS (target 500) - FAIL
Random read speed 2203 IOPS (target 1500) - PASS
Run 3
prepare-file;0;0;12750;24
seq-write;0;0;19051;37
rand-4k-write;0;0;1611;402
rand-4k-read;8909;2227;0;0
Sequential write speed 19051 KB/sec (target 10000) - PASS
Random write speed 402 IOPS (target 500) - FAIL
Random read speed 2227 IOPS (target 1500) - PASS
Test FAIL

On the other side, if I put the SO in RO mode, strangely the diagnostic tool shows me a PASS message

and its log is telling this:

Test : SD Card Speed Test
Run 1
fio: looks like your file system does not support direct=1/buffered=0
fio: destination does not support O_DIRECT
fio: looks like your file system does not support direct=1/buffered=0
fio: destination does not support O_DIRECT
fio: looks like your file system does not support direct=1/buffered=0
fio: destination does not support O_DIRECT
fio: looks like your file system does not support direct=1/buffered=0
fio: destination does not support O_DIRECT
fio: pid=1626, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument
fio: pid=1627, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument
fio: pid=1628, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument
fio: pid=1629, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument
prepare-file;0;0;0;0
seq-write;0;0;0;0
rand-4k-write;0;0;0;0
rand-4k-read;0;0;0;0
/usr/share/agnostics/sdtest.sh: 13: [: Illegal number: fio: pid=1627, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument
Sequential write speed fio: pid=1627, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument KB/sec (target 10000) - PASS
/usr/share/agnostics/sdtest.sh: 20: [: Illegal number: fio: pid=1628, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument
Random write speed fio: pid=1628, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument IOPS (target 500) - PASS
/usr/share/agnostics/sdtest.sh: 26: [: Illegal number: fio: pid=1629, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument
Random read speed fio: pid=1629, err=22/file:filesetup.c:711, func=open(/var/tmp/sd.test.file), error=Invalid argument IOPS (target 1500) - PASS
Test PASS

Maybe I’m not able to completely understand the inner working principle of the diagnostics tool but, shouldn’t it make more sense for the diagnostic test to fail when the SDcard is read-only instead of the other way around (as is happening to me)?

Maybe I’m doing something wrong or on the other hand, the diagnostic tool isn’t the best way to tell if the system is in RO or R&W (or maybe indirectly it is)?

2 Likes

Hi Nicola,

This is my output

Raspberry Pi Diagnostics - version 0.9
Fri Jan 28 10:04:02 2022

Test : SD Card Speed Test
Run 1
prepare-file;0;0;295207;576
seq-write;0;0;291271;568
rand-4k-write;0;0;54841;13710
rand-4k-read;48294;12073;0;0
Sequential write speed 291271 KB/sec (target 10000) - PASS
Random write speed 13710 IOPS (target 500) - PASS
Random read speed 12073 IOPS (target 1500) - PASS
Test PASS

You’re getting a fail in the RW mode because the speed requirements are not met.

The pass during the RO state could be due to some internal parameter set (probably at infinity vs. the given pass value).

My intent of the initial post is if one can see any difference between the RW and RO state during the diagnostics testing, it would be an indication of RO mode active, without performing an labor intensive task.

Definitely, the log messages are different and someone can see that the system produces an error in the log, during the write test. The read test will also have an error message because it will read the data it had written.

The exalted Wizards of Ubuntu or Linux can provide a better explanation.

2 Likes

Hi Nicola,

I’d try the steps in Tim’s demo to confirm if you’ve enabled read-only mode successfully.

Let us know how it goes!
-James

1 Like

Hi i am using raspberry pi 4 as attendance machine. the machine is usually directly turned off by power cut by the staff. my memory card get corrupted after few days . i have tried your solution in this post last day. but now the problem is that the script which checks the attendance creates a separate log file for each day, but now it is not creating , can u help with finding a solution for it? although the script is working fine but no logs are shown in the logs folder. I am a newbie in all these raspberry pi things.

Hi,

Thanks for posting. How interesting, where are these log files being created? Are you using journalctl to interact with them being stored in /var/log/journal or similar? Or is it something completely different?

Once we know more about the process which is creating the logs and when it is scheduled to run (I’d suspect within a cronjob or an enabled service that restarts on boot/startup?) that should help in determining why the files are not being created.

Fantastic, many thanks for this guide about the Read-Only Raspberry Pi!

I have been developing prototype instruments which aim to be commercial in later iterations. The prototypes have used a Raspberry Pi with the 7" Touchscreen for the high-level control functions.

I had been thinking that I would have to replace the Raspberry Pi with a high-end microcontroller (one with hardware Graphics support) and a touchscreen, in order to solve this very problem: At the end of the working day, you want the end user to be able to simply switch the instrument off, instead of having to run a Shutdown procedure.

The Read-Only Raspberry Pi idea gives me another option to think over; I’ll probably look at both options in more detail, but it’s very nice to have this extra option!

The only comment I would add is that if you want the Raspberry Pi’s App to save log files or other data (as alluded to by DevSrb above, and my App would need to save some data files too), you couldn’t save them to the Pi’s System SD Card. Thus you would need another drive connected to the Raspberry Pi, for saving Log Files or data to. That second drive could be either (i) a USB drive plugged into the Raspberry Pi, or (ii) plug a USB to MicroSD adapter into the Raspberry Pi, with another MicroSD Card in it for data, and then save your Log Files or data to that second drive. i.e. adapt your App’s code to save Log files or other data to that second drive.

The second drive could also be a full-size SD card, if you used a USB-to-standard SD Card adapter.

Core Electronics sells some USB to Micro SD adapters, for example their CEO8436. It’s also useful for cloning or backing up a System MicroSD card:

2 Likes

Thanks for the reply Bryce…

Actually the log file were created dynamically for each day in /home/pi/raspberry-pi-attendance/logs/
the logs were written through the python logger package.

yes i have created a linux service which runs the service on boot.

1 Like

Hi Sourabh,

Ahhhh - the directory /home/pi/raspberry-pi-attendance/logs/ is inside of the SD card so new files wont be created.
There are a couple of ways to solve this!
Edward has chimed in with a great idea of a microSD card, you could also go for a USB drive.
Another way could be to connect to a fileserver of some sort, there are some guides around on different ways you could do this i.e. Google Drive or OneDrive.

Keen to see it come together!
Liam