SD card and power losses

Hi folks!

I'm running a Pine A64 with the fs on SD card (ext4, custom image). In case of power losses the fs gets corrupted what leads into booting/random reboots problems. E.g. "fsck" told me that an inode has changed.
I guess "ext4 + journal" would help but I often read it's not recommended because of performance issues.

What do you think? Any other options?

Switch to squashfs fs

Hi @markbirss Can I edit my /etc/config on a different pc with squashfs?

Refer to further instructions about squashfs to unpack and repack
https://tldp.org/HOWTO/SquashFS-HOWTO/creatingandusing.html

Here is another bool todo some other nice tasks

How does squashfs avoid SD card corruption by power loss?

It mounts read-only as sated on

If it is read-only, where are your changes permanently saved?

Thank you, I will read through the links, but whats wrong with ext4+journal?

only at modification via a overlay

And the overlay resides... on the SD card?
How can it then be immune to SD card corruption?

would still be prone to corruption when changes are made

Thanks, that was my point.

@gueni If you want to avoid SD card corruption due to power loss, make sure that there is no power loss (e.g. UPS).

1 Like

Here is another approach to adding spi flash to microsd

It case you missed this also
From the OpenWRT docs

Which image to chose?

Often, different images are available for a device. The differ in the filesystem used.

ext4-sdcard.img.gz

  • not optimized for flash memory (journaling speed up flash wear)

  • sdcard can be easyly mounted externally for modification

  • desktop linux standard

squashfs-sdcard.img.gz

  • newer images include a hidden f2fs filesystem, which is optimized for flash memory

  • compressed

  • needs special mount procedure, to externally modify it

  • all changes are done in an overlay partition

other images
  • ubifs-sdcard.img.gz

Ext4 will cause more flash wear

It might be true on regular linux but is it true for OpenWrt what writes very little (if at all) to sd card? Journal should prevent data corruption on power loss, doesn't it?

Yes, it is possible but that is what exists in the OpenWRT documentation with regard to ext4 and squashfs.

I wounder how an inode can be corrupted on power loss if no changes made to the fs from the user. Does the kernel write to inodes regularly? Maybe it has nothing to do with the fs but with the SD card itself?

There MIGHT be few writes from the active services. I.e. to update a time stamp of a file, to keep initial system time on next boot not too far off real time (unless you have battery backed Real Time Clock on your device). I do these writes explicitly, in a cron job, for years already. Quite possible, because of wireguard this has been automated, in the meantime. ext4+journal should fix your issue, correct. But then you might examine your files, first, which ones are modified and how often.

Thank you all for your input! I let it sink in.

I found that on raspi forum:

https://forums.raspberrypi.com/viewtopic.php?t=219032

So on SD cards it's probably "hopeless" and @tmomas is right with his statement:

Since on my last build the "poweroff" command it's working now the issue is small cause I don't have to pull the plug while running...

2 Likes