Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

badblocks command in Linux with examples

  • Last Updated : 26 Feb, 2019

badblock command in Linux is used to search for bad blocks (block of memory which has been corrupted and can no longer be used reliably) in a device. It is by default set to run in non-destructive read-only mode.

Syntax:

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]]

Options:

  • badblocks -s : It is used to display current progress of the test by showing the percentage of blocks scanned.

    Example:

    sudo badblocks -s /dev/sdb1

  • badblocks -b: It allows to specify the block size(usually a multiple of 512) in bytes (default is 1024 bytes).

    Example:



    sudo badblocks -sb 2048 /dev/sdb1

  • badblocks -c : It is used to specify the number of blocks to be tested at a time (default is 64 blocks).

    Example :

    sudo badblocks -sc 5000 /dev/sdb1

  • badblocks -f: (not recommended) badblocks does not run its test on a device if it is mounted.The -f option will force it to run test even if the device is mounted which may damage the file system.

    Example :

    sudo badblocks -sf /dev/sdb1

  • badblocks -o: It is used to write the list of badblocks to a file rather than on standard output.

    Example:

    sudo badblocks -o out.txt /dev/sdb1

  • badblocks -i : It is used to provide an input file which contains a list of known bad blocks in device. This would skip the known bad blocks at the time of test.

    Example:

    sudo badblocks -i ./out.txt /dev/sdb1

  • badblocks -n : It is used to perform a non-destructive read-write test on device. It would not erase data on device.

    Example:

    sudo badblocks -sn /dev/sdb1

  • badblocks -w : It perform the read write test on device by writing some patterns on every block and comparing them. It would erase data on device and do test processing at a faster rate as compared to -n option.

    Example:

    sudo badblocks -sw /dev/sdb1

Specify blocks to test:

  1. last block: It can be specified by passing the last block as an option after device name. It would test blocks from the first block to the specified last block.

    Example:

    sudo badblocks -s /dev/sdb1 1000

  2. first block: It can be specified by passing the starting block number to test as an option after last block.

    Example:

    sudo badblocks -s /dev/sdb1 5000 100

    My Personal Notes arrow_drop_up
Recommended Articles
Page :