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

I have enabled this on a couple of RPi4 that I have. One is running the weather monitor from a past Core Elec project and the other is running a Chrome browser displaying some graphs from a Grafana instance.

I find that once I enable the write protection, the RPi becomes unusably slow.

I am using Samsung Pro Endurance UHS-1 Class 10 SD cards.

If there a way to resolve this?

Hi all,
I just wanted to share my experiences with running raspi’s as read-only.

I have 8 raspi4B’s running non-interactive slideshow kiosks 24/7. They are on a private network which isn’t connected to the internet and I use their ethernet port instead of wifi. The private network has an NTP time server so the time is also correct. I had the system running with raspi3B+'s for 3-4 years while I worked out the best way to setup the slideshow operation and around Nov 2023 I replaced them with raspi4B’s. This summer I encountered some strange behaviour which I’ll share with you. Maybe someone might have some ideas on what might be happening.

Each kiosk is setup as follows.
Hardware:
raspi4B (CE06425)
‘Teamgroup’ 16G uSD card (CE04628)
32G SanDisk thumbdrive formatted FAT32 (CE08417)
raspi plugpack (CE06427)
samsung 32" monitor
Win10 PC on the same network to access the different raspi’s using VNC viewer

Software:
Raspi OS (legacy) with desktop - bullseye
‘feh’ image viewer installed to run the slideshow

Settings:
wifi and bluetooth disabled
‘updater’ disabled and removed from the taskbar
VNC enabled, its auto update disabled
SSH enabled
watchdog enabled
‘feh’ autostarts when raspi boots and displays the slideshow
crontab runs 2 scripts (7pm and 8am) to blank/unblank the display
overlay filesystem enabled
boot partition write protected

I won’t go into detail on how the above is setup unless someone asks but if there’s interest I can write a more detailed description of my setup. Basically ‘feh’ runs the slideshow displaying images stored in a folder on the thumbdrive called ‘Slideshow’. The reason for this of course is because the raspi is setup as read-only so the images shouldn’t be stored on the uSD card. Using VNC Viewer on the Win10 PC allows an easy way to delete and add images to the Slideshow folder to update the show. The first thing I noticed is that after running this setup for a while (not sure exactly how many days/weeks it takes) if I eject a thumbdrive and plug it into my Windows laptop it always says that there’s a fault with the drive and it needs to scan it to fix the errors. This takes a second or so and all is ok.

Last christmas I decided to shutdown all the displays and I switched them back on after about 4 weeks. Half the raspi’s came up ok but the others didn’t boot and displayed a screen full of messages including “Failed to open device: ‘sdcard’”. So I thought this was a good opportunity to re-install the OS and re-format the thumbdrives so everything runs afresh.

The first problem I found was that some of the uSD cards weren’t recognised by Windows. When I plugged the card reader with the uSD card into a USB socket the laptop froze and became unresponsive until the reader was unplugged. By playing around a bit, unplugging it in and out I could finally get it to appear in “This PC” but double clicking to open it froze windows again. So after more unplugging/plugging it I could right click its icon and selected ‘Format’ but that did nothing, it just sat there. I also have a separate SD Card Formatter program which I normally use to convert Linux partitioned cards back to FAT32. This froze too. I then downloaded and tried ‘AOMEI Partition Assistant’ but it didn’t do anything either. I also ran ‘diskpart’ from the command line but it didn’t recognise the uSD card at all so I couldn’t repartition the card. After a few days I thought of trying to do something using a raspi. So I plugged the SD card reader into it and under ‘Accessories’ I ran ‘SD Card Copier’. This time it recognised the card and so I made a copy of the raspi’s OS. At the end it came up with an error message - the DOS partiton was OK but the linux partition wasn’t created properly. So I re-ran SD Card Copier and this time it fully recovered the uSD card. I could plug it back into my laptop and the DOS partition appeared as it should. These cards are now running in the 8 raspi’s again.

Then I tried reformatting the thumbdrives and found the same problem as I did with the uSD cards, nearly all of them froze Windows when I plugged them in. One card in particular was interesting - even though it was originally formatted as FAT32 it froze Windows when plugged into my laptop but when plugged into a raspi I could see everything on it. Very strange behaviour. Once again they were recovered using a raspi but because I tried so many things I don’t recall now what I did to get them up and running again. I could have been SD Card Copier or possibly fdisk or fsck on the raspi that got them working. Anyway I managed to get 7 of the drives working so I reformatted them as FAT32 using the laptop. One thumbdrive however is still faulty. It only allows 268M to be available on the raspi but not Windows. I’ve put it back into service since my image files don’t take that much space and so far it’s still working.

Where to from here? I’ll be trying a few things over the next year to see what’s causing the problem.
I don’t understand what could be changing things on the uSD card when the raspi is set as read-only. So firstly I’ll reboot the raspi’s at the start of each month to see if that might help (I might set this up in crontab). From what I read the raspi’s do store log files during operation and because of the limited RAM available for the OS when running with the overlay filesystem enabled maybe this might help ‘clear’ things.
Secondly, I don’t know how many times during the year a raspi might reboot due to the watchdog timer or due to power dropping out. I intend to write a simple script to increment a number in a file on the thumbdrive each time a raspi boots so I can keep an eye on how many times this happens.

Any other ideas?
Peter

I have split my SD card into 2 partitions and mounted /home on the separate partition to /.
Is there a way to only enable the overlayfs on the / mount while leaving /home writeable?

I found the answer to my question in this thread.

TLDR: Edit the 2 lines in /usr/bin/raspi-config that start with “sed -i $CMDLINE -e” and change “overlayroot=tmpfs” → “overlayroot=tmpfs:recurse=0”