10

I bought a new HD(WD5000BPVT) which unfortunately tries to sleep every 5-8 seconds. Not only is the clicking noise quite audible, the 1-second spinup time adds very noticeable latency in day-to-day use.

I've found hdparm -B 254 /dev/sda will disable the very short sleep but I don't know how to enforce this setting every time the drive is powered on. The dconf-editor and 'Power Management Preferences' apps both do nothing with regard to HD settings. I don't have any /etc/hdparm or /etc/acpi paths. MATE is the window manager.

On Fedora 19, how can I force this command to run whenever the drive is activated?

12

I had the same problem none of the solutions here suited my needs. Using cron is really a workaround, not a solution, udev rules are run when power is connected/disconnected but not after suspending/resuming and pm-utils are no longer used by default in Fedora 19 when you for example close lid of your laptop.

Since systemd is now responsible for suspending/hibernating, I think that the only proper way to handle this situation is to create a systemd unit that will run both after boot and after resuming from suspend.

Notes:

  • By using /dev/disk/by-id/... instead of /dev/sda, you are always be sure to get the right disk (sda,b,c depends on the order they are detected by the kernel)
  • You can have multiple ExecStart lines so you can configure multiple disks

Here's the unit I wrote:

[Unit]
Description=Silence HD
After=suspend.target

[Service]
Type=oneshot
# Disable automatic head parking for the main disk
ExecStart=/sbin/hdparm -B 254 /dev/disk/by-id/ata-ST3250824AS_4N127FD1
# Enable automatic spin down after 30 seconds for the second, infrequently used disk
ExecStart=/sbin/hdparm -S 6 /dev/disk/by-id/ata-ST31000528AS_BVP5H5X1

[Install]
WantedBy=suspend.target basic.target

Save this file as /etc/systemd/system/hdsilence.service and then enable it using:

systemctl enable hdsilence.service
systemctl daemon-reload
  • Works great here on Fedora 20, too. Thank you! – Jakob Oct 11 '14 at 10:28
  • So this makes changes to /etc/hdparm.conf obsolete? – domih Nov 18 '18 at 21:23
  • @domih: As far as I can tell the hdparm.conf is a Debian thing and it is not supported on Fedora. – Krzysztof Adamski Nov 22 '18 at 11:26
6

You can have the system run the command during boot by creating your own systemd service or adding the command to /etc/rc.d/rc.local.

If you want the command to run every time you wake the system after sleep/hibernate, you can add a script that starts with 2 digits to /etc/pm/sleep.d/, look at the other scripts in /usr/lib64/pm-utils/sleep.d (assuming x86_64) for more details. Basically, it takes a parameter depending on which state it is entering. You might also need to add some login to power.d/ in the same parent directory if you want to operate differently on battery power compared to when plugged in.

  • 1
    creating your own systemd service can you be more specific? I don't have a /etc/rc.d/rc.local file. – Pete Jun 23 '13 at 18:18
  • 1
    The systemd documentation explains the syntax of a systemd service unit. The /etc/rc.d/rc.local file is just a shell script, create it and make sure its executable. – jsbillings Jun 25 '13 at 0:48
3

For different settings when running on AC / battery, I'd do it via a simple udev rule, e.g.
/etc/udev/rules.d/98-apmsettings.rules:

SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/hdparm -B 128 /dev/sda"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/hdparm -B 254 /dev/sda"

This would set apm to 254 when the laptop is plugged in and respectively 128 when unplugged. Also, it should always work, even after resuming from suspend.

  • 1
    For those who like copying verbatim, newer releases have hdparm in /usr/sbin, so adjust the paths. – Roman Aug 5 '13 at 18:49
2

I have the same disk (and the same problem). My stupid but working solution: I have put that in /etc/crontab:

-*/5  * * * *   root  hdparm -B 254 /dev/sda
  • Doesn't this simply access the drive every 12 seconds? I considered something along that line but I kinda would like some level of sleep when undocked. – Pete Jun 23 '13 at 16:59
  • Every five minutes. You may write a wrapper script which checks the power state of the system. – Hauke Laging Jun 23 '13 at 17:04
1

The udev rules work well on plug events, but to get the correct behaviour after resume from suspend I need somthing like this in /etc/pm/sleep.d:

#!/bin/sh

case "${1}" in
    resume|thaw)
    if grep -q 1 /sys/class/power_supply/ADP1/online; then
      /usr/sbin/hdparm -B 254 /dev/sda
    else
      /usr/sbin/hdparm -B 128 /dev/sda
    fi
;;
esac

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.