Ubuntu hdparm APM and laptop mode tools

Ubuntu 8.10 is supposed to fix the apm=128 issue which causes high loading/unloading cycles for some hard drives; however, it is still BROKEN by default, here’s why:
the file 90-hdparm.sh located in various folders in /etc/acpi such as /etc/acpi/ac.d/, /etc/acpi/battery.d/, /etc/acpi/resume.d/, and /etc/acpi/start.d/ is supposed to fix the hdparm problem; however, notice the following lines:
DO_HDPARM=y
if [ -e /usr/sbin/laptop_mode ] ; then
LMT_CONTROL_HD_POWERMGMT=$(. /etc/laptop-mode/laptop-mode.conf && echo "$CONTROL_HD_POWERMGMT")
if [ "$LMT_CONTROL_HD_POWERMGMT" != 0 ] ; then
# Laptop mode controls hdparm -B settings, we don't.
DO_HDPARM=n
fi
fi

This checks if the file /usr/sbin/laptop_mode exists and if it exists, then it checks if CONTROL_HD_POWERMGMT in laptop-mode.conf is set to a non-zero number in order to determine if laptop mode is enabled. However, Ubuntu installs laptop-mode-tools by default, so /usr/sbin/laptop_mode always exist and that by itself does not tell whether laptop mode is on. Rather, ubuntu turns laptop mode off by default by setting the variable ENABLE_LAPTOP_MODE=false in /etc/default/acpi-support, but this variable is not used anywhere except in the init script /etc/init.d/laptop-mode from line 30 to 37:
# FIXME: this shouldn't be configured there
if [ -f /etc/default/acpi-support ]; then
. /etc/default/acpi-support;
fi

if [ x$ENABLE_LAPTOP_MODE = xfalse ]; then
exit 0;
fi
which stops the script from executing if the variable is set to false. One funny thing about this is that it says FIXME in the comment but it actually never get fixed even after Ubuntu 8.10 is released. With Ubuntu’s default settings laptop mode tool is supposed to be disabled by ENABLE_LAPTOP_MODE=false, but the script 90-hdparm.sh always thought that it is enabled as long as laptop mode is installed because /usr/sbin/laptop_mode is always there. It then checks the variable CONTROL_HD_POWERMGMT in /etc/laptop-mode/laptop-mode.conf, which is 1 by default, and it will set DO_HDPARM=n, thinking that laptop-mode is on and letting it to handle hard drive’s APM setting instead while actually laptop-mode is OFF and not taking care of the APM problem. This makes nobody changing the hard drive’s default APM setting from 128 to something else, leaving the clicking problem unsolved.
I did some workaround to 90-hdparm.sh by changing the line "if [ -e /usr/sbin/laptop_mode ] ; then" to "if [ -e /var/run/laptop-mode-tools/enabled ] ; then" in order to check if laptop mode tool is enabled, because whenever laptop mode tool is enabled, it creates the file /var/run/laptop-mode-tools/enabled, so I think this is the right way to check if it is actually enabled rather than just installed. I also think that the variable ENABLE_LAPTOP_MODE in /etc/default/acpi-support should be removed instead, just as Debian did in acpi-support version 1.109-5. That variable is just there to confuse people more and mess up the configurations. Even the comment in /etc/init.d/laptop-mode says “FIXME: this shouldn’t be configured there” already, why don’t they just fix it right now and make all these things less messy. I have tested Debian six months before and they really did a good job in fixing those hard drive clicking issues by making the 90-hdparm.sh file and removing the ENABLE_LAPTOP_MODE variable.

4 thoughts on “Ubuntu hdparm APM and laptop mode tools”

  1. /var/run/laptop-mode-tools/enabled

    or

    /var/run/laptop-mode-enabled

    ?
    From http://samwel.tk/laptop_mode/faq
    “Is Laptop Mode Enabled?
    How do I check if laptop mode is enabled?

    Execute cat /proc/sys/vm/laptop_mode. If it contains a nonzero value, then laptop mode is enabled, if it says 0, then it isn’t.
    What’s /var/run/laptop-mode-enabled got to do with things?

    Well, this file is created and destroyed by the laptop-mode init script to enable/disable laptop mode activity. If this file is not present, then laptop mode tools will not do a thing except disable itself, even when you unplug your computer from the mains.
    …”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: