From ArchWiki
Jump to: navigation, search

Related articles

hdparm is a command line utility to set and view hardware parameters of hard disk drives. It can also be used as a simple benchmarking tool.

Warning: Be careful, changing default parameters can damage the drive or freeze the system.


Install the hdparm package. For use with SCSI devices, install the sdparm package.


Disk info

To get information about hard disks, run the following:

# hdparm -I /dev/sda


See Benchmarking/Data storage devices.

Power management configuration

Modern hard drives support numerous power management features, the most common ones are summarized in the following table. See hdparm(8) for the complete list.

Warning: Overly aggressive power management can reduce the lifespan of hard drives due to frequent parking and spindowns.
Parameter Description
-B Set the Advanced Power Management feature. Possible values are between 1 and 255, low values mean more aggressive power management and higher values mean better performance. Values from 1 to 127 permit spin-down, whereas values from 128 to 254 do not. A value of 255 completely disables the feature.
-S Set the standby (spindown) timeout for the drive. The timeout specifies how long to wait in idle (with no disk activity) before turning off the motor to save power. The value of 0 disables spindown, the values from 1 to 240 specify multiples of 5 seconds and values from 241 to 251 specify multiples of 30 minutes.
-M Set the Automatic Acoustic Management feature. Most modern hard disk drives have the ability to speed down the head movements to reduce their noise output. The possible value depends on the disk, some disks may not support this feature.

To query current value, pass the parameter without a value. For example:

# hdparm -B /dev/sda

To apply different value, for example set APM to 127:

# hdparm -B 127 /dev/sda

Tips and tricks

Querying the status of the disk without waking it up

Invoking hdparm with the query option is known to wake-up some drives. Instead, consider smartctl provided by smartmontools to query the device which will not wake up a sleeping disk.


# smartctl -i -n standby /dev/sda
smartctl 6.5 2016-05-07 r4318 [x86_64-linux-4.10.13-1-ARCH] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

Device is in STANDBY mode, exit(2)

Working with unsupported hardware

Some drives, particularly external ones, do not support spin down via hdparm. A diagnostic error message similar to the following is a good clue this is the case:

# hdparm -S 240 /dev/sda
setting standby to 240 (20 minutes)
HDIO_DRIVE_CMD(setidle) failed: Invalid argument

Such drives can be spun down using hd-idle which ships with a systemd service. One need only edit /etc/conf.d/hd-idle and edit the "HD_IDLE_OPTS" line followed by starting and enabling hd-idle.service:

Example using a 30 min idle time for sda:

HD_IDLE_OPTS="-i 0 -a sda -i 1800"

Persistent configuration using udev rule

To make the setting persistent, adapt the following udev rule:

ACTION=="add", SUBSYSTEM=="block", KERNEL=="sda", RUN+="/usr/bin/hdparm -B 254 -S 0 /dev/sda"

Systems with multiple hard drives, can make the rule more flexible. For example, to apply power-saving settings for all external drives (assuming there is only one internal drive, /dev/sda):

ACTION=="add|change", KERNEL=="sd[b-z]", ATTR{queue/rotational}=="1", RUN+="/usr/bin/hdparm -B 127 -S 12 /dev/%k"

Putting a drive to sleep directly after boot

A device which is rarely needed can be put to sleep directly at the end of the boot process. This does not work with the above udev rule because it happens too early. In order to issue the command when the boot is completed, just create a systemd service.

Description=hdparm sleep

ExecStart=/usr/bin/hdparm -q -S 120 -y /dev/sdb


Then enable it.

Power management for WD Green HDDs

The the Western Digital Green drives have a special "idle3" timeout, which controls how often the drive parks its heads and enters a low power consumption state. The factory default is 8 seconds, which is a very poor choice for use with Linux. Leaving it at the default will result in hundreds of thousands of head load/unload cycles in a very short period of time, which could result in premature failure, not to mention the performance impact of the drive often having to wake-up before doing routine I/O.

WD supplies an official WDIDLE3.EXE DOS utility for tweaking this setting, which should be used if at all possible. hdparm features a reverse-engineered implementation behind the -J flag, which is not as complete as the original official program, even though it seems to work on at a least a few drives. Another unofficial utility is provided by the idle3-tools package. A full power cycle is required for any change in setting to take effect, regardless of which program is used to tweak things.


APM level reset after suspend

The APM level may get reset after a suspend requiring it to be re-executed after each resume. This can be automated with the following systemd unit (adapted from a forum thread):

Description=Local system resume actions
After=suspend.target hybrid-sleep.target hibernate.target

ExecStart=/usr/bin/hdparm -B 254 /dev/sda

Note: The sleep.target is pulled by all suspend, hybrid-sleep and hibernate targets, but it finishes starting up before the system is suspended, so the three targets have to be specified explicitly. See [1].

Alternatively, create a hook in /usr/lib/systemd/system-sleep.