badblocks

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:

Options:

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

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

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

  • 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 :

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

  • 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:

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

  • 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:

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:

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

Leave a comment