Reducing SD Card crash

Hi there guys!!
I have seen lots of complains about people having problems with Raspberry + SD Card combination, and I believe we can reduce this kind of issue.
Not that the SSD is a bad option, but sometimes it’s just not necessary for some people, and they just don’t understand what’s going on.
As Home Assistant uses SQlite as its database, HA always needs to write an increasing number of sensors and entities we created in that database. and if you have influxDB also, this situation only gets worse, specially when you have short sensor update times, like once per second etc…
what happens is that your number of I/O writes increases and your wait/queue for i/o writes also increases.
So basically you are always writing a high volume of data to the SD, and in combination with an inappropriate power source or fluctuations in your electrical system, the card will get corrupt very quickly.

So, what to do?

1 - Decrease your I/O writings:
On sqlite, mariaDB or InfluxDB you can reduce the amount of sensors that write to the database by removing them in the integration.

# Here you choose what to write or not on sqlite
recorder:
  exclude: # this section exclude entire domains or entities from writing to database
    domains:
      - sensor
  include: # this section includes entire domains or entities
    entities:
      - sensor.last_boot
   
# see https://www.home-assistant.io/integrations/recorder/ for more details

Removing from InfluxDB
the nomenclature is the same, you just have to reproduce it within the influxdb section

influxdb:
  exclude: # this section exclude entire domains or entities from writing to influx database
    domains:
      - sensor
  include: # this section includes entire domains or entities
    entities:
      - sensor.last_boot
     
# see https://www.home-assistant.io/integrations/influxdb/ for details

2 - Monitor your reads/writes
How to monitor the number of writes and reads? one way to do this is to add the system monitor. on this platform we can add CPU process waiting time. if it’s too high, the chance of crashing your card is very high.

- platform: systemmonitor
  resources:
    - type: load_1m
    - type: load_5m
    - type: load_15m

The last card I had, was overwhelmed with like 50 processes waiting for the processor at 1m load. today with the appropriate card this number has dropped to between 0.5 to 1.5 processes in 1m.

3 - Buy an SD with a good number of I/O writes
Many people buy SDcard Class 10 or UHS speed class 3 thinking that only this is necessary to get a good card, but the class that defines the number of writes/reads I/O is Class A2
If your card is A2 it prioritizes inputs and outputs of an operating system, some class 10 don’t even have A1 rating, so choose an A2 card.

image

With this simple steps i managed to get a stable system, It worked for me this way and I believe it can work for more people. Hope this helps.

1 Like

Use a larger Micro SD. If your SD has wear leveling (i.e. WD Purple microSD) it will take much longer to use up the write cycles of a 128Gb SD card.

1 Like

One way to achieve a large reduction in writes would be not to do snapshots. Of course, it would be better if HA gave us the option to do snapshots to an external device like a NAS, but that’s apparently not in the cards.

I agree that it’s also important to exclude as many things from recorder as possible. It’s absurd that the default for HA is to record everything. The fact that there’s no GUI way to exclude things is downright embarrassing. This should be part of the setup process for each device and entity. Again, there appears to be no interest in this among the developer community.

It’s almost like recommending running HA off an SD card is deliberately setting new users up for failure.

1 Like

Home Assistant Add-on: Samba Backup

Hi @Joel_Marambaia (and the others), thank you for this write up!
Do have any idea/experience what the real effect is between a standard setup and your way?

1 Like

I don’t understand the question or to whom it is directed.
I was only answering your lament that HA needed a snapshot option other than the SD card.

If you have a NAS you can do your logging on that, which dramatically reduces SD card reads and writes. There’s a discussion of it here. Mine’s been running for about 18 months.

1 Like

or use operating-system/partition.md at d42f80c65e8506a6aec0c7f7f9e603107e163faf · home-assistant/operating-system · GitHub and only see the sd card flashing during power on… no more writing to it at all, and officially supported

That’s a great add-on, but it doesn’t really help here.

The snapshot is still created on the SD card. The add-on just copies it to the Samba share. There’s a great Google Drive Backup add-on, too. Same problem.

The real solution would be to create the snapshot somewhere else in the first place.

Think about it. If your system crashes, there’s a very good chance you’ll be reloading the snapshot from another place (Samba share, Google Drive, etc.) anyway. It could be difficult or even impossible to retrieve from a failed SD card. Why create it there?

Is this a suggestion of what to add/exclude in reducing wear on the SD card or it’s an example of how the file structure looks like?

# Here you choose what to write or not on sqlite
recorder:
  exclude: # this section exclude entire domains or entities from writing to database
    domains:
      - sensor
  include: # this section includes entire domains or entities
    entities:
      - sensor.last_boot
   
# see https://www.home-assistant.io/integrations/recorder/ for more details

1 Like

just my case example. i don´t need sensors on lovelace, only on influx_db, and not all of them, so i removed. i kept sensor.last_boot to be aware of reboots, which i don´t need on influx, only at the lovelace.

Regarding theA2 rating I just happened to read this article yesterday.
Maybe in terms of stability /endurance A2 is still better. But at least performance actually seems to have reduced according to the article, as A2 apparently requires support of the system the card is used in.