Hdparm: Difference between revisions
| Line 144: | Line 144: | ||
| lang = terminal | | lang = terminal | ||
}} | }} | ||
It may take <code>hdparm</code> some time before showing the success message if the disk needs to reallocate the sector. If the corrupt sector was reallocated, you should see both the <code>Reallocated_Sector_Ct</code> and <code>Reallocated_Event_Count</code> value increase and the <code>Current_Pending_Sector</code> decrease. | It may take <code>hdparm</code> some time before showing the success message if the disk needs to reallocate the sector. If the corrupt sector was reallocated, you should see both the <code>Reallocated_Sector_Ct</code> and <code>Reallocated_Event_Count</code> value increase and the <code>Current_Pending_Sector</code> decrease. | ||
After writing to a sector and forcing a sector reallocation, try writing to the disk with <code>dd</code>. If you continue to experience errors, try rewriting the sectors near where the error took place and then try again.<br />{{Navbox Linux}} | |||
<br />{{Navbox Linux}} | |||
[[Category:Linux]] | [[Category:Linux]] | ||
[[Category:LinuxUtilities]] | [[Category:LinuxUtilities]] | ||
Revision as of 03:28, 3 April 2021
hdparm is a disk utility that allows for low level commands to be sent to the storage device.
Usage
hdparm can be used to on any mass storage device.
Disk Information
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
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
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
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 by issuing low-level write command directly to the disk.
# hdparm --write-sector 4005685760 --yes-i-know-what-i-am-doing /dev/sdb
## This could take some time if the disk needs to reallocate the sector.
/dev/sdb:
re-writing sector 4005685760: succeeded
## In cases where you think there's a range of bad sectors, you can do something like:
# for i in {1000..1010} ; do echo $i ; hdparm --write-sector $i --yes-i-know-what-i-am-doing /dev/sdb ; done
It may take hdparm some time before showing the success message if the disk needs to reallocate the sector. If the corrupt sector was reallocated, you should see both the Reallocated_Sector_Ct and Reallocated_Event_Count value increase and the Current_Pending_Sector decrease.
After writing to a sector and forcing a sector reallocation, try writing to the disk with dd. If you continue to experience errors, try rewriting the sectors near where the error took place and then try again.