>_cmd.script

hdparm

Get/set SATA and IDE disk drive parameters

Disk

By CMD Script Team · 4 min read · Last updated

SYNTAX
hdparm [OPTIONS] DEVICE

Options

Command options and flags
FlagDescription
-iShow identification info reported by the drive (model, firmware, geometry)
-IShow detailed identification info direct from the drive (ATA IDENTIFY data)
-tTime buffered (physical) disk reads without cache benefit
-TTime cached reads from the buffer cache (memory speed, not disk speed)
-tTRun both cached and buffered read timing tests in one pass
-WGet/set the drive's write-caching feature, e.g. -W 0 to disable
-CCheck the drive's current power management state (active/idle/standby)
-yForce the drive to enter standby mode immediately

Distribution compatibility

  • Ubuntu
  • Debian
  • Fedora
  • Arch
  • macOS (not available)

What it does

hdparm gets and sets parameters on SATA/IDE (ATA-family) hard disks on Linux, operating directly on a block device like /dev/sda. It can report drive identification data, benchmark raw read throughput, toggle features like write caching or the drive's acoustic management, and control power states (spin-down/standby). It's a low-level tool that talks to the drive's firmware through the kernel's ATA ioctl interface, so it mostly applies to spinning disks and SATA SSDs rather than NVMe.

Beginner examples

  • sudo hdparm -i /dev/sda — show drive identification (model, firmware revision, geometry)
  • sudo hdparm -I /dev/sda — show the full detailed ATA IDENTIFY data
  • sudo hdparm -tT /dev/sda — quick read-speed benchmark (cached and buffered)
  • sudo hdparm -C /dev/sda — check whether the drive is active, idle, or in standby
sudo hdparm -tT /dev/sda

Advanced examples

  • Compare read throughput across two drives to spot a failing one: sudo hdparm -tT /dev/sda /dev/sdb
  • Disable write caching for safety on a drive without a battery-backed controller: sudo hdparm -W 0 /dev/sda
  • Force a drive to spin down into standby to save power or reduce noise: sudo hdparm -y /dev/sda
  • Set the standby (spin-down) timeout so the drive sleeps after inactivity: sudo hdparm -S 120 /dev/sda
  • Check and set the Advanced Power Management level (lower = more aggressive power saving): sudo hdparm -B 127 /dev/sda
sudo hdparm -tT /dev/sda /dev/sdb

Common mistakes

  • Running hdparm -tT on an SSD and drawing conclusions about "disk speed" — the numbers are useful for relative comparisons but don't reflect real-world random I/O performance.
  • Forgetting sudo, which causes silent permission errors or truncated output instead of a clear failure.
  • Assuming hdparm works the same way on NVMe drives — most feature flags and timing commands are ATA-specific and simply don't apply.
  • Changing write-cache or power settings (-W, -B, -S) on a production disk without understanding the durability tradeoff — disabling write cache is safer but slower; enabling it is faster but risks data loss on power failure without a UPS.

Tips

  • Run -tT a few times in a row; the first run may be affected by prior cache state, so a couple of repeats give a more stable benchmark.
  • Use -I (capital) instead of -i when you need the full raw IDENTIFY payload, including supported features, security status, and SMART capability flags.
  • -C is a quick, non-destructive way to check if a drive is spun down without waking it (unlike issuing a read, which would force it to spin up).
  • Combine with smartctl (from smartmontools) for actual health/SMART data — hdparm doesn't do health diagnostics, only parameter get/set and basic timing.

Best practices

  • Always double-check the target device (/dev/sda vs /dev/sdb) before changing settings — running the wrong flag against the wrong disk can silently degrade performance or reliability.
  • Avoid destructive-sounding flags (like security erase commands) unless you fully understand ATA security features; a misused command can lock a drive.
  • Persist power-management changes (like -B, -S) via a udev rule or systemd unit, since hdparm settings are typically not retained across reboots by default.
  • Use -tT for quick sanity checks only; for serious benchmarking use fio or dd with oflag=direct to get more controlled, reproducible numbers.

Try it yourself

A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.

Real-world use cases

  • Diagnosing a suspected failing hard drive by comparing its buffered read throughput against a known-good drive of the same model.
  • Tuning laptop power consumption by adjusting a spinning disk's standby timeout and APM level to reduce battery drain.
  • Verifying that write caching is enabled/disabled as expected after a firmware update or RAID controller configuration change.

Common interview questions

  • What's the difference between hdparm's -t and -T flags? -T measures cached reads from the buffer cache (memory speed); -t measures buffered/physical reads directly from the disk, bypassing cache, giving a real disk throughput estimate.
  • Why doesn't hdparm work well on NVMe drives? hdparm speaks the legacy ATA command set over an ioctl interface; NVMe drives use a different command protocol over PCIe, so most hdparm features don't apply — nvme-cli is the NVMe equivalent.
  • How would you check if a drive has spun down without waking it up? hdparm -C /dev/sda queries the power state without issuing an I/O request, so it won't force the drive to spin up.

Frequently Asked Questions

Why do I need sudo to run hdparm?

hdparm issues low-level ioctl calls directly to the block device (e.g. /dev/sda), which requires root privileges. Run it as sudo hdparm ...

Does hdparm work on NVMe SSDs?

Only partially. hdparm was designed for the older ATA/SATA command set. Most NVMe drives don't support hdparm's timing or feature-toggle commands; use nvme-cli for NVMe-specific tuning instead.

What's the difference between -t and -T?

-T times reads from the Linux buffer cache (RAM speed, no disk I/O), used as a baseline. -t times actual reads from the disk, bypassing cache, showing real physical throughput. Running -tT together gives both numbers for comparison.

Is hdparm available on macOS?

No. macOS uses IOKit and diskutil to manage storage devices; hdparm's ioctl interface is Linux-specific and isn't ported to macOS.

Cheat sheet

Download a quick-reference cheat sheet for hdparm.