Zram not working accordingly on raspberry pi 5

Hi all,

I migrated my openHAB installation to new hardware:

  • Pi 5 Model B 8GB
  • Installed Openhabian 64 bit with Raspberry Pi Imager
  • Imported Openhab backup via openhabian-config

After the setup, everything was working as expected until the first reboot. After the reboot, the historic state for all items is gone. At first I suspected an issue with RRD4J, but I think it has to do with zram.

  • I created a test file in /var/log/test.log, after a reboot the file is gone. I stopped zram using sudo zram-config stop, created the file, rebooted and the file is still here.
  • I installed grafana and influx using sudo openhabian-config, created an openhab database, after a reboot the database file is gone.

I am on a clean, fresh installation. Thereā€™s nothing running on the host except for components that come with the Pi Imager.

Any idea on how to solve the problem, except for permanently disabling zram which is a bad idea as I donā€™t want to kill my SD card too quickly, and no, I also donā€™t plan to switch to an SSD. :slight_smile:

Thanks,
Florian

I donā€™t know that a standard backup includes the persistence data. Open the zip file and see if you have userdata/persistence/rrd4j and one file in that folder for each Item. If not your backup didnā€™t include persistence.

How did you reboot? Zram will write out itā€™s contents to the SD card on a normal reboot. Itā€™s only when power is pulled that you would lose data.

Not without a few more details on how exactly you are rebooting and knowing whether or not your backup included persistence or not. When using openhab-cli, persistence is only included when the --full option is supplied.

also openHABian 1.9.1 was just released it has some changes wrt zram I suggest to use that.
Imager should use it but to make sure you do: manually download it.

Thanks, checked that. Persistence is included and available right after the update. The data is gone after rebooting.

How did you reboot? Zram will write out itā€™s contents to the SD card on a normal reboot. Itā€™s only when power is pulled that you would lose data.

Clean reboot with sudo reboot.

Not without a few more details on how exactly you are rebooting and knowing whether or not your backup included persistence or not. When using openhab-cli, persistence is only included when the --full option is supplied.

Itā€™s a full backup, persisted data is there and loaded correctly after importing the backup. The data disappears after a reboot, which indicates that the zram information is not written back to the file system. If I disable zram, apply the backup, then turn zram back on, the data is persisted during reboot, but comes with other problems when zram tries to restore data on boot.

Thx, verified and 1.9.1 is running. To make sure, uninstalled and re-installed zram. Installation works without problems. Thereā€™s a log line that influx was successfully added to the zram config. So I tried setting up influx, rebooted and the influx configuration was gone again :frowning:

So what do you use for persistence, rrd4j or influx ? InfluxDB you must not put on zram.

BTW to restore item states you should be using mapdb

Iā€™m using RRD4J.

Influx is just another persistence backup I wanted to set up, but I noticed that zram kills the db after installing it via openhabian-config.

I will look into mapdb, but first have to fix zram. From what I can tell it looks like that zram is not written to the SD card on reboot.

what db do you use to restoreOnStartup if not mapdb?

RRD4J, the default. I am currently running a clone of my old Pi4 setup on the Pi5. Same software versions, same config, same persistence on both systems.

By the way, if I install MapDB, is there a way to sync MapDB with the RRD4J data so I can activate MapDB as the default moving forward without losing data?

Iā€™m not sure if restoreOnStartup supposed to work at all with rrd4j.
Enable mapdb to do that instead.

You did not really explain what exactly is the problem. Is it that your item states do not restore ?
Is it that old states are restored ? Is it that the persistence files went missing ?
Can you still chart historic data after reboot, and if so, is there data missing ?

Sounds fishy, didnā€™t you say you did a fresh install ?
What do you mean by ā€˜cloneā€™ then and what does that have to do with persistence ?

You can set an everyMinute strategy on the MapDB persistence startegy for a few minutes and then change it back to everyChange.

It works but only with number type data. It doesnā€™t save and therefore cannot restore stuff like Strings or DateTimes and the like but it can restoreOnStartup anything that it can save.

After every reboot, all historic data is empty. I ran the OH backup through openhabian-config which restored all items, all persistence files, everything accordingly. I could chart historic data until a reboot. After a reboot, all historic data is gone. The items start writing new data, and I see chart data from the reboot time to the next shutdown. Then again, all historic data is gone and the last item state is null until a new update comes in.

I did a fresh install on a Pi 5 and imported the backup from Pi 4. OH versions, persistence services, etc are identical. I am using the same persistence service on Pi4 with the same configurations. Rebooting on the Pi4 does not cause any issues, states are restored accordingly upon reboot. Files I put into /var/log are still there after a reboot, not on the Pi 5 though.

Fascinating, it sounds like the Pi 5 is having some weird interactions with zram on shutdown. Do me a favor and try uninstalling zram on your pi 5 and see if it works then.

After that, try reinstalling zram and see if the behavior returns. I donā€™t currently have a Pi 5 on hand to test on, so if you could help me debug this a little that would be great.

Also if you could provide me a copy of what the file /var/log/zram-config/zram-config.log has both before and after reboot, that would be great. You could also try manually stopping zram while the system is running and see if that works or if it doesnā€™t work even then.

Sure, here we go:

Scenario 1

  • Booted the Pi with zram enabled
  • Restored a backup with openhabian-config
  • Restarted openhab service with sudo systemctl restart openhab.servie
  • Checked historic item state in charts:
  • Saved /var/log/zram-config/zram-config.log (I saved the file on 8/14/8:20 am after I imported the openhab backup, interestingly the last change in the log file was on 8/13/8:23pm, so yesterday)
    zram-config.log (23.2 KB)
  • Rebooted the pi with sudo reboot
  • Checked historic item state in charts:
  • Saved /var/log/zram-config/zram-config.log:
    zram-config.log (36.1 KB)

Scenario 2

  • Uninstalled zram via openhabian-config
  • Restored a backup with openhabian-config
  • Restarted openhab service with sudo systemctl restart openhab.servie
  • Checked historic item state in charts:
  • Rebooted the pi with sudo reboot
  • Checked historic item state in charts:
  • Re-installed zram via openhabian-config
  • Re-started openhab via sudo systemctl restart openhab.service
  • Checked historic item state in charts for the last hour (data visible is since restoring the backup):
  • Rebooted openhab with sudo reboot
  • Checked historic item state in charts for the last hour (data after re-enabling zram is gone again):

So yes, itā€™s definitely zram. Let me know in case you need debug or verbose logs for zram to investigate further.

2 Likes

OK, I think I figured it out, thanks for the logs.

I was a little silly when I made some recent updates to zram-config, and probably should have tested better that they worked correctly. There was a change to one of the options I used in merging the directories on an upstream dependecy and I forgot to change it in the zram-config code.

I just updated it and pushed it to zram-config, if you go and update zram-config with openhabian-config and test again, I think it should be fixed. Please let me know if it doesnā€™t work.

2 Likes

Just figured out that I also was running into this problem - but on a Raspi 4 .
Running a fresh Openhabian 1.9.1 (64 Bit ) install and restore of OH config (coming from from OH 4.2).

A simple daily OH config Backup script saved some days of persistance - from initial OH config restore till I made first ā€œsudo rebootā€.

Thanks to the quick fix - you are my heroes!

If one needs a simple instruction on how to fix this, here is what I (finally) did:

  1. While ZRAM is still installed do a ā€œupdate zramā€ in openhabian-config (Menue pt.below 38.)
  2. Do a ā€œuninstall zramā€ in openhabian-config Menue
  3. Do a ā€œuse zramā€ ,which is openhabian-config Menue pt. 38.

Initially I tried 1) update zram and 2) Use-zram , but that did not update /usr/local/sbin/zram-config , therefore the 3 steps.

Realized that above (stroke out) 3 Steps did not solve my problem. I have to investigate myself a bit moreā€¦

Reg, Bert

1 Like

Hey @ndye,

Unfortunately the issue still persists.

Best,
Florian

Sorry about that, Iā€™m investigating now to see why that might be.

I might need you to provide logs again, I just tested on my system and after updating zram, mine appears to work correctly. Can you give some more details?

As I just did some simple tests to chek if zram woks for me, I think the zram issue is not limited to Raspi 5
So here what I did on a Raspi 4 2GB:

  1. Installed Openhabian v1.9.1 (used this file: openhabian-raspios32-latest-202408061716-crc411a778e.img.xz)
  2. Very basic OH setup (Timezone, Location, installed the 3 suggested persistance bindings mapdb, memory and rrd4j)
  3. Created a small txt file in /var/lib/openhab/persistence/rrd4j/
  4. Issued a sudo rebootā€¦ log in again ā€¦ file is gone. (that was expected)
  5. In openhabian-config : update zram ā€¦ Uninstall zram ā€¦sudo reboot
  6. Created a small txt file in /var/lib/openhab/persistence/rrd4j/
  7. Issued a sudo rebootā€¦ log in again ā€¦ file persists ( :slight_smile: so all ok without zram !)
  8. In openhabian-config : use zram
  9. Created a small txt file in /var/lib/openhab/persistence/rrd4j/
  10. Issued a sudo rebootā€¦ log in again ā€¦ file persists ( :interrobang: so thats with zram !?!)
  11. Created a small txt file in /var/lib/openhab/persistence/rrd4j/
  12. Issued a sudo rebootā€¦ log in again ā€¦ file is gone ( :frowning: so thats with zram !)

Dont know why test file persisted one time after step 10 (which was created right after zram re-install), guess zram needs a reboot to start?. After zram update and reinstall AND a reboot the small testfile is always gone after a reboot.

Here the zram-config.log (the variouse zram-config start/stop are due to the reboots.)
zram-config-base32Bit_zram_updated_2.log (20.6 KB)

I dont like the lines: overlay: unrecognized option '--ignore-mounted' when zram is stopped.

So for me the zram function does not work right nowā€¦on a Raspi 4 ā€¦

Do I miss something in updating zram ? (attached the /usr/local/sbin/zram-config used after step 8)
zram-config.txt (14.2 KB)

Regards, Bert