Detect disk bad sectors
When the disk following occurs:
io wait unreasonably high or higher;
Hard disk voice suddenly from the original Friction sound into a strange sound;
The system can not start normally, appear "IO error" message and so on;
mkfs time, progress to a standstill, the last error, can not be completed;
Each time the system will run fsck boot scan disk error;
When the implementation of disk fdisk, to a certain schedule will be repeated forward and backwards.
Appears above situation, the need for timely detection of bad sectors on the disk timely detection of bad sectors on the disk to disk test availability, and back up data immediately.
1. bad blocks and bad sectors on a hard disk system for detecting the linux
1. View displays information about all disk or flash by fdisk
fdisk -l /dev/sd*
2. Check badlocks bad sectors on the hard disk linux / bad blocks
# badblocks -v /dev/sdb1 > badsectors.txt 或者 # badblocks -s -v /dev/sdb1 > badsectors.txt Checking blocks 0 to 20970495 Checking for bad blocks (read-only test): done Pass completed, 0 bad blocks found. (0/0/0 errors)
Note: -v option to let it show operating details
Disk has bad sectors
Premise: If there are bad sectors, provided that the data do a backup, do the important data backed up trying to repair.
If you do not find bad sectors on the disk, unmount the disk and the system like this do not write data to the sector in reporting.
Execute e2fsck (for ext2 / ext3 / ext4 file system) or fsck command, the command also need to use badsectors.txt files and device files.
NOTE: -l option tells the command to the sector number will be listed in the file specified badsectors.txt added to the bad blocks list.
------------ 针对 for ext2/ext3/ext4 文件系统 ------------ # e2fsck -l badsectors.txt /dev/sdb1 e2fsck 1.42.9 (28-Dec-2013) /dev/sdb1: Updating bad block inode. Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sdb1: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sdb1: 12/1310720 files (8.3% non-contiguous), 128782/5242624 blocks
------------ for other file systems ------------ $ sudo fsck badsectors.txt the -l / dev / SDA10
fsck
parameter:
filesys: disk device name (eg./dev/sda1), mount (mount) point (eg / or / usr.)
-t: Given the type of file system, or kernel itself has been defined support if the / etc / fstab of this parameter plus you do not need
-s: sequentially one by one to check execution instruction fsck
-A: on / etc / fstab all listed partitions (Partition) for tests
-C: display a complete check progress
-d: Print out e2fsck Debug results
-p: At the same time there is -A conditions, while checks performed along a plurality of fsck
-R: -A while when conditions are omitted / not checked
-V: detailed display mode
-a: If the check is wrong then automatically fix
-r: If the check is wrong by the user to answer whether repair
-y: option specifies detect each file is automatically entered yes, the uncertainty that is not normal, they can perform all the checks # fsck -y repair .
2. Use Smartmontools tool to scan bad sectors on Linux
This method is more reliable and efficient on modern disks with SMART (Self-Monitoring Analysis and Reporting Technology Self-Monitoring, Analysis and Reporting Technology ) system (ATA / SATA and SCSI / SAS hard drives and solid state drives). SMART system can help detect, report, and may record their state of health, so you can identify any potential hardware failure.
You can use the following command to install smartmontools:
------------ system it based on Debian / Ubuntu of ------------
$ sudo apt-get install smartmontools
------------ based on the system RHEL / CentOS of ------------
$ sudo yum install smartmontools
After the installation is complete, use the integrated SMART disk smartctl control system. So you can see its manual or help:
$ man smartctl $ smartctl -h
Smartctrl then execute the command and specify your equipment in the command as an argument, the following command contains a parameter -H or --health to display the overall health of SMART self-assessment test results.
$ sudo smartctl -H /dev/sda10
Check the Linux hard drive health
above results indicate that your hard drive is healthy, hardware failure is unlikely to happen in the near future.
To get an overview of disk information, use -a or --all option to display all SMART information about the disk, -x or --xall to display all the information about SMART disk and non-SMART information.