(Created page with "hdparm is a disk utility that allows for low level commands to be sent to the storage device. == Repair a bad sector == If you have a bad sector that the disk is unable to re...")
 
Line 1: Line 1:
 
hdparm is a disk utility that allows for low level commands to be sent to the storage device.
 
hdparm is a disk utility that allows for low level commands to be sent to the storage device.
  
== Repair a bad sector ==
+
==Repair a bad sector==
 
If you have a bad sector that the disk is unable to read, you can use hdparm to write to a specific sector which will hopefully cause the disk to remap the bad sector to a good sector. This process is done transparently by the disk's firmware and the number of bad sectors that have been reallocated can be seen under the <code>Reallocated_Sector_Ct</code> parameter on SMART.
 
If you have a bad sector that the disk is unable to read, you can use hdparm to write to a specific sector which will hopefully cause the disk to remap the bad sector to a good sector. This process is done transparently by the disk's firmware and the number of bad sectors that have been reallocated can be seen under the <code>Reallocated_Sector_Ct</code> parameter on SMART.
  
Line 96: Line 96:
 
0000 0000 0000 0000 0000 0000 0000 0000
 
0000 0000 0000 0000 0000 0000 0000 0000
 
| lang = terminal
 
| lang = terminal
}}
+
}}But the reallocate sector count didn't increase...
 +
 
 +
Something's wonky with this...

Revision as of 12:57, 31 July 2020

hdparm is a disk utility that allows for low level commands to be sent to the storage device.

Repair a bad sector

If you have a bad sector that the disk is unable to read, you can use hdparm to write to a specific sector which will hopefully cause the disk to remap the bad sector to a good sector. This process is done transparently by the disk's firmware and the number of bad sectors that have been reallocated can be seen under the Reallocated_Sector_Ct parameter on SMART.

Given the following message, we know that LBA 4005685760 is bad:

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
 1  Extended offline    Completed: read failure       40%     12786         4005685760

We can confirm this by attempting to read that sector with dd or hdparm:

# dd if=/dev/sdb of=/dev/null skip=4005685760 bs=512 conv=sync
dd: error reading '/dev/sdb': Input/output error

# hdparm --read-sector 4005685760  /dev/sdb
/dev/sdb:
reading sector 4005685760: FAILED: Input/output error

Using hdparm, we can write to this specific sector. As per hdparm's man page, the write-sector issues a low-level write command directly to the disk. (Question: Does this mean the write-sector will ignore remapped sectors by the disk firmware?) We may also try the same with dd. In fact, dd'ing the entire disk with zeros is a sure way of finding and remapping all bad sectors on a drive.

# dd if=/dev/zero of=/dev/sdb skip=4005685760 bs=512 count=1 conv=sync

# hdparm --write-sector 4005685760 --yes-i-know-what-i-am-doing /dev/sdb
## A very long time later:
/dev/sdb:
re-writing sector 4005685760: succeeded

hdparm took a very long time before showing the success message. dmesg shows that the disk is still having I/O errors on that logical block:

[Fri Jul 31 11:22:36 2020] blk_update_request: I/O error, dev sdb, sector 0 op 0x1:(WRITE) flags 0x800 phys_seg 0 prio class 0
[Fri Jul 31 11:22:38 2020] sd 2:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE cmd_age=1s
[Fri Jul 31 11:22:38 2020] sd 2:0:0:0: [sdb] tag#0 Sense Key : Medium Error [current] 
[Fri Jul 31 11:22:38 2020] sd 2:0:0:0: [sdb] tag#0 Add. Sense: Unrecovered read error
[Fri Jul 31 11:22:38 2020] sd 2:0:0:0: [sdb] tag#0 CDB: Read(16) 88 00 00 00 00 00 ee c1 ea 00 00 00 00 08 00 00
[Fri Jul 31 11:22:38 2020] blk_update_request: critical medium error, dev sdb, sector 4005685760 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 timing out command, waited 360s
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE cmd_age=360s
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 Sense Key : Hardware Error [current] 
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 Add. Sense: Internal target failure
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 CDB: Synchronize Cache(10) 35 00 00 00 00 00 00 00 00 00
[Fri Jul 31 11:28:38 2020] blk_update_request: I/O error, dev sdb, sector 0 op 0x1:(WRITE) flags 0x800 phys_seg 0 prio class 0
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE cmd_age=0s
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 Sense Key : Medium Error [current] 
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 Add. Sense: Unrecovered read error
[Fri Jul 31 11:28:38 2020] sd 2:0:0:0: [sdb] tag#0 CDB: Read(16) 88 00 00 00 00 00 ee c1 ea 00 00 00 00 08 00 00
[Fri Jul 31 11:28:38 2020] blk_update_request: critical medium error, dev sdb, sector 4005685760 op 0x0:(READ) flags 0x0 phys_seg 8 prio class 0
[Fri Jul 31 11:28:38 2020] Buffer I/O error on dev sdb, logical block 4005685760, async page read
[Fri Jul 31 11:28:38 2020] Buffer I/O error on dev sdb, logical block 4005685761, async page read
[Fri Jul 31 11:28:38 2020] Buffer I/O error on dev sdb, logical block 4005685762, async page read
[Fri Jul 31 11:28:38 2020] Buffer I/O error on dev sdb, logical block 4005685763, async page read
[Fri Jul 31 11:28:38 2020] Buffer I/O error on dev sdb, logical block 4005685764, async page read
[Fri Jul 31 11:28:38 2020] Buffer I/O error on dev sdb, logical block 4005685765, async page read
[Fri Jul 31 11:28:38 2020] Buffer I/O error on dev sdb, logical block 4005685766, async page read
[Fri Jul 31 11:28:38 2020] Buffer I/O error on dev sdb, logical block 4005685767, async page read

However, the hdparm --read-sector on the sector now works, though dd still fails.

# dd if=/dev/sdb of=/dev/null skip=4005685760 bs=512 conv=sync
dd: error reading '/dev/sdb': Input/output error

# hdparm --read-sector 4005685760 /dev/sdb
/dev/sdb:
reading sector 4005685760: succeeded
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000

But the reallocate sector count didn't increase...

Something's wonky with this...