hdparm - ArchWiki

# hdparm

Related articles

- Securely_wipe_disk#hdparm

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.

## Installation

hdparm can be installed from the official repositories. For use with SCSI devices, install sdparm.

## Usage

### Disk info

To get information about your hard disk, run the following:

    # hdparm -I /dev/sda

### Benchmarking

#### Reading speed

To measure how many MB/s your hard disk (SATA/IDE) can read, run the following:

    # hdparm -t --direct /dev/sda

#### Writing speed

To measure how many MB/s your hard disk (SATA/IDE) can write, run the following:

    $ sync;time bash -c "(dd if=/dev/zero of=bf bs=8k count=500000; sync)"

Do not forget to `Ctrl+c` and `rm bf` after that.

Note: `bf` is just the name of the output file that `dd` writes to.
Tip: See dd-benchmark for an explanation on the requirement to `sync` and further related `dd` options.

### 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: Too aggressive power management can reduce the lifespan of your hard drive 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

#### Persistent configuration using udev rule

To make the setting persistent, adapt the following udev rule for your values:

    /etc/udev/rules.d/50-hdparm.rules

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

If you have more than one hard drive you could 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`):

    /etc/udev/rules.d/50-hdparm.rules

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

## Tips and tricks

### KDE => 4.4.4 and hdparm

To stop KDE version 4.4.4 or greater from messing around with your (manually) configured hdparm values, enter the following and you should be done:

    # touch /etc/pm/power.d/harddrive

## Troubleshooting

### APM level reset after suspend

The APM level may get reset after a suspend, so you will probably also have to re-execute the command after each resume. This can be automated with the following systemd unit: (adapter from a forum thread)

    [Unit]
    Description=Local system resume actions
    After=sleep.target

    [Service]
    Type=simple
    ExecStart=/usr/bin/hdparm -B 254 /dev/sda

    [Install]
    WantedBy=sleep.target

Or you could create `/usr/lib/systemd/system-sleep/hdparm_set`: found here

    #!/bin/sh
    hdparm -B254 /dev/sda

And make it executable:

    chmod +x /usr/lib/systemd/system-sleep/hdparm_set

Categories:

- File systems
- Storage