Badblocks

From Leo's Notes
Revision as of 05:11, 2 June 2017 by Leo (talk | contribs) (more info, formatting)
This page was last edited on 2 June 2017, at 05:11.

badblocks is a utility that checks for bad blocks on a storage device.

This is useful for testing new or questionable media including fake USB drives that show as a larger drive than it can actually store.

Basic Usage

The destructive test can be done by running:

## Warning! This will wipe your data!
# badblocks -wsv -o /root/badblocks.txt /dev/sda

Use the -n flag for a non-destructive test. A non-destructive test will store the sector value, test the sector, then restore the original sector value.

There are 3 numbers that will be returned as 1/2/3 in this order:

  1. number of read errors
  2. number of write errors
  3. number of corruption errors

The badblocks.txt file that gets created can then be used by mkfs so that the filesystem can skip over known bad sectors like so:

# mkfs.ext4 -l /tmp/badblocks.txt /dev/sda

Test Patterns

The test that is done by default is to write to the disk in 4 passes, each with the following pattern:

  1. 0xAA
  2. 0x55
  3. 0xff
  4. 0x00

You may override this using the -t flag.


See Also