02 January 2011

Fixing overzealous hard drive head parking

Debian Squeeze on my Samsung R510 has been working very well, with one exception: pause... pause... click... pause... pause... pause... click... The hard drive seems to be overzealous about parking its heads. There are some (strawman alert?) who feel that heavy head parking actually reduces the life of a drive. Whether or not that's the case, I find the frequent clicking to be downright annoying on this otherwise intensely quiet computer.

As is the case with many things in Linux, a fix is at hand. Many thanks to SammyNetbook for pointing the way. The frequency of head parking can be changed by lowering the aggressiveness of APM power saving through the hdparm command. In the case of my lappy, running

# hdparm -B 254 /dev/sda

(as root) solved the headparking issue. (There maybe lower levels that work as well, but I'm happy enough with the result now that I haven't experimented.)

Running the command at startup
The effect of the above command ends at restart. To automatically run it when my lappy starts up, I used init.d. I first created a file mfk-hdsilence.sh in /etc/init.d:
#! /bin/sh
# /etc/init.d/mfk-hdsilence.sh
#

# Some things that run always
hdparm -B 254 /dev/sda

exit 0

Then to activate this:
# update-rc.d mfk-hdsilence.sh defaults

I got a warning when I did this, but it seemed safe to ignore. Result? A non-clicky, super silent lappy. Life is good.

Update: it seems suspending the lappy resets the drive's APM, so I'll need to figure out a way to rerun hdparm when waking up. I am currently experimenting with placing a file 30_mfk-hdsilence.sh in /etc/pm/sleep.d:

#! /bin/sh
# 30_mfk-hdsilence.sh
#

# silence aggressive head parking
case ${1} in
 resume|thaw)
  hdparm -B 254 /dev/sda
  ;;
esac

exit 0

It seems to be working, but I'll need to live with it for a while to make sure. Suspending under Linux is always stressful for me.