Linux checks hard disk for damaged sectors and blocks

Source: Internet
Author: User

Function Description: Check the damaged block in the disk appliance.

Syntax: badblocks [-svw][-b < chunk size >][-o < output file >][disk device] [disk block count] [start Block]

Supplementary Note: The instructions must be executed to specify the disk device to be inspected and the number of disk blocks for the appliance.

A hard drive is a lossy device that can cause physical failures such as bad times when used for a period of time. Computer hard disk after bad, if not in time to replace or technical processing, bad road will be more and more, and will cause frequent crashes and data loss. The best way is to replace the disk, but in the temporary case, should be in time to block the bad section of the sector, do not touch them. Badblocks is a tool to check the location of the bad track.
First, command parameters
Badblocks uses the 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]
The parameter meaning is:
Reference
-B blocksize
Specifies the chunk size, in bytes, of the disk, and the default value is Block 4K (4k/block)
-C blocksize
Number of checks per block, default is 16 times
-F
To force a read or write test operation to be performed on a device that is already mounted
(We recommend umount the equipment before the bad track detection.) You can use this option only if/etc/mtab has a false positives device mount error.
-I. File
Skip the bad track already displayed in the file, without detection (you can avoid duplicate detection)
-O File
Output test results to file files
-P Number
Repeat the search device until no new bad block location is found in the specified number of passes, the default number is 0
-S
Show progress while checking
-T pattern
Blocks are detected by reading and writing in the specified mode. You can specify a decimal positive value of 0 to ulong_max-1, or use random (random).
If you specify more than one pattern, Badblocks will use the first mode to detect all blocks and then use the next mode to detect all the blocks.
The read-only mode accepts only one pattern, and it cannot accept random mode.
-V
Display detailed information at execution time
-W
Write to each block before reading the information from it
[Device]
Specifies the disk appliance to check.
[Last-block]
Specifies the total number of blocks for the disk appliance.
[Start-block]
Specify which block to start checking

Step: 1 Use the FDISK command to identify hard drive information

# sudo fdisk-l

Step: 2 Scan hard disk for damaged sectors or blocks

# sudo badblocks-v/dev/sdb >/tmp/bad-blocks.txt
Simply replace "/dev/sdb" with the hard disk/partition of your own machine. After executing the above command, a text document named "Bad-blocks" will be created in/TMP and will contain all the corrupted blocks.

For example:

Step: 3 Prompts the operating system not to use corrupted block storage

After the scan is complete, if the damaged blocks are found and then use "Bad-blocks.txt" through the E2FSCK command, the operating system is forced to not use these corrupted chunks to store the data.

# sudo e2fsck-l/tmp/bad-blocks.txt  /dev/sdb
Note: Before running the e2fsck command, make sure the device is not mounted.
For more help with the badblocks and e2fsck commands, please refer to the following man page
# Man Badblocks
# mans E2FSCK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.