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?

  • could someone create and add badblocks and io tags to this question? I do not have the privilege : ( – kaptan Jul 19 at 2:04
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.

  • I understand what you are saying and I know about the mapping. The question is if the underlying cells/blocks wear out such that they cause I/O errors and eventually system crash, would it be still safe to reuse the SD card by reformatting? – kaptan Jul 19 at 20:10
  • In other words, how to determine the wear and tear of an SD card and based on that decide the SD card is worn out too much and should not be reused. – kaptan Jul 19 at 20:15
  • Also mentioned in the comment for the other answer below: I am just using badblocks as a tool to do some intense reads and writes on the entire SD card. So that if there are any potential issues with reading and writing they would show up. I am not assuming badblocks can report back the actual worn out blocks/cells that the SD card controller has blacklisted. – kaptan Jul 19 at 21:20
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.

  • I agree. I am just using badblocks as a tool to do some intense reads and writes on the entire SD card. So that if there are any potential issues with reading and writing they would show up. I had a few SD cards that badblocks reported error on them or it was running very very slow on them. Do you know any tool that could determine the health or wear and tear of an SD card? – kaptan Jul 19 at 20:23
  • @kaptan Have you looked at the link I have given in my answer? Try read after write without caching. It would be nice if you could give feedback after trying it. – Ingo Jul 19 at 20:34
  • Sure I will give it a try and update you. – kaptan Jul 19 at 21:01
  • If I understand correctly your code is doing almost the same thing as badblocks but at filesystem level as opposed to block device level. Right? – kaptan Jul 19 at 21:23
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.

  • "If the crashed card won't boot, but reformats to empty, generally safe." This is my understanding too. I just want to find a more objective way to measure the wear and tear, and then decide. – kaptan Jul 19 at 20:18
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.

  • I agree. I just don't have the luxury of having an extra USB flash. – kaptan Jul 19 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.