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