badblocks command is a Linux utility used to search for bad blocks on a storage device. It can be used to test a hard drive or any other block device for bad sectors or blocks. The command writes a series of patterns to the device and then reads them back to detect any errors.
The basic syntax for the
badblocks command is:
badblocks [options] device
device is the path to the device you want to test.
badblocks will perform a read-only test on the device, which means it won’t write anything to the device. This is useful for checking if a device already has bad blocks. However, you can also perform a read-write test on the device using the
-w option. This will write a series of patterns to the device and then read them back to detect any errors.
Here’s an example of how to use
badblocks to test a hard drive:
badblocks -w /dev/sda
This will perform a read-write test on the
/dev/sda device. Note that this can take a long time, especially on larger drives.
You can also specify a range of blocks to test using the
-b option. For example, to test only blocks 1000 to 2000, you can use:
badblocks -w -b 1000 2000 /dev/sda
badblocks will output the results to the terminal. However, you can also save the results to a file using the
-o option. For example:
badblocks -w -o badblocks.txt /dev/sda
This will save the results to a file named
badblocks.txt in the current directory.
Here’s a table of all the available options for the
||Specifies the block range to test|
||Specifies the number of blocks to test at once|
||Saves the results to a file|
||Performs a read-write test on the device|
||Shows progress of the test|
- If you get an error message saying that the device is busy, make sure that no other programs are accessing the device.
- If the test takes a long time, be patient. It can take several hours to test a large hard drive.
- If you suspect that your hard drive has bad blocks, it’s a good idea to back up your data before running
badblocks. The test can sometimes cause data loss.
badblocksshould not be used on mounted devices or devices that contain important data.
- If you’re not sure which device to test, you can use the
lsblkcommand to list all the available block devices on your system.