Checking data consistency – 1 – badblocks

In order to ensure the consistency of a data storage a regularly check is recommended. This might be checking a hdd, sdd, usb stick, flash card (sd,cf). In general there is only a basic check by the operating system. This check is insufficient to guarantee no data loss. When using Linux there are some small tools that provide an enhanced check for data consistency. This is the first part that describes the usage of badblocks.

Why to use badblocks

Badblocks provides a low level check of the consistency of the data storage medium. Badblocks directly accesses the storage medium an reads and writes on it. There is no check of the file system and there are no effects concerning file system caches etc … So even a file system check is ok, badblocks might find errors.

Using badblocks

After installing badblocks (should be available in every Linux distribution by default) simply call badblocks.

Per default badblocks runs a read only test that tries to read all the blocks of the device.

Some options might be a good idea:

Option Description
-n Non-destructive read/write test. Should only be used with a non-mounted device!!
-p Defines the number of passes. In case there is the expection the device is errornous, repeating the test might helpt to detect an not reproducable bad block
-o Writes a list of identified bad blocks into the specified file
-s Shows the progress of badblocks. As the runtime of badblocks might be very very long this options should be compulsory
-v Prints all errors to stderr



Run badblocks regularly

In an optimum way badblocks runs regularly. This might be done via a cronjob. Furthermore the results of running badblocks should be logged in order not to lose the addresses of all the errornous blocks.

Send error report via email

After running badblocks the logs should be checked whether there is at least one bad block identified. In case there is a bad block an email should be sent. So there is no need to regularly check the logs to get to know whether a device has a problem or not.


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.