22
July
2022
How to check hard drive for bad sectors or bad blocks in Linux
15:01

How to check hard drive for bad sectors or bad blocks in Linux

22 July 2022 15:01
  1. Poor sectors are called disk sections from which it is impossible to read either information on them, or the access speed is significantly (several orders of magnitude) lower than that of the rest of the sectors.

The importance of monitoring the number of bad sectors

Timely detection of "flying" sectors allows you to save most of the information from the carrier. Usually, the failure of any carrier begins gradually - at first single Bad blocks appear, then their number grows. The appearance of BAD'S is associated with the physical damage of the device (for example, from a severe concussion with a laptop with an HDD disc), or wear of the storage device (more characteristic of the SSD disk), or a gross violation of operating conditions (power outage during operation). With an increase in the number of BAD blocks, an immediate replacement of a faulty disk with a new one is necessary, with the transfer of the operating system and information from the "home" user catalogs.

How to find out the number of bad sectors in Linux

First, we will display a list of available discs and sections on:

lsblk

We find our device in the list (for example,sdb):

user@linux ~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 37,3G 0 disk
sdb 8:16 0 119,2G 0 disk
├─sdb1 8:17 0 32,3G 0 part
├─sdb2 8:18 0 4,9G 0 part
├─sdb3 8:19 0 1K 0 part
└─sdb5 8:21 0 82,1G 0 part /
sdc 8:32 0 465,8G 0 disk
└─sdc1 8:33 0 391,2G 0 part
sdd 8:48 1 250M 0 disk
├─sdd1 8:49 1 250M 0 part /media/vladimir/7E2B-BE10
└─sdd4 8:52 1 39,5M 0 part
sr0 11:0 1 1024M 0 rom

In this case, I took a small flash drive with a volume of 256 MB. - /DEV /SDD

Solution: Checking the disk on the Badblocks with utility BAD blocks

Disk scan on BAD blocks:

sudo badblocks -sv /dev/sdd

Where the key "S" serves to display the percentage of execution.
The parameter "V" - for the output of detailed information after the end of work.

If there are no errors, the message will be displayed:

Without a key -v
Checking for bad blocks (read-only test): done

With the key -v
Pass completed, 0 bad blocks found. (0/0/0 errors)

On severely damaged discs, it makes sense to interrupt the execution after detecting a certain number of damage. For example, if the number of BAD blocks is more than 20, interrupt the test:

Team - stop testing after 20 errors:

sudo badblocks -se 20  /dev/sdd

If the physical size of the sector, for example, 512 bytes, can be specified, you can clarify it in the team parameters. Then, the number of sectors of 512 bytes, not blocks, will be displayed.

Sudo Badblocks -sve 20 /DEV /SDD -B 512

The size of the physical sector can be found using the FSIDK -L command

 fdisk -l 

Difference: in the first case, blocks (default 1024 bytes) were checked, in the latter - sector (512 bytes).
Their number differs significantly.

Thus, we can find out the number of bad blocks on the device using the command line and the Badblocks utility.

Correction of BAD blocks using the E2FSK -c command

Addition from 01.08.2023
Usually, not only detection is required, but also the power of the BAD blocks.
The E2FSCK -C & LAQUO; name_toma & raquo; Calls the command badblocks при использовании ключа -c в режиме проверки (check).
At the same time, all the bad blocks found are processed by E2FSCK, marked as “bad” (information cannot be recorded on them). This command operates like a Chkdsk C: /F /R /X Windows team, but in Linux for a file system type Ext4:

sudo e2fsck -c /dev/sda1

where SDA1 is the name of Tom (see LSBLK conclusion).

Quick receipt of information about the number of BAD blocks using GNOME DISKS

When using a hard drive with SMART support, to quickly derive the number of bad blocks using the Gnome-Disks graphic utility

The Gnome-Desks utility displays the exact number of BAD blocks.

1) Install the GNOME-DISKS program:

sudo apt-get install gnome-disk-utility

2) Then we launch the program in the "Start" menu - "standard" - "wheels":
Or from the command line:

gnome-disks

3) Choose a disk.

4) the number of bad blocks is displayed in the window:
Diagnostics

5) if a detailed diagnosis is needed, we go to the menu with 3 points (more),
select the menu item "Self -diagnostics data and Smart"

6) Stretch the window over the entire screen and look for the item "Figant sectors"
out_of_work

Addition: GSMARTCONTROL utility for reading information S.M.A.R.T.

For Linux, there is a utility for viewing internal diagnostics of HDD and SSD hard drives, called GsmartControl.

sudo apt install gsmartcontrol

Launch using the Start menu - "system" - "GSMARTCONTROL" or team:

sudo gsmartcontrol-root

The appearance of the windows of the GSMARTCONTROL program:

GSMARTCONTROL1

GSMARTCONTROL2

Information about BAD blocks is available on the "Attributes" bookmark:

  • Parameter "Offline unrecoverable"

The number of blocks approaching the “Bad-Block” state, the data from which are moved to the reserve area of the hard drive:

  • Parameter "Reallocated Sector Count" .

Obviously, the good disk has both numbers of "Offline Unrecoverable" and "Reallocated Sector Count" should be zeros.

Note: the high values of the “Seek Error Rate” parameter (several thousand) indicate serious problems with the positioning of the magnetic heads of the hard disk, are usually found in old “hard drives”. Such hard drives require replacement due to problems with mechanics. The “RAW Read Error Rate” is not a thano one indicates problems with the surface of the disk.

A short check (self-testing) is available on the "SELF-TESTS" . On HDD, the duration of testing is about 2 minutes, for SSD - about 40 seconds.

GSMARTCONTROL3

At the end of the audit, the program concludes about the suitability of the disk. Message "Test Result: Completed Without Error" means that electronics (and mechanics in the case of HDD) are working:

Selftest

home page GSMARTCONTROL:
https://gsmartcontrol.shaduri.dev/

Diagnostic conclusion S.M.A.R.T. by command line

If GSMARTControl is not possible to install, in many distributions there is a command line utility "Smartctl" , which tests the disk and can output S.M.A.R.T.

Usage:

sudo smartctl --test=short /dev/sda

After starting a quick disk check, you need to wait 2 minutes (the test is made in the background).
After 120 seconds, you need to execute the second command:

sudo smartctl -H /dev/sda

Conclusion of the command: Passed - Healthy disk, Failed - disk is faulty.

If necessary, we get all the information about the health of the disk:

sudo smartctl -a /dev/sda | less

The transition to the next screen is the gap key.

In the output results, the diagnostic parameters listed below should be zeros:
1 "raw_read_error_rate"
5 "REALLOCATED_SECTOR_CT"
196 "Reallocated_Event_count"
197 "Current_pending_Sector"
198 "Offline_uncorrectable"
232 "AVAILABLE_RESERVD_SPACE"

The result of a short check in the case of a good disk:
Status: "Competed Without Error"



Related publications