Turn off APM at boot

This is a quick tip to turn off APM (Advanced Power Management) on a specific drive, which is sda in this case.
I did this on the laptop I refurbished as a server because the drive continuously spinned down and spinned up every few seconds. The repeated spin-down / spin-up could wear the mechanical parts, and thus, shorten the drive’s lifespan.

The APM can be set with hdparm using the -B flag. The manual explains the possible values, and a value of 255 means the APM is disabled.
The command to turn off APM for sda is hdparm -B 255 /dev/sda

However, the configuration is lost at reboot, and for an unknown reason, the /etc/hdparm.conf file is ignored.
My workaround is to create a service that runs one time at boot, once the system is “ready”, so after the multi-user.target.

Just put this content in the /etc/systemd/system/hdparm.service file (non-existant by default):

1
2
3
4
5
6
7
8
9
[Unit]
Description=hdparm sda

[Service]
Type=oneshot
ExecStart=/usr/sbin/hdparm -B 255 /dev/sda

[Install]
WantedBy=multi-user.target sleep.target

Finally, activate the service with sudo systemctl enable hdparm