1

I have the following set-up:

  1. RPi 3
  2. 8GB MLC microSD
  3. partition 1: root and the rest (read-only)
  4. partition 2: /var filesystem (rw)
  5. continuous writes to /var/logs
  6. system will experience unexpected sudden power offs
  7. no swap

Once in a while looks like that either the filesystem gets corrupted beyond fixable by fsck, or some blocks on SD card are somehow worn out causing I/O issues, which either way results in an unbootable system.

Now the question is, if I run an intense badblocks (like below) on such a SD card and I do not get any bad blocks reported back, would it be reasonably safe to reuse that SD card?

sudo badblocks -o ~/tmp/badblocks.list -w -s -v /dev/mmcblk0

My understanding is that the controller on the SD card is putting the worn out blocks on a black list such that they cannot be accessed from the OS anymore. In that case we have basically taken out the bad tooth and we should be able to keep using it.

The only thing I can think of that would stop me from reusing the SD card is that since there has been at least one worn out block, it means that most probably more worn out blocks will pop up soon. This is because if I am right the SD card controller is supposed to try to write to blocks evenly. Which means that other working blocks on the SD card are probably close to the end of their lives.

Is this a correct assertion?

kaptan
  • 193
  • 1
  • 5

4 Answers4

3

Your concept of how a SD Card works is incorrect.

The blocks on the file system bear no relationship to the underlying ssd storage (except in so far that a FS block that maps to a bad area will be unusable).

The (hidden proprietary) firmware on the card maps FS blocks and this continually changes as files are deleted.

Running badblocks on ssd is futile and actually causes more wear.

Milliways
  • 62,573
  • 32
  • 113
  • 225
2

badblocks is an old tool made for magnetic Hard Disk Drives (HDD). A Solid State Drive (SSD) like a SD Card does not use blocks to store data. It uses NAND cells to store bits of data. Single NAND cells can be destroyed. Modern firmware will replace them with reserved new NAND cells on the fly so the driver of the operating system doesn't see any errors about this. The firmware simply doesn't report them. I haven't seen that badblocks reports any errors on a SSD even not on a bad one.

There are some other issues with caching of the data that also mask errors. You can try to test with read after write. I have examined this at Detect an SD card that became read-only.

And to answer your question: no, it would not be reasonably safe to reuse a failed SD card checked with badblocks, that doesn't report errors.

Ingo
  • 42,961
  • 20
  • 87
  • 207
1

To answer your question: "Is it safe to reuse a crashed SDcard?"

  • If the crashed card boots, and has not gone read-only, generally
    safe.
  • If the crashed card won't boot, but reformats to empty, generally safe.
  • If the crashed card boots, but has gone read-only, it is generally worthless.
  • If the crashed card won't boot, and won't reformat to empty, totally worthless.

(SDcards have a read-only safety feature to attempt to preserve data when the card detects damage has occured.)

BTW, the OS is probably caching your "continuous writes to /var/log", but any critical application or critical data deserves an UPS.

Cyclical Obsessive
  • 220
  • 1
  • 2
  • 10
0

I have found the best way to prevent SD corruption on unexpected power-downs is to make the SD card partitions mounted as Read Only. You can then use an inexpensive USB flash drive for log files (and indeed other folders you need to access). This page: https://learn.adafruit.com/read-only-raspberry-pi/ has a great explanation of how this is implemented and it works well.

Jonathan
  • 354
  • 1
  • 6