A hard disk is a consumable device. When used for a period of time, physical faults such as bad channels may occur. If a bad track occurs on the hard disk of a computer, if it is not replaced or processed in time, the number of bad tracks will increase and cause frequent crashes and data loss. The best solution is to change the disk, but in the case of temporary, block sectors of Bad Sectors in time, do not touch them. Badblocks is a tool for checking bad track locations.
I. Command Parameters
Badblocks format:
Reference badblocks [-svwnf] [-B block-size] [-c blocks_at_once] [-I
Input_file] [-o output_file] [-p num_passes] [-t test_pattern]
Device [last-block] [start-block]
Parameter description:
Reference-B blocksize
Disk block size, in bytes. Default Value: "block 4 K" (4 K/block)
-C blocksize
The number of times each block is checked. The default value is 16.
-F
Forces a read/write or non-destructive write test on a mounted device.
(We recommend that you first perform the umount device and then perform the bad track detection. This option can be used only when a device Mount error occurs in/etc/mtab)
-I file
Skip the bad track that has been displayed in the file without detecting it (you can avoid repeated detection)
-O file
Output the detection result to the file.
-P number
Repeat the device until no new bad block location is found within the specified number of passes. The default number of times is 0.
-S
Display progress during check
-T pattern
Blocks are read and written in the specified mode. You can specify a decimal positive value from 0 to ULONG_MAX-1, or use random (random ).
If you specify multiple modes, badblocks detects all blocks in the first mode, and then uses the next mode to detect all blocks.
The Read-only method only accepts one mode. It cannot accept the random mode.
-V
Detailed information is displayed during execution
-W
Write Data to each block before reading information from it.
[Device]
Specify the disk device to be checked.
[Last-block]
The total number of blocks for the specified disk device.
[Start-block]
Specify the block from which the check starts
Ii. Example
Badblocks is a block of 4096. Each block is checked 16 times and the result is output 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:
Reference # cat hda-badblocks-list
51249
51250
51251
51253
51254
......
61245
......
You can perform several operations on suspicious blocks. Below, badblocks takes 4096 bytes as a "block", each "block" is checked once, and the result is output to the "hda-badblocks-list.1" file, starting from 51,000th blocks and ending with 63000 Blocks
# Badblocks-B 4096-c 1/dev/hda1-o hda-badblocks-list.1 63000 51000
The time spent this time is relatively short. In the specified circumstances, the hard disk will generate a burst of noise in a very short time. Because of the different check conditions, the output results are not exactly the same. When you repeat the same operation several times, the results vary depending on the number of conditions. After multiple operations, until the final hda-badblock-list.final file is generated.
Iii. Others
1. fsck uses badblocks Information
Badblocks only indicates the bad track information in the log file. If you want to skip these bad blocks during disk detection, you can use the-l parameter of fsck:
# Fsck. ext3-l/tmp/hda-badblock-list.final/dev/hda1
2. Detect bad channels before creating a File System
Badblocks can be run with e2fsck and mke2fs-c deletion (the same for ext3 file systems). Before creating a file system, check the bad track information:
# Mkfs. ext3-c/dev/hda1
The code indicates to use-c to check the bad path hard disk before creating the file system.
This operation clearly tells us that we can use the "mkfs. ext3-c" option to check the hard disk in the "read-only" mode. This command will check the hard disk when formatting the hard disk and mark the wrong hard disk "block ". It takes a lot of patience to format the hard disk using this method, because after the command is run, the hard disk will be checked one by one in Read mode.
Iv. References
Original article from:
Http://www.oreillynet.com/linux/cmd/cmd.csp? Path = B/badblocks
Refer:
Http://tech.ccidnet.com/art/302/20031106/70263_1.html