Storage‎ > ‎Storage-disk‎ > ‎

badblocks - search a device for bad blocks

Thank you for visiting this page, this page has been update in another link Badblocks search bad blocks on a block device


badblocks is used to search for bad blocks on a device (usually a disk partition). It's in e2fsprogs, which provides the filesystem utilities for use with the ext2 filesystem. It also supports the ext3 and ext4 filesystems

Usage:

Usage: badblocks [-b block_size] [-i input_file] [-o output_file] [-svwnf]
       [-c blocks_at_once] [-d delay_factor_between_reads] [-e max_bad_blocks]
       [-p num_passes] [-t test_pattern [-t test_pattern [...]]]
       device [last_block [first_block]]

Testing for bad blocks

No one can guarrany that one disk can last forever and no bad block at all, commonly in disk industry, for example Seagate Enterparise 3.5' 4TB Constellation ES.3

Nonrecoverable Read Errors per Bits Read 1 sector per 10E15

read-write Test

Note: this test will destroy you data


# badblocks -wsv /dev/<device>
Checking for bad blocks in read-write mode From block 0 to 488386583 Testing with pattern 0xaa: done Reading and comparing: done Testing with pattern 0x55: done Reading and comparing: done Testing with pattern 0xff: 22.93% done, 4:09:55 elapsed. (0/0/0 errors) [...] Testing with pattern 0x00: done Reading and comparing: done Pass completed, 0 bad blocks found. (0/0/0 errors)

In the test above, there were three options used.
-s Show the progress of the scan by writing out rough percentage completion of the current badblocks pass over the disk. Note
that badblocks may do multiple test passes over the disk, in particular if the -p or -w option is requested by the user.

-v Verbose mode.

-w Use write-mode test. With this option, badblocks scans for bad blocks by writing some patterns (0xaa, 0x55, 0xff, 0x00) on
every block of the device, reading every block and comparing the contents. This option may not be combined with the -n option,
as they are mutually exclusive.

read-write Test (non-destructive)

Origionally, a non-destructive read-write test does transparently backup original content before testing sectors with a single random pattern and then restoring the content from the backup. This is a single pass test and is useful as a general maintenance test. 

The way is to use -n option,

But what I noticed is that by default, badblocks doesn't do any test if it detects the device actually is in use.

#badblocks -nsv /dev/sda
/dev/sda is apparently in use by the system; it's not safe to run badblocks!

Well, you can try -f option to force it if you dare

       -f     Normally, badblocks will refuse to do a read/write or a non-destructive test on a device which is  mounted,  since  either  can
              cause  the  system  to  potentially crash and/or damage the filesystem even if it is mounted read-only.  This can be overridden
              using the -f flag, but should almost never be used --- if you think you’re smarter than the badblocks program, you almost  cer-
              tainly  aren’t.   The  only  time  when  this option might be safe to use is if the /etc/mtab file is incorrect, and the device
              really isn’t mounted.

Read-ony test

#badblocks -v /dev/sda
Checking blocks 0 to 976762583
Checking for bad blocks (read-only test): done                               
Pass completed, 0 bad blocks found.

Write badblocks to a file

badblocks -v -o /home/sda_badblocks /dev/sdc      
-o output_file
              Write the list of bad blocks to the specified file.  Without this option, badblocks displays the list on its  standard  output.
              The format of this file is suitable for use by the -l option in e2fsck(8) or mke2fs(8).

Use badblocks list when create filesystem

Note: This command recreate the file system.
mkfs.<filesystem-type> -l /home/sda_badblocks /dev/sdc

Skip badblocks when re-scan

For some reason you need to re-scan the disk, and you want to skip badblocks that you know.
# badblocks -v -i badblocks.lst /dev/sdc
Checking blocks 0 to 8388607
Checking for bad blocks (read-only test): ^C5.48% done, 0:17 elapsed



Comments