Inspect and Tune SATA Disks Safely with hdparm

A drive that will not spin down, or one that spins down so often it drags out every read, usually comes down to one setting hdparm can show you. This guide uses hdparm to inspect a disk, check its power state, run a read-only timing test, and persist one modest power-management setting through Debian's /etc/hdparm.conf. The installed package here is hdparm 9.65+ds-1build1, providing hdparm v9.65. Allow about 15 minutes, plus time to watch the disk after you change its standby policy.

Replace /dev/sdX with the whole disk you have identified, not a partition such as /dev/sdX1. Most commands need elevated privileges because they use device ioctls; the version check and device inventory do not.

1. Identify the target disk

Start with a read-only inventory. Do not guess the target from its size alone if the machine holds several similar disks.

$ lsblk -o NAME,MODEL,SERIAL,SIZE,TYPE,MOUNTPOINTS

Match the model, serial number and mount points against your hardware records. A whole-disk path looks like /dev/sda; a partition path ends in a partition number. Keep the placeholder until that match is confirmed.

Checkpoint: confirm the installed binary and version:

$ command -v hdparm
/usr/sbin/hdparm
$ hdparm -V
hdparm v9.65

2. Read the current settings

Ask for the common settings explicitly. With no options, hdparm assumes -acdgkmur, which is easy to forget when you are reading back through a script months later. The -I report goes further, reading the device's IDENTIFY data directly.

$ sudo hdparm -acdgkmur /dev/sdX
$ sudo hdparm -I /dev/sdX

Check the immediate power mode on its own:

$ sudo hdparm -C /dev/sdX
 /dev/sdX:
  drive state is:  active/idle

The possible states are unknown, active/idle, standby and sleeping; exact spacing and wording vary. A report of unknown is a device limitation, not a reason to force a different state onto it.

3. Measure reads without changing disk settings

-t times a device read; -T times a buffer-cache read. Both are benchmarks, not filesystem tests, and the -t run flushes the buffer cache while it works, so run it when nothing else is busy rather than treating it as a harmless production probe.

$ sudo hdparm -tT /dev/sdX

 /dev/sdX:
  Timing cached reads:   ... MB in ... seconds = ... MB/sec
  Timing buffered disk reads: ... MB in ... seconds = ... MB/sec

Run it two or three times on an otherwise quiet machine. Treat the numbers as comparisons for this host and kernel, not a spec sheet for the disk: cached reads mostly exercise memory and the processor, while buffered disk reads sit closer to sequential device throughput, still excluding filesystem overhead.

4. Change one temporary setting

-B controls Advanced Power Management where the drive supports it. Values 1 to 127 allow spin-down, 128 to 254 do not, and 255 asks the drive to disable APM entirely. Higher is not automatically better: a more aggressive setting can trade power for extra wake-ups and latency.

Record the old value from your earlier inspection, make the change in a maintenance window, and pick a value that suits the hardware. For a temporary test:

$ sudo hdparm -B 128 /dev/sdX
 /dev/sdX:
  setting = 128

Verify rather than trust a copied result:

$ sudo hdparm -B /dev/sdX

The setting normally lasts only until the device is reset or powered off. To undo the test, set the recorded previous value back, for example sudo hdparm -B 254 /dev/sdX. Use the value you actually recorded, not an example plucked from a guide.

5. Persist a deliberate setting with hdparm.conf

Debian's /etc/hdparm.conf is read mainly by udev. An option outside a device stanza applies to every drive; a stanza runs hdparm for that one device. The safest useful form names a single device and keeps the setting local to it.

/dev/sdX {
    apm = 128
}

Stick to the syntax this configuration file supports and keep comments on their own lines: inline comments are not supported, only whitespace or a line starting with # is treated as a comment. A duplicate option is replaced by whichever instance comes later, which makes leftover stanzas particularly confusing to debug.

Edit the file as root, then check the exact stanza before applying it:

$ sudoedit /etc/hdparm.conf
$ sudo sed -n '/^\/dev\/sdX {/,/^}/p' /etc/hdparm.conf

To re-apply one device's entry without a reboot, Debian documents this udev helper:

$ sudo env DEVNAME=/dev/sdX /lib/udev/hdparm

Verify the effective value with sudo hdparm -B /dev/sdX. If the setting causes boot trouble, the manpage documents the kernel parameter nohdparm to stop the init script running at all. Remove or fix the stanza once the machine is reachable again; do not keep retrying a setting that makes a disk unreliable.

6. Leave the dangerous options alone

This guide deliberately skips anything that can corrupt or destroy data. The manpage marks sector writes, sector-range trimming, sector-size changes, DCO restoration, firmware download, security erase, and several low-level transfer or interrupt settings as dangerous. Do not experiment with --write-sector, --trim-sector-ranges, --set-sector-size or --security-erase on a production disk; a backup does not make a mistaken device path safe.

Do not reach for -d1, -X, -p, -u1 or -m just because a benchmark disappoints you either. Modern SATA drivers normally negotiate suitable modes on their own, and the documented failure modes here include filesystem corruption. Chase cabling, kernel logs and workload before touching low-level transfer behaviour.

Done means