The 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.
Overview
The basic syntax for the badblocks
command is:
badblocks [options] device
Where device
is the path to the device you want to test.
By default, 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
By default, 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.
Options
Here’s a table of all the available options for the badblocks
command:
Option | Description |
---|---|
-b |
Specifies the block range to test |
-c |
Specifies the number of blocks to test at once |
-o |
Saves the results to a file |
-w |
Performs a read-write test on the device |
-s |
Shows progress of the test |
-v |
Verbose output |
Troubleshooting Tips
- 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.
Notes
badblocks
should 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
lsblk
command to list all the available block devices on your system.