badblocks

Find corrupted blocks on disk

Supplementary instructions

badblock command is used to find damaged blocks on the disk. The hard disk is a wear-and-tear device, and physical failures such as bad sectors may occur after being used for a period of time. After the computer hard disk has bad sectors, if it is not replaced in time or technical treatment is performed, there will be more and more bad sectors, which will cause frequent crashes and data loss. The best way to deal with it is to replace the disk, but in temporary situations, the sectors with bad sectors should be shielded in time and do not touch them. badblocks is a good tool for checking the location of bad sectors.

grammar

badblock(option)(parameter)

Options

-b<block size>: Specifies the block size of the disk, in bytes;
-o<output file>: Write the inspection results to the specified output file;
-s: Display progress during inspection;
-v: Display detailed information during execution;
-w: When checking, perform a write test.

Parameters

Example

badblocks uses a block of 4096, checks each block 16 times, and outputs the results to the "hda-badblocks-list" file.

badblocks -b 4096 -c 16 /dev/hda1 -o hda-badblocks-list

hda-badblocks-list is a text file with the following content:

cat hda-badblocks-list
51249
51250
51251
51253
51254
…
61245
…

You can perform several more operations on suspicious blocks. Below, badblocks uses 4096 bytes as a "block", each "block" is checked once, and the result is output to the "hda-badblocks-list.1" file, starting from the 51000th block and ending with the 63000th block.

badblocks -b 4096 -c 1 /dev/hda1 -o hda-badblocks-list.1 63000 51000

This time it took a relatively short time, and the hard drive made a "rattling, rattling" sound in a short period of time under specified circumstances. Due to different checking conditions, the output results are not exactly the same. Repeating the same operation several times will result in different results because the conditions are somewhat different. After multiple operations, until the final hda-badblock-list.final file is generated.

other

1. Information about fsck using badblocks

badblocks will only mark bad sector information in the log file, but if you want to skip these bad blocks when detecting the disk, you can use the -l parameter of fsck:

fsck.ext3 -l /tmp/hda-badblock-list.final /dev/hda1

2. Detect bad sectors before creating a file system

badblocks can be run with the -c deletion of e2fsck and mke2fs (same for ext3 file systems), and detects bad sector information before creating the file system:

mkfs.ext3 -c /dev/hda1

The code indicates using -c to check the hard drive for bad sectors before creating the file system.

This operation has clearly informed us that we can use the mkfs.ext3 -c option to check the hard disk in read-only mode. This command will check the hard drive when formatting it and mark the wrong hard drive "block". Formatting the hard drive in this way requires a lot of patience, because after the command is run, the hard drive will be checked one by one by reading.