Home >php教程 >PHP开发 >How to detect bad sectors and blocks on your hard drive on Linux

How to detect bad sectors and blocks on your hard drive on Linux

高洛峰
高洛峰Original
2016-11-18 09:15:551415browse

Let’s start with the definition of bad sectors and bad blocks. They are parts of a disk or flash memory that can no longer be read or written, usually due to specific physical damage to the disk surface or failure of the flash memory transistors.

As bad sectors continue to accumulate, they can have unpleasant or damaging effects on your disk or flash memory capacity, and may even cause hardware failure.

At the same time, it is also important to note that the presence of bad blocks is a warning that you should start thinking about buying a new disk, or simply mark the bad blocks as unusable.

So, in this article, we go through a few necessary steps to use a specific disk scanning tool to enable you to determine whether a Linux disk or flash memory has bad sectors.

Here are the steps:

Use the Bad Block Tool to check for bad sectors on Linux

The Bad Block Tool allows users to scan the device to check for bad sectors or blocks. The device can be a disk or external disk and is represented by a file such as /dev/sdc.

First, execute the fdisk command with superuser privileges to display the information of all your disks or flash drives and their partition information:

$ sudo fdisk -l

How to detect bad sectors and blocks on your hard drive on Linux

List Linux file system partitions


Then check you with the following command Bad sectors/bad blocks on the Linux hard disk:

$ sudo badblocks -v /dev/sda10 > badsectors.txt

How to detect bad sectors and blocks on your hard drive on Linux

Scan the hard disk for bad sectors on Linux


In the above command, badblocks scans the device /dev/sda10 (remember to specify your actual device), The -v option causes it to display details of the operation. In addition, output redirection is used here to redirect the operation results to the file badsectors.txt.

If you find any bad sectors on your disk, unmount the disk and tell the system not to write data to the reported sectors as below.

You need to execute the e2fsck (for ext2/ext3/ext4 file system) or fsck command. The badsectors.txt file and device file are also required in the command.

The -l option tells the command to add the sector numbers listed in the specified file badsectors.txt to the bad block list.

------------ 针对 for ext2/ext3/ext4 文件系统 ------------  
$ sudo e2fsck -l badsectors.txt /dev/sda10  
或  
------------ 针对其它文件系统 ------------  
$ sudo fsck -l badsectors.txt /dev/sda10

Use Smartmontools tool to scan for bad sectors on Linux

This method is suitable for modern disks (ATA/SATA and SCSI/SAS hard drives with S.M.A.R.T (Self-Monitoring, Analysis and Reporting Technology) system) and solid-state drives) are more reliable and efficient. S.M.A.R.T systems can help detect, report, and possibly record their health so you can identify any possible hardware failures.

You can install smartmontools using the following command:

------------ 在基于 Debian/Ubuntu 的系统上 ------------
$ sudo apt-get install smartmontools
------------ 在基于 RHEL/CentOS 的系统上 ------------
$ sudo yum install smartmontools

After the installation is complete, use smartctl to control the disk-integrated S.M.A.R.T system. You can view its manual or help like this:

$ man smartctl$ smartctl -h

Then execute the smartctrl command and specify your device as a parameter in the command. The following command includes the parameter -H or --health to display the SMART overall health self-assessment test results.

$ sudo smartctl -H /dev/sda10

How to detect bad sectors and blocks on your hard drive on Linux

Check Linux hard drive health


The above results indicate that your hard drive is healthy and hardware failure is unlikely to occur in the near future.

To get an overview of disk information, use the -a or --all option to display all SMART information about the disk, and -x or --xall to display all SMART information about the disk as well as non-SMART information.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn