Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the badblocks command in linux to check for damaged blocks in the disk device

Shulou Source: shulou.com Published: 2022-06-02 18:40:33 11月04日 Update

Xiaobian to share with you the use of linux badblocks command to check the disk device damaged blocks, I hope you read this article after a big harvest, let us discuss it together!

badblocks is a command to check for bad blocks in a disk drive. When executed, the command simply specifies the disk drive to be checked and the number of disk blocks for that drive.

Syntax format: badblocks [parameter]

Common parameters:

-b Specifies the chunk size of the disk in bytes-o Writes the results of the check to the specified output file-s Displays progress during check-v Displays detailed information during execution-w Performs a write test during check

Reference Example

Scan the hard disk by command:

[root@linuxcool ~]# badblocks -s -v /dev/sdnx

where n represents the hard disk device name, x represents the partition number corresponding to the hard disk, for example, you need to check "/dev/sda2":

[root@linuxcool ~]# badblocks -s -v /dev/sda2 Checking blocks 0 to 30681000 Checking for bad blocks (read-only test): 306809600674112/ 306810000000 30680964306809653068096630680967306809683068096930680970306809713068097230680973 ... done Pass completed, 37 bad blocks found. where "37 bad blocks found" means there are 37 bad blocks on the hard drive.

Take 4096 bytes as a "block", check each "block" once, output the result to the file "hda-badblocks-list.1", starting with block 51000 and ending with block 63000:

[root@linuxcool ~]# badblocks -b 4096 -c 1 /dev/hda1 -o hda-badblocks-list.1 63000 51000

Scan the hard disk for damaged sectors or blocks and write to the bad-blocks.txt file under the temporary folder:

[root@linuxcool ~]# badblocks -v -o /dev/sdb > /tmp/bad-blocks.txt

If a bad track is found, a write scan can be performed to repair it. Write scan will automatically remap when bad track is encountered. Write scan will overwrite the original data, so please backup first. Write scanning speed is very low, so you should only scan the parts where errors are found during read-only scanning:

[root@linuxcool ~]# badblocks -w -s /dev/sdb END START

Replace END and START with the block numbers of the end and start.

After reading this article, I believe you have a certain understanding of using the badblocks command in linux to check the damaged blocks in the disk device. If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!

Tags: Check block disk command device hard disk file parameter byte time article result time display output information unit backup size finished instance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei MariaDB Apple Shulou Technology