Difference between revisions of "Hdparm"

From ArchWiki
Jump to: navigation, search
(Parking your hard drive: resume resets APM level)
(APM level reset after suspend: Little changes in a note in relation to the After Unit Section Option semantics.)
 
(48 intermediate revisions by 19 users not shown)
Line 1: Line 1:
 +
{{Lowercase title}}
 
[[Category:File systems]]
 
[[Category:File systems]]
 
[[Category:Storage]]
 
[[Category:Storage]]
 
[[fr:hdparm]]
 
[[fr:hdparm]]
{{lowercase title}}
+
[[ja:hdparm]]
hdparm is a performance and [[benchmarking]] tool for your hard disk (SATA/IDE).
+
{{Related articles start}}
 +
{{Related|Securely wipe disk#hdparm}}
 +
{{Related articles end}}
 +
hdparm is a command line utility to set and view hardware parameters of [[wikipedia:Hard disk drive|hard disk drives]]. It can also be used as a simple [[benchmarking]] tool.
  
{{Warning|Be careful, it is easy to destroy your hard drive with hdparm!}}
+
{{Warning|Be careful, changing default parameters can damage the drive or freeze the system.}}
  
 
== Installation ==
 
== Installation ==
  
{{Pkg|hdparm}} can be installed from the [[Official Repositories|official repositories]]. For use with SCSI devices, install {{Pkg|sdparm}}.
+
[[Install]] the {{Pkg|hdparm}} package. For use with SCSI devices, install the {{Pkg|sdparm}} package.
  
 
== Usage ==
 
== Usage ==
  
 
=== Disk info ===
 
=== Disk info ===
 +
 
To get information about your hard disk, run the following:
 
To get information about your hard disk, run the following:
 +
 
  # hdparm -I /dev/sda
 
  # hdparm -I /dev/sda
  
=== Reading speed MB/s ===
+
=== Benchmarking ===
 +
 
 +
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 {{ic|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.}}
 +
 
 +
{| class="wikitable"
 +
! Parameter !! Description
 +
|-
 +
| {{ic|-B}} || Set the [[wikipedia:Advanced Power Management|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.
 +
|-
 +
| {{ic|-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.
 +
|-
 +
| {{ic|-M}} || Set the [[wikipedia:Automatic Acoustic Management|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 ==
 +
 
 +
=== Persistent configuration using udev rule ===
 +
 
 +
To make the setting persistent, adapt the following [[udev]] rule for your values:
 +
 
 +
{{hc|/etc/udev/rules.d/50-hdparm.rules|<nowiki>
 +
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sda", RUN+="/usr/bin/hdparm -B 254 -S 0 /dev/sda"
 +
</nowiki>}}
 +
 
 +
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, {{ic|/dev/sda}}):
 +
 
 +
{{hc|/etc/udev/rules.d/50-hdparm.rules|<nowiki>
 +
ACTION=="add|change", KERNEL=="sd[b-z]", ATTR{queue/rotational}=="1", RUN+="/usr/bin/hdparm -B 127 -S 12 /dev/%k"
 +
</nowiki>}}
 +
 
 +
=== 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.
 +
 
 +
{{hc|/etc/systemd/system/hdparm.service|<nowiki>
 +
[Unit]
 +
Description=hdparm sleep
 +
 
 +
[Service]
 +
Type=oneshot
 +
ExecStart=/usr/bin/hdparm -q -S 120 -y /dev/sdb
  
To measure how many MB/s your hard disk (SATA/IDE) can read, run the following:
+
[Install]
# hdparm -t --direct /dev/sda
+
WantedBy=multi-user.target
 +
</nowiki>}}
  
=== Writing speed MB/s ===
+
Then [[enable]] it.
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 {{Keypress|Ctrl+c}} and {{ic|rm bf}} after that.
+
== Troubleshooting ==
  
{{Note|{{ic|bf}} is just the name of the output file that {{ic|dd}} writes to.}}
+
=== APM level reset after suspend ===
  
=== Parking your hard drive ===
+
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 (adapted from a [https://bbs.archlinux.org/viewtopic.php?id=151640 forum thread]):
  
If your hard drive is clicking many times, the kernel is parking the hard drive's actuator arm (what moves the read/write head). This happens often on laptops (2.5" IDE hard drives). If it happens too often, it could damage your hard drive.
+
{{hc|/etc/systemd/system/apm.service|2=
 +
[Unit]
 +
Description=Local system resume actions
 +
After=suspend.target hybrid-sleep.target hibernate.target
  
This will just park the reading head when you shut down the computer:
+
[Service]
# hdparm -B254 /dev/sd
+
Type=simple
 +
ExecStart=/usr/bin/hdparm -B 254 /dev/sda
  
Default value is {{ic|-B128}}. An average value could be {{ic|-B199}} if it is parking too often.
+
[Install]
 +
WantedBy=sleep.target
 +
}}
  
To make this persistent, add a [[udev]] rule by creating e.g. <code>/etc/udev/rules.d/11-sda-apm-fix.rules</code>:
+
{{Note|1=The {{ic|sleep.target}} is pulled by all {{ic|suspend}}, {{ic|hybrid-sleep}} and {{ic|hibernate}} targets, but it finishes starting up ''before'' the system is suspended, so the three targets have to be specified explicitly. See [https://wiki.archlinux.org/index.php?title=Talk:Hdparm&oldid=440457#Troubleshooting_APM_settings_after_suspend.2C_hibernate_or_hybrid-sleep].}}
  
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sda", RUN+="/sbin/hdparm -B 254 /dev/sda"
+
Alternatively you can create a [[Power_management#Hooks_in_.2Fusr.2Flib.2Fsystemd.2Fsystem-sleep|hook in /usr/lib/systemd/system-sleep]].
  
Note that the APM level may get reset after a suspend, so you will probably also have to re-execute the command after each resume. That could be automated via a [[systemd#Suspend.2Fresume_service_files|systemd resume@ service file]].
+
=== Drive is not supported ===
  
==Tips and tricks==
+
{{Move|Power_management#Hard_disk_drive|Not related to hdparm in any way.}}
=== 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:
+
In this case you could consider using a different approach and the tool [http://hd-idle.sourceforge.net/ hd-idle].
# touch /etc/pm/power.d/harddrive
+

Latest revision as of 06:43, 11 July 2016

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.

Installation

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

Usage

Disk info

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

# hdparm -I /dev/sda

Benchmarking

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: 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

Tips and tricks

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"

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.

/etc/systemd/system/hdparm.service
[Unit]
Description=hdparm sleep

[Service]
Type=oneshot
ExecStart=/usr/bin/hdparm -q -S 120 -y /dev/sdb

[Install]
WantedBy=multi-user.target

Then enable it.

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 (adapted from a forum thread):

/etc/systemd/system/apm.service
[Unit]
Description=Local system resume actions
After=suspend.target hybrid-sleep.target hibernate.target

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

[Install]
WantedBy=sleep.target
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 you can create a hook in /usr/lib/systemd/system-sleep.

Drive is not supported

Tango-go-next.pngThis article or section is a candidate for moving to Power_management#Hard_disk_drive.Tango-go-next.png

Notes: Not related to hdparm in any way. (Discuss in Talk:Hdparm#)

In this case you could consider using a different approach and the tool hd-idle.