hdparm is a disk utility that allows for low level commands to be sent to the storage device.
Usage[edit | edit source]
hdparm can be used to on any mass storage device.
Disk Information[edit | edit source]
Use hdparm -I /dev/disk
to show hardware properties of the device.
# hdparm -I /dev/sdb
/dev/sdb:
ATA device, with non-removable media
Model Number: ST3000DM001-9YN166
Serial Number: W1F0SJ27
Firmware Revision: CC4B
Transport: Serial, SATA Rev 3.0
Standards:
Used: unknown (minor revision code 0x0029)
Supported: 8 7 6 5
Likely used: 8
Configuration:
Logical max current
cylinders 16383 16383
heads 16 16
sectors/track 63 63
--
CHS current addressable sectors: 16514064
LBA user addressable sectors: 268435455
LBA48 user addressable sectors: 5860533168
Logical Sector size: 512 bytes
Physical Sector size: 4096 bytes
Logical Sector-0 offset: 0 bytes
device size with M = 1024*1024: 2861588 MBytes
device size with M = 1000*1000: 3000592 MBytes (3000 GB)
cache/buffer size = unknown
Nominal Media Rotation Rate: 7200
Capabilities:
LBA, IORDY(can be disabled)
Queue depth: 32
Standby timer values: spec'd by Standard, no device specific minimum
R/W multiple sector transfer: Max = 16 Current = ?
Advanced power management level: 128
Recommended acoustic management value: 208, current value: 0
DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6
Cycle time: min=120ns recommended=120ns
PIO: pio0 pio1 pio2 pio3 pio4
Cycle time: no flow control=120ns IORDY flow control=120ns
Commands/features:
Enabled Supported:
* SMART feature set
Security Mode feature set
* Power Management feature set
* Write cache
* Look-ahead
* Host Protected Area feature set
* WRITE_BUFFER command
* READ_BUFFER command
* DOWNLOAD_MICROCODE
* Advanced Power Management feature set
SET_MAX security extension
* 48-bit Address feature set
* Device Configuration Overlay feature set
* Mandatory FLUSH_CACHE
* FLUSH_CACHE_EXT
* SMART error logging
* SMART self-test
* General Purpose Logging feature set
* WRITE_{DMA|MULTIPLE}_FUA_EXT
* 64-bit World wide name
Write-Read-Verify feature set
* WRITE_UNCORRECTABLE_EXT command
* {READ,WRITE}_DMA_EXT_GPL commands
* Segmented DOWNLOAD_MICROCODE
* Gen1 signaling speed (1.5Gb/s)
* Gen2 signaling speed (3.0Gb/s)
* Gen3 signaling speed (6.0Gb/s)
* Native Command Queueing (NCQ)
* Phy event counters
* READ_LOG_DMA_EXT equivalent to READ_LOG_EXT
DMA Setup Auto-Activate optimization
Device-initiated interface power management
* Software settings preservation
* SMART Command Transport (SCT) feature set
* SCT Write Same (AC2)
unknown 206[7]
unknown 206[12] (vendor specific)
unknown 206[13] (vendor specific)
Security:
Master password revision code = 65534
supported
not enabled
not locked
not frozen
not expired: security count
supported: enhanced erase
330min for SECURITY ERASE UNIT. 330min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 5000c500529df4f3
NAA : 5
IEEE OUI : 000c50
Unique ID : 0529df4f3
Checksum: correct
Disk Timing and Benchmark[edit | edit source]
Use hdparm -t
to benchmark how fast the disk can be read. The documentation suggests running this a few times on an idle system for the best result.
Because disks start from the outside of the platter, an offset could be used to test disk performance in another area with the --offset <GiB>
parameter. For example, a 8TB disk could be benchmarked with an offset of 4000 GB to see the read speed somewhere near the middle of the platter.
Tuning[edit | edit source]
You can tune how many sectors the disk is to return for each data transmission to help speed up disk reads. According to the manual, this can help with the OS I/O overhead by 30-50% and may improve throughput between 5%-50%. Eg: hdparm -m16
You can improve sequential reads of large files by setting a hread-ahead value. This specifies how many sectors to read-ahead by in anticipation of them being read later on. Set this with the -a
option: hdparm -a16
.
Acoustic modes can be set with -M
, passing either 128 (for quiet mode), or 254 (fastest).
Tasks[edit | edit source]
Repair a bad sector[edit | edit source]
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...