Comment 612 for bug 59695

Revision history for this message
Bart Samwel (bart-samwel) wrote : Re: [Bug 59695] Re: High frequency of load/unload cycles on some hard disks may shorten lifetime

bojo42 wrote:
> @angel chen: good question. i'm somewhat confused by that, but when
> laptop mode is disabled in general in /etc/default/acpi-support then
> logically it shouldn't be enabled by default on battery either. but you
> could you tell me how you started laptop mode when "cat
> /proc/sys/vm/laptop_mode" still gives you a zero.
>
> @all: who knows for sure if laptop mode is enabled on battery in
> intrepid?
>
> who knows how to reliable check if laptop mode is enabled, for fixing
> the included scripts in intrepid?

Checking for /proc/sys/vm/laptop_mode is not the way to go. This is to
check if the _kernel feature_ called "laptop mode" is enabled. What you
need to check for is whether the relevant functionality of the _package_
laptop-mode-tools is enabled, a very different thing (yes, the name
"laptop-mode-tools" is a confusing name -- blame history!). Because if
it is, then laptop-mode-tools will handle this stuff regardless of
battery, non-battery, and the state of the kernel feature that is
represented by /proc/sys/vm/laptop_mode. (The /proc/sys/vm/laptop_mode
feature is also controlled by laptop-mode-tools, but this is independent
of the hdparm features and should absolutely be ignored!) How to check
if (a) the _package_ laptop-mode-tools is enabled AND (b) its feature
controlling hdparm is enabled? Well:

(a): by checking /etc/default/acpi-support for ENABLE_LAPTOP_MODE=true
(b): by executing /etc/laptop-mode/laptop-mode.conf and testing whether
CONTROL_HD_POWERMGMT=1

The current 90-hdparm.sh already does (b). One should simply add (a).
One could replace this:

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

by:

if [ -e /usr/sbin/laptop_mode ] ; then
  LMT_CONTROL_HD_POWERMGMT=$(. /etc/laptop-mode/laptop-mode.conf && echo
"$CONTROL_HD_POWERMGMT")
  ACPI_SUPPORT_ENABLE_LAPTOP_MODE=$(. /etc/default/acpi-support && echo
"$ENABLE_LAPTOP_MODE")
  if [ "$LMT_CONTROL_HD_POWERMGMT" != 0 &&
"$ACPI_SUPPORT_ENABLE_LAPTOP_MODE" = "true" ] ; then
    # Laptop mode controls hdparm -B settings, we don't.
    DO_HDPARM=n
  fi
fi

and that should do the trick.

Cheers,
Bart