Checking storage devices with badblocks

I like my files and I do not want to store them on faulty devices. Hard drives, SSDs, SD cards — every storage device has its longevity, so it is a matter of time before they fail.

But how to detect that something bad happens to the device?

One solution is to scan the device. A tool called badblocks can help with this verification. It operates in two modes: read-only and write-mode. I prefer the latter (destructive) option, as it’s more thorough and makes more sense to me.

badblocks in write-mode will overwrite the entire storage space by writing data to it, then reading it, and verifying that it is correct. Here is how to run it:

badblocks -s -w DEVICE_NODE

Obviously, it cannot run on a device with important data on it, because all data stored on the device will be erased.

I use this method to test SD cards that I use with my cameras, USB sticks, and disks — whenever there is a chance to do so.

badblocks is a very basic tool that works in simple scenarios. It is not suitable for all situations, and there are more modern ways of checking disks. But when it comes to raw testing of storage devices, the simplicity is good.

You can read more about this tool in manpages or Arch Linux wiki.