Check the damaged sectors and blocks of the hard disk in linux.
BadblocksIs a command tool for linux and similar operating systems to scan and check hard disks and external devices for damaged sectors. The damaged sector or block is the space that is permanently damaged in the hard disk or cannot be read by the operating system.
The Badblocks command can detect all corrupted sectors or blocks in the hard disk and save the results in a text file. In this way, we can useE2fsckCommand to configure the operating system to not store data in these corrupt sectors.
Step: 1. Use the fdisk command to identify hard disk Information
- # sudo fdisk -l
Step 2. Scan the damaged sectors or blocks of the hard disk
- # sudo badblocks -v /dev/sdb > /tmp/bad-blocks.txt
Replace "/dev/sdb" with the hard disk/partition of your machine. After the preceding command is executed, a text file named "bad-blocks" will be created under/tmp, And it will contain all corrupted blocks.
For example:
Step 3: prompt the operating system not to use damaged Block Storage
After scanning, if the damaged block is discovered, the e2fsckcommand will be used to use “bad-blocks.txt, forcing the operating system not to use the damaged block to store data.
- # sudo e2fsck -l /tmp/bad-blocks.txt /dev/sdb
Note: before running the e2fsck command, ensure that the device is not mounted.
For more help on badblocks and e2fsck commands, refer to the following man page:
- # man badblocks
- # man e2fsck
Via: http://www.linuxtechi.com/check-hard-drive-for-bad-sector-linux/
Author: Pradeep Kumar Translator: Vic ___ Proofreader: Caroline
Http://linux.cn/article-3671-1.html.