Openhab and RPi in ReadOnly mode


How can I configure OpenHab to work on RPi in readOnly mode?
As you know, RPI has typical problem with SD card if we use it in 24/7.

@watou has posted a link to a tutorial for how to run the Pi on an external USB drive. There is no way to run openHAB as far as I know in readOnly mode. Even if you shut off the logging you have to deal with persistence and other parts of openHAB writing out temporary data.

I have my RPi B with OpenHAB running for more than 1,5 years now on the same SD card and never had any problems…

Isn’t it possible to run pi in readOnly mode and configure logs and persistence to use an external USB stick? My SD has also corrupted. I have backup but it would be better to avoid this issue.

@watou posted a link a long time ago here on this forum (I can’t seem to find it right now) on how to configure the Pi to run off of an external drive. Search the forum or maybe send him a quick IM and he can point you in the right direction.

A USB stick is also flash memory so it would have the problems as SD cards.

Using an External Drive as a Raspberry Pi Root Filesystem “Quickly set up your Pi to boot with a USB stick or external hard drive as main storage.”


External SD, USB, HDD is not a solution of problem.
The problem’s root is IO (writing) operations during a power off.
The industrial controllers for these tasks used embedded batteries.

In other words, it is necessary to seek some external power bank for correct shutdown.

External drive is technically a good solution but has two drawbacks in my opinion:

  • It means additional cost. compared to rpi it’s quite expensive
  • It is quite big and takes a lot space, hard to wall mounted, maybe it requires additional power source and so on.

I think it would be better to run openhab from a write protected SD (write protected partition) and write logs and persistence to an external drive (USB, or Hard Drive) or maybe a network storage.

RPI is a simple and cheap device. I think we need a solution which fits to this simplicity.

Theoretically, would it be possible to run openhab from a write protected SD, or configure rrd4j to save persistence values to an external drive? My aim is to run openhab as stable as possible because it handles my heating system. Logs and persistence is far less important for me.

You could edit your /usr/share/openhab/bin/ file to send the logs to a different directory, like /tmp, or mount a new tmpfs file system for the logs, so they are written to RAM and not SD.

There are probably a good collection of techniques to achieve what you are after. The process of making a Raspberry Pi “read-only” is probably better covered on a Raspberry Pi forum somewhere already, but it will always be somewhat specific to how you are using the Raspberry Pi.

Once you figure out how to do it, please share a HOWTO with the rest of us!

I will play with this, but unfortunately I am not a developer. My linux programming knowledge begins at command ‘cd’ and ends at ‘sudo nano’ :blush:

Here is one trick I think I just figured out to decrease ongoing disk writes. I got tired of Googling for a good answer for how to disable the internal (Jetty) web server request log. I never look at those log files, they are writing to disk all the time, and it’s wearing out SD cards to log this unused information. Of course, there are probably people who would say it’s a bad idea to stop request logging, but for those like me who don’t need them:

  • Edit /etc/openhab/jetty/etc/jetty.xml and comment out the RequestLogHandler using XML comment tags <!-- and -->:
           <!-- Item>
             <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
           </Item -->
  • Comment out the request log configuration:
    <!-- Ref id="RequestLog">
      <Set name="requestLog">
        <New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog">
          <Set name="filename"><SystemProperty name="jetty.logs" default="/tmp"/>/yyyy_mm_dd.request.log</Set>
          <Set name="filenameDateFormat">yyyy_MM_dd</Set>
          <Set name="retainDays">90</Set>
          <Set name="append">true</Set>
          <Set name="extended">false</Set>
          <Set name="logCookies">false</Set>
          <Set name="LogTimeZone">GMT</Set>
    </Ref -->

This seems to be working correctly for me. Please post if you try this and it leads to problems. Also please note that an apt-get upgrade might undo these edits, so they might need to be added back after an upgrade.

1 Like

openHAB is just one application running on an even minimally configured Linux environment, many of which require the ability to write to disk to operate. I don’t think a completely read only installation is feasible.

However, keep in mind that this is generic. If you configure the RasPi to boot and run from a RAM disk and everything that needs to write can do so. I’ve seen this successfully done using PXE booting but it is not easy to get right. Also, because the Pi has a limited amount of RAM, I’m not sure there is enough to act as the disk plus act as the system RAM.

I still working to solve this problem. My Pi running Wheezy (Kingston SD - 8Gb) were loosing (corrupted SD) OS every week.
Now I did a clean reinstall running Jessie (ScanDisk SD - 8Gb), but today… after a week… I lost everything again by corrupted SD.
What could be the a solution for stop loosing everything again and again?

I do rsync “backup” every 10 minutes to my NAS, than I am able to restore my Openhab close to latest configuration.
I have also a image with full working installation, to quickly restore everything in the right place.
However, this is not a solution to stop to corrupt SDs. I am not able to disable swap?

I’ve been trying to do the same thing recently on v1.8.2.

The absolute minimum needed for OpenHab to even start is to have the following writeable:

  • $HOME/.eclipse (directory)
  • $PWD/workspace/.metadata (directory)
  • $PWD/logs (directory)
  • $PWD/webapps/static/version (file)

I achieve this with two scripts:

#1. Run once before going read-only:


tmpfsfiles="$HOME/.eclipse $PWD/workspace/.metadata $PWD/logs $PWD/webapps/static/version"
for file in $tmpfsfiles; do
        rm -r "$file"
        ln -s "/tmp/$dashfile" "$file"

#2. Run before

(note the missing version file here. Only directories):


tmpfsfiles="$HOME/.eclipse $PWD/workspace/.metadata $PWD/logs"
for file in $tmpfsfiles; do
        mkdir "/tmp/$dashfile"

#3. Log size

I use this to limit number of jetty/openhab past logs:


sed -i.backup -r -e 's/(retainDays">)[0-9]+/\1'$logdays'/' $dest/etc/jetty.xml
sed -i.backup -r -e 's/(<maxHistory>)[0-9]+/\1'$logdays'/' -e 's/\{yyyy-ww\}/{yyyy-MM-dd}/' $dest/configurations/logback.xml

4. Next steps

  • test this actually works in real scenarios (it is fine for small test so far) :slight_smile:

@watou disabling the jetty logs still working fine? I too don’t look at these logs but I do the other logs which I assume are unaffected by this change.

I can’t verify right now if it’s still working but it should be under 1.8. Not so under 2.0 beta. Only the request log should be affected.