Using hdparm for SATA Drive Parameters in Linux

The hdparm utility is a command-line Linux tool designed to inspect, measure, and modify hardware parameters on SATA and IDE storage devices. It functions by issuing low-level commands through the Linux kernel directly to the drive controller, allowing administrators to benchmark throughput, configure power-saving modes, toggle write caching, and read hardware identity information. This article explains the underlying mechanism hdparm uses to interact with SATA storage and details how it performs both measurement and parameter modification.

How hdparm Communicates with SATA Drives

Although modern SATA drives present themselves as SCSI devices in Linux (typically under /dev/sdX) via the kernel's libata subsystem, hdparm communicates using ATA command sets.

  1. System Calls and IOCTLs: hdparm uses ioctl() (Input/Output Control) system calls, specifically HDIO_* commands or the generic SG_IO (SCSI Generic) interface.
  2. SAT (SCSI-to-ATA Translation): Because SATA drives are managed by libata, hdparm packages ATA commands inside SCSI Pass-Through commands. The kernel's SCSI-to-ATA Translation Layer receives these commands, unpacks them into ATA Taskfile registers (Frame Information Structures or FIS), and transmits them across the physical SATA bus directly to the drive’s onboard firmware.

Measuring Drive Parameters and Performance

hdparm queries drive telemetry and evaluates read throughput through dedicated flags.

1. Hardware Identification (-I)

Running hdparm -I /dev/sdX instructs the drive controller to execute the ATA IDENTIFY DEVICE command (opcode 0xEC). The drive responds with a 512-byte data structure containing hardcoded factory parameters and active runtime configurations, such as:

2. Cache and Buffer Read Benchmarks (-t and -T)

Setting Drive Parameters

When used to alter hardware settings, hdparm constructs specific ATA commands that change non-volatile or volatile configuration registers within the drive's firmware.

1. Write Caching (-W)

2. Advanced Power Management (-B)

3. Standby/Spindown Timeout (-S)

4. Acoustic Management (-M)

Persistence of Changes

Parameters set by hdparm operate at the drive's runtime firmware level. Because most SATA parameters set via SET FEATURES reset when the device loses power, Linux distributions maintain persistent settings by re-applying hdparm rules during the boot process via /etc/hdparm.conf or udev rules triggered when the block device node is created.