Read only raspberry pi

I am looking for a read only script for stretch (not lite). I have found a lot of things these last few days but nothing that will do read only for stretch and work with the latest OF from git. I do have a USB stick in the pi to read and write changing files, and it is faster than the SD card so I can redirect swaps and whatever I need to there.

The main reason is I want this device to be able to be hard unplugged, there is not really a good way for a shutdown sequence. If anyone has any good pointers it would be great to know.

I don’t have experience with read only pi’s, but if you can’t find a working script depending on your needs and budget you could maybe look into a UPS (Uninterruptible Power Supply ) for Raspberry Pi. When your Pi loses power these boards allow you to switch to a backup battery, giving your Pi the time to cleanly shutdown.

>Link to a random example of such a board<

Hey thanks, I am making a hand held battery powered device so a UPS is not an option. Mostly the device should be properly shut down but I cannot guarantee it.

Technically you could still use something like a UPS. Your first power supply will just be your battery, instead of mains. So you’ll have one large battery for regular use, and a second, smaller battery for the UPS :wink:

But getting readonly to work would be more convenient. Hopefully someone else can help you with that. Might be worth asking at Adafruit or another forum that is more Pi-centered?

If you are not writing to the sdcard then you shouldn’t need to worry about it. The linux filesystem is journaled so even if you were writing the most that can happen from a hard unplug is that you loose the very latest data but not corruption of the fs.

sd cards can get damaged if you frequently read/write to them so it’s a good idea to write somewhere else but apart from that i wouldn’t worry about suddenly unplugging the rpi

Hi @fresla, take a look at:

The script is only for Raspbian lite, but openFrameworks (at leats 0.9, I have not tested yet 0.10) work flawsless on lite.

Hi, cheers I saw this, but did not start my project with raspbian lite. Is there much difference between the lite and full raspbian?

HI @fresla, I do not see differences beyond the absence of the desktop and the lack of windows system X11.
I haven’t had time yet to try openFrameworks 0.10 with Raspbian Strech Lite, but I’ve used openFrameworks 9.8 with Raspbian Jessie lite for a couple of years without a problem.
As far as i know, raspbian lite is a cutdown version of the complete raspbian version, maybee you will need to install some packages.
For me the ausence of the destock is a good new, less loading time at boot, more free ram, less services in background…

Ok, after some more experiments I dont seem to have a problem with the SD card as such, but, I am using a USB stick to store data on, stuff that needs to be changed regularly as the PI itself is locked well in a moving object in an aluminium case.

What I do see is that after a few times of pulling the power the path to the USB stick will become corrupted. normally this path is /media/pi/nameofusbdisk after a few hard power offs this path is still there, but the actual usb path is now /media/pi/nameofusbdisk1 and then after a few more power cuts it becomes /media/pi/nameofusbdisk2 and so on. In this way the path to my USB stick is never correct after a few power cuts and the whole project is a kind of mess, of course it is quickly fixed, but I am looking for a more bullet proof solution.

Does anyone have any hints to stop this behaiviour (at the moment my usb stick is fat32 so I can write and read from anything.

It would be great to solve this somehow.



fat32 is not a journaled system so it can get corrupted if you turn off the computer without properly unmounting it first. ext4 would be the safest under linux but if you want to access it easily from other systems at least use ntfs. also there’s drivers for windows and osx for the ext fs so if you only need to read it from your own machine you can use ext4 and install the corresponding drivers in your computer

Ok, but the usb drive seems not to be corrupted (maybe I am wrong), it is the raspberry pi that adds another path to the drive (on the OS on the SD card that is not FAT) when it loses power. I will try an ext format and see what results I get…it seems the OS is getting corrupted when it loses power.

oh i see sorry didn’t read properly your post. you just need to add the usb device to the /etc/fstab config file so instead of mounting in an automatic path under media it always mounts in a folder in the user directory for example

in some projects with battery i used this circuit:
with some minor changes, maybe it can be useful!

Hey I have a few mechanisms in place, but I am having trouble with ofxGpio at the moment with the latest OF and latest stretch…I do have an off switch but it is not always registering, so I want to make it a bit more sturdy even if it does not turn off, which is now largely the case.

I’ve been running ofxGPIO + Stretch + of0.10.0 without any issues. Are you trying to read the switch state with ofxGPIO? Does the circuit have a pull up/down resistor for the switch - an absence of that usually leads to noisy or unpredictable registrations.

ok, it seems I am the anomoly so I will do a fresh install and see how it goes. @ayruos yes, I am using a pullup resistor, the strange thing for me is my circuit works fine in python and node-red, and as soon as I try it with one of them it will fine with ofxGPIO, until I reboot…

Thanks arturo that works perfectly. I am not using read only in the end and now the system works perfectly. @veketor I will switch over to lite once development is complete, I am still going through some lazy stuff using VNC, I know it can be done with ssh there are some things that slow me down. Once I have a final build I will switch to lite (I have 5 battery powered hardware devices that I am updating through the internet logging into my collaborators laptops so VNC is the easiest way for now).

@kashim I have no idea why, but I never got ofxGPIO to work with properly my button without first running some other program to access it. For now I run node-red when I start the PI and then close it before running my application and it works fine. From then my buttons work perfectly with ofxGPIO, I am not sure why but I have reliability now so I keep going.

Thanks to everyone for your help. It really made the difference between a project that was unreliabe and terrifying to one that is progressing well.

Have a look at allows you to create numerous zram directories via unionFS or even have a complete ephemeral root.

Bit of a necro but noticed it and it might be useful.

1 Like