Difference between revisions of "Debian on laptop"

From YobiWiki
Jump to navigation Jump to search
m
 
m
Line 105: Line 105:
 
If you have a Radeon video card, it does not turn off when you close your LID and if you have e.g. a Dell D610 with an Intel 915GM card, id does turn off but doesn't turn on anymore when opened, even worse!! <br />Here is a script backlight_install.sh to solve both problems:
 
If you have a Radeon video card, it does not turn off when you close your LID and if you have e.g. a Dell D610 with an Intel 915GM card, id does turn off but doesn't turn on anymore when opened, even worse!! <br />Here is a script backlight_install.sh to solve both problems:
   
  +
<source lang=bash>
<nowiki>
 
#!/bin/bash
+
#!/bin/bash
  +
 
# Version: 0.04
+
# Version: 0.04
# Copyright:
+
# Copyright:
# 2006 Philippe Teuwen &lt;phil-debian _at_ teuwen.org&gt;
+
# 2006 Philippe Teuwen &lt;phil-debian _at_ teuwen.org&gt;
# License:
+
# License:
# GPL
+
# GPL
# Usage:
+
# Usage:
# Install radeontool if you have an ATI Radeon video card
+
# Install radeontool if you have an ATI Radeon video card
# or install vbetool if you have an Intel 915GM video card
+
# or install vbetool if you have an Intel 915GM video card
# To install this script, run it without params
+
# To install this script, run it without params
  +
 
# For printing extra messages -&gt; /var/log/acpid
+
# For printing extra messages -&gt; /var/log/acpid
DEBUG=false
+
DEBUG=false
  +
 
# Supported card_handlers: radeon/vbepost/vbestate
+
# Supported card_handlers: radeon/vbepost/vbestate
# You are not supposed to change this yourself but rather run this script
+
# You are not supposed to change this yourself but rather run this script
# without parameters for a proper installation!!
+
# without parameters for a proper installation!!
card_handler=undef
+
card_handler=undef
  +
 
###########################################################################
+
###########################################################################
# read permanent states
+
# read permanent states
lid_state="unknown"
+
lid_state="unknown"
  +
 
function read_lid_state() {
+
function read_lid_state() {
case $(cat /proc/acpi/button/lid/LID/state) in
+
case $(cat /proc/acpi/button/lid/LID/state) in
*open)
+
*open)
lid_state=open
+
lid_state=open
;;
+
;;
*closed)
+
*closed)
lid_state=closed
+
lid_state=closed
;;
+
;;
esac
+
esac
}
+
}
  +
 
function check_installed() {
+
function check_installed() {
tool=$1
+
tool=$1
if which $tool &gt;/dev/null; then
+
if which $tool &gt;/dev/null; then
echo "Good! $tool found."
+
echo "Good! $tool found."
else
+
else
echo "Please install $tool and run this script again"
+
echo "Please install $tool and run this script again"
exit 1
+
exit 1
fi
+
fi
}
+
}
  +
 
function install() {
+
function install() {
EVENT_NAME=backlight_handler
+
EVENT_NAME=backlight_handler
echo "Installation of this script..."
+
echo "Installation of this script..."
echo -n "Which card handler do you want to use? [radeon/vbepost/vbestate/none]: "
+
echo -n "Which card handler do you want to use? [radeon/vbepost/vbestate/none]: "
#TODO: detect radeon automatically?
+
#TODO: detect radeon automatically?
read mycard
+
read mycard
case "$mycard" in
+
case "$mycard" in
radeon)
+
radeon)
check_installed radeontool
+
check_installed radeontool
;;
+
;;
vbepost)
+
vbepost)
check_installed vbetool
+
check_installed vbetool
;;
+
;;
vbestate)
+
vbestate)
check_installed vbetool
+
check_installed vbetool
echo "Saving current video hardware data..."
+
echo "Saving current video hardware data..."
mkdir -p /var/lib/vbetool
+
mkdir -p /var/lib/vbetool
save_vt_nr=$(fgconsole)
+
save_vt_nr=$(fgconsole)
chvt 1
+
chvt 1
vbetool vbestate save &gt; /var/lib/vbetool/vbestate
+
vbetool vbestate save &gt; /var/lib/vbetool/vbestate
chvt $save_vt_nr
+
chvt $save_vt_nr
echo "Done."
+
echo "Done."
;;
+
;;
none)
+
none)
echo "Then you probably don't need this script! Exiting."
+
echo "Then you probably don't need this script! Exiting."
exit 0
+
exit 0
;;
+
;;
*)
+
*)
echo "Error: unsupported card handler!: $mycard. Exiting."
+
echo "Error: unsupported card handler!: $mycard. Exiting."
exit 1
+
exit 1
;;
+
;;
esac
+
esac
echo "Installation of the script"
+
echo "Installation of the script"
ACTION_DEST=/etc/acpi/actions
+
ACTION_DEST=/etc/acpi/actions
EVENT_DEST=/etc/acpi/events
+
EVENT_DEST=/etc/acpi/events
me="$(basename $0)"
+
me="$(basename $0)"
cd "$(dirname $0)"
+
cd "$(dirname $0)"
if [ ! -d $EVENT_DEST ]; then
+
if [ ! -d $EVENT_DEST ]; then
echo "Error! Did you install acpid?"
+
echo "Error! Did you install acpid?"
exit 1
+
exit 1
fi
+
fi
cat &gt; $EVENT_DEST/$EVENT_NAME &lt;&lt; EOF
+
cat &gt; $EVENT_DEST/$EVENT_NAME &lt;&lt; EOF
event=button[ /]lid
+
event=button[ /]lid
action=$ACTION_DEST/$EVENT_NAME.sh %e
+
action=$ACTION_DEST/$EVENT_NAME.sh %e
EOF
+
EOF
/etc/init.d/acpid reload
+
/etc/init.d/acpid reload
if [ "$(pwd)/$me" != "$ACTION_DEST/$EVENT_NAME.sh" ]; then
+
if [ "$(pwd)/$me" != "$ACTION_DEST/$EVENT_NAME.sh" ]; then
mkdir -p "$ACTION_DEST"
+
mkdir -p "$ACTION_DEST"
sed "s/^\(card_handler=\).*/\1$mycard/" $me &gt; "$ACTION_DEST/$EVENT_NAME.sh"
+
sed "s/^\(card_handler=\).*/\1$mycard/" $me &gt; "$ACTION_DEST/$EVENT_NAME.sh"
chmod 755 "$ACTION_DEST/$EVENT_NAME.sh"
+
chmod 755 "$ACTION_DEST/$EVENT_NAME.sh"
else
+
else
# In-place re-configuration
+
# In-place re-configuration
sed -i "s/^\(card_handler=\).*/\1$mycard/" $me;
+
sed -i "s/^\(card_handler=\).*/\1$mycard/" $me;
fi
+
fi
echo "Installation finished!"
+
echo "Installation finished!"
exit 0
+
exit 0
}
+
}
  +
 
###########################################################################
+
###########################################################################
# Main()
+
# Main()
  +
 
[ "$1" = "" ] &amp;&amp; install
+
[ "$1" = "" ] &amp;&amp; install
read_lid_state
+
read_lid_state
$DEBUG &amp;&amp; echo "LID: $lid_state"
+
$DEBUG &amp;&amp; echo "LID: $lid_state"
case "$lid_state" in
+
case "$lid_state" in
open)
+
open)
$DEBUG &amp;&amp; echo "Setting light on";
+
$DEBUG &amp;&amp; echo "Setting light on";
case "$card_handler" in
+
case "$card_handler" in
radeon)
+
radeon)
radeontool light on;
+
radeontool light on;
;;
+
;;
vbepost)
+
vbepost)
save_vt_nr=$(fgconsole)
+
save_vt_nr=$(fgconsole)
chvt 15
+
chvt 15
vbetool post
+
vbetool post
sleep 1
+
sleep 1
chvt $save_vt_nr
+
chvt $save_vt_nr
;;
+
;;
vbestate)
+
vbestate)
save_vt_nr=$(fgconsole)
+
save_vt_nr=$(fgconsole)
chvt 15
+
chvt 15
if [ -e /var/lib/vbetool/vbestate ]; then
+
if [ -e /var/lib/vbetool/vbestate ]; then
vbetool vbestate restore &lt; /var/lib/vbetool/vbestate
+
vbetool vbestate restore &lt; /var/lib/vbetool/vbestate
else
+
else
$DEBUG &amp;&amp; echo "Error: unconfigured vbestate, fallback to vbepost";
+
$DEBUG &amp;&amp; echo "Error: unconfigured vbestate, fallback to vbepost";
vbetool post
+
vbetool post
fi
+
fi
sleep 1
+
sleep 1
chvt $save_vt_nr
+
chvt $save_vt_nr
;;
+
;;
*)
+
*)
$DEBUG &amp;&amp; echo "Error: unknown card_handler: $card_handler";
+
$DEBUG &amp;&amp; echo "Error: unknown card_handler: $card_handler";
;;
+
;;
esac
+
esac
;;
+
;;
closed)
+
closed)
$DEBUG &amp;&amp; echo "Setting light off";
+
$DEBUG &amp;&amp; echo "Setting light off";
case "$card_handler" in
+
case "$card_handler" in
radeon)
+
radeon)
radeontool light off;
+
radeontool light off;
;;
+
;;
vbe*)
+
vbe*)
;;
+
;;
*)
+
*)
$DEBUG &amp;&amp; echo "Error: unknown card_handler: $card_handler";
+
$DEBUG &amp;&amp; echo "Error: unknown card_handler: $card_handler";
;;
+
;;
esac
+
esac
;;
+
;;
*)
+
*)
$DEBUG &amp;&amp; echo "Error: LID state not recognized: $lid_state"
+
$DEBUG &amp;&amp; echo "Error: LID state not recognized: $lid_state"
;;
+
;;
esac</nowiki>
+
esac
  +
</source>
   
 
If you know what you are doing, you can achieve much smaller script, cf LaptopDellD610 step-by-step
 
If you know what you are doing, you can achieve much smaller script, cf LaptopDellD610 step-by-step
 
----
 
   
 
=== Low battery warning ===
 
=== Low battery warning ===
Line 278: Line 277:
 
/etc/acpi/actions/warn_battery.sh (chmod +x):
 
/etc/acpi/actions/warn_battery.sh (chmod +x):
   
  +
<source lang=bash>
<nowiki>
 
#! /bin/bash
+
#! /bin/bash
  +
 
# Automatically warns when the battery almost runs out.
+
# Automatically warns when the battery almost runs out.
# Version: 0.03
+
# Version: 0.03
# Copyright:
+
# Copyright:
# 2006 Philippe Teuwen &lt;phil-debian _at_ teuwen.org&gt;
+
# 2006 Philippe Teuwen &lt;phil-debian _at_ teuwen.org&gt;
# License:
+
# License:
# GPL
+
# GPL
  +
 
BATT_INFO=/proc/acpi/battery/$2
+
BATT_INFO=/proc/acpi/battery/$2
  +
 
MINIMUM_BATTERY_MINUTES=7
+
MINIMUM_BATTERY_MINUTES=7
MINIMUM_BATTERY_CHARGE_MAH=500
+
MINIMUM_BATTERY_CHARGE_MAH=500
MINIMUM_BATTERY_CHARGE_MWH=500
+
MINIMUM_BATTERY_CHARGE_MWH=500
CRITICAL_BATTERY_MINUTES=1
+
CRITICAL_BATTERY_MINUTES=1
CRITICAL_BATTERY_CHARGE_MAH=100
+
CRITICAL_BATTERY_CHARGE_MAH=100
CRITICAL_BATTERY_CHARGE_MWH=100
+
CRITICAL_BATTERY_CHARGE_MWH=100
#WARNING_SOUND=/usr/share/sounds/pop.wav
+
#WARNING_SOUND=/usr/share/sounds/pop.wav
WARNING_SOUND=/usr/share/kismet/wav/new_network.wav
+
WARNING_SOUND=/usr/share/kismet/wav/new_network.wav
  +
 
if [ -f $BATT_INFO/state ] ; then
+
if [ -f $BATT_INFO/state ] ; then
[[ $(cat /proc/acpi/ac_adapter/AC/state) = *on-line* ]] &amp;&amp; exit
+
[[ $(cat /proc/acpi/ac_adapter/AC/state) = *on-line* ]] &amp;&amp; exit
if cat $BATT_INFO/state | grep -q discharging ; then
+
if cat $BATT_INFO/state | grep -q discharging ; then
REMAINING=`cat $BATT_INFO/state | grep "remaining capacity:.*m.h" | sed "s/.* \([0-9][0-9]* \).*/\1/" `
+
REMAINING=`cat $BATT_INFO/state | grep "remaining capacity:.*m.h" | sed "s/.* \([0-9][0-9]* \).*/\1/" `
REMAINING=${REMAINING:-0}
+
REMAINING=${REMAINING:-0}
FULL=`cat $BATT_INFO/info | grep "last full capacity:.*m.h" | sed "s/.* \([0-9][0-9]* \).*/\1/" `
+
FULL=`cat $BATT_INFO/info | grep "last full capacity:.*m.h" | sed "s/.* \([0-9][0-9]* \).*/\1/" `
FULL=${FULL:-0}
+
FULL=${FULL:-0}
IN_MAH=0
+
IN_MAH=0
IN_MWH=0
+
IN_MWH=0
( cat $BATT_INFO/state | grep mWh &gt;/dev/null ) &amp;&amp; IN_MWH=1 &amp;&amp; UNIT=mW
+
( cat $BATT_INFO/state | grep mWh &gt;/dev/null ) &amp;&amp; IN_MWH=1 &amp;&amp; UNIT=mW
( cat $BATT_INFO/state | grep mAh &gt;/dev/null ) &amp;&amp; IN_MAH=1 &amp;&amp; UNIT=mA
+
( cat $BATT_INFO/state | grep mAh &gt;/dev/null ) &amp;&amp; IN_MAH=1 &amp;&amp; UNIT=mA
DO=0
+
DO=0
DO_CRIT=0
+
DO_CRIT=0
PRESENT_RATE=`cat $BATT_INFO/state | grep "present rate:.*m" | sed "s/.* \([0-9][0-9]* \).*/\1/" `
+
PRESENT_RATE=`cat $BATT_INFO/state | grep "present rate:.*m" | sed "s/.* \([0-9][0-9]* \).*/\1/" `
PRESENT_RATE=${PRESENT_RATE:-0}
+
PRESENT_RATE=${PRESENT_RATE:-0}
[ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
+
[ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
REMAINING_MINUTES=$(($REMAINING * 60 / $PRESENT_RATE))
+
REMAINING_MINUTES=$(($REMAINING * 60 / $PRESENT_RATE))
[ "$REMAINING" -ne 0 -a "$FULL" -ne 0 ] &amp;&amp; \
+
[ "$REMAINING" -ne 0 -a "$FULL" -ne 0 ] &amp;&amp; \
REMAINING_PERCENT=$(($REMAINING * 100 / $FULL))
+
REMAINING_PERCENT=$(($REMAINING * 100 / $FULL))
[ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
+
[ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
(($REMAINING_MINUTES &lt; $MINIMUM_BATTERY_MINUTES)) &amp;&amp; DO=1
+
(($REMAINING_MINUTES &lt; $MINIMUM_BATTERY_MINUTES)) &amp;&amp; DO=1
[ "$IN_MAH" -ne 0 -a "$REMAINING" -lt "$MINIMUM_BATTERY_CHARGE_MAH" ] &amp;&amp; DO=1
+
[ "$IN_MAH" -ne 0 -a "$REMAINING" -lt "$MINIMUM_BATTERY_CHARGE_MAH" ] &amp;&amp; DO=1
[ "$IN_MWH" -ne 0 -a "$REMAINING" -lt "$MINIMUM_BATTERY_CHARGE_MWH" ] &amp;&amp; DO=1
+
[ "$IN_MWH" -ne 0 -a "$REMAINING" -lt "$MINIMUM_BATTERY_CHARGE_MWH" ] &amp;&amp; DO=1
[ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
+
[ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
(($REMAINING_MINUTES &lt; $CRITICAL_BATTERY_MINUTES)) &amp;&amp; DO_CRIT=1
+
(($REMAINING_MINUTES &lt; $CRITICAL_BATTERY_MINUTES)) &amp;&amp; DO_CRIT=1
[ "$IN_MAH" -ne 0 -a "$REMAINING" -lt "$CRITICAL_BATTERY_CHARGE_MAH" ] &amp;&amp; DO_CRIT=1
+
[ "$IN_MAH" -ne 0 -a "$REMAINING" -lt "$CRITICAL_BATTERY_CHARGE_MAH" ] &amp;&amp; DO_CRIT=1
[ "$IN_MWH" -ne 0 -a "$REMAINING" -lt "$CRITICAL_BATTERY_CHARGE_MWH" ] &amp;&amp; DO_CRIT=1
+
[ "$IN_MWH" -ne 0 -a "$REMAINING" -lt "$CRITICAL_BATTERY_CHARGE_MWH" ] &amp;&amp; DO_CRIT=1
if [ $DO -ne 0 ] ; then
+
if [ $DO -ne 0 ] ; then
text="WARNING!!!\n"
+
text="WARNING!!!\n"
text=$text"Remaining: $REMAINING${UNIT}h ($REMAINING_PERCENT%)\n"
+
text=$text"Remaining: $REMAINING${UNIT}h ($REMAINING_PERCENT%)\n"
[[ $PRESENT_RATE -ne 0 ]] &amp;&amp; text=$text"You have about $REMAINING_MINUTES mins left (discharging at $PRESENT_RATE$UNIT)\n"
+
[[ $PRESENT_RATE -ne 0 ]] &amp;&amp; text=$text"You have about $REMAINING_MINUTES mins left (discharging at $PRESENT_RATE$UNIT)\n"
# Send to /var/log/acpid
+
# Send to /var/log/acpid
echo -e -n $text
+
echo -e -n $text
# Send to all terms
+
# Send to all terms
#echo -e -n $text | wall
+
#echo -e -n $text | wall
# Send an X pop-up
+
# Send an X pop-up
eval $(w -s -h|grep --max-count=1 "\(startx\|dm\?\)"|sed 's/^\([^[:space:]]\+\)[[:space:]]\+\([^[:space:]]\+\).*$/XUSER=\1;XDISP=\2;/')
+
eval $(w -s -h|grep --max-count=1 "\(startx\|dm\?\)"|sed 's/^\([^[:space:]]\+\)[[:space:]]\+\([^[:space:]]\+\).*$/XUSER=\1;XDISP=\2;/')
[[ "$XDISP" != :* ]] &amp;&amp; XDISP=:0
+
[[ "$XDISP" != :* ]] &amp;&amp; XDISP=:0
echo -e -n $text | su - $XUSER -c "DISPLAY=$XDISP /usr/X11R6/bin/xmessage -center -timeout 10 -file - " &amp;
+
echo -e -n $text | su - $XUSER -c "DISPLAY=$XDISP /usr/X11R6/bin/xmessage -center -timeout 10 -file - " &amp;
# Play a sound
+
# Play a sound
aplay $WARNING_SOUND
+
aplay $WARNING_SOUND
fi
+
fi
if [ $DO_CRIT -ne 0 ] ; then
+
if [ $DO_CRIT -ne 0 ] ; then
# Shutdown
+
# Shutdown
shutdown -h now
+
shutdown -h now
# Sleep if you prefer and have an adequate script
+
# Sleep if you prefer and have an adequate script
#/etc/acpi/actions/acpi_handler.sh button_sleep
+
#/etc/acpi/actions/acpi_handler.sh button_sleep
fi
+
fi
fi
+
fi
  +
fi
fi</nowiki>
 
  +
</source>
   
 
/etc/init.d/acpid reload
 
/etc/init.d/acpid reload

Revision as of 18:21, 28 March 2008

Converted with HTML::WikiConverter::MediaWiki from my old phpwiki site


How to tune a laptop to save battery life and to handle on-the-go configuration?

ACPI

  • apt-get install acpi acpid acpitool

Adaptative CPU speed (on Pentium Mobile Centrino) with 2.6 kernels

Choose one of these methods:

With laptop_mode (preferred as it does more than CPU scaling and does not run as daemon)

By default, conservative governor when on battery and performance governor when on AC

  • add to /etc/modules:
    • cpufreq_conservative
    • cpufreq_ondemand
    • speedstep_centrino
  • apt-get install laptop-mode-tools
  • /etc/laptop-mode/laptop-mode.conf: set CONTROL_CPU_FREQUENCY=1
  • Note that the script /usr/sbin/laptop_mode contains an error line 606: (at least version 1.11-1, a bugreport exists)
    • Replace THIS_GOVERNOR by THIS_CPU_GOVERNOR
  • Another bug: when on verbose, it empties the log file /var/log/acpid!
  • Some broken ACPI don't send AC events, monitor /var/log/acpid while (un)plugging the power and see if there are calls to lm_ac_adapter.sh or only to lm_battery.sh.
    If only to lm_battery.sh, then set ACPI_WITHOUT_AC_EVENTS=1 in laptop-mode.conf

With powernowd:

By default, aggressive switch to highest freq when load > 80% and progressive switch to lowest freq when load < 20%

  • apt-get install powernowd
  • add to /etc/modules:
    • cpufreq_userspace
    • speedstep_centrino

Manually:

If you want to use always the same governor, then this is the easiest:

  • apt-get install sysfsutils
  • add to /etc/modules the desired scaling governor: cpufreq_(powersave/conservative/ondemand)
  • edit /etc/sysfs.conf
    • devices/system/cpu/cpu0/cpufreq/scaling_governor=ondemand
  • for some stats:
    • modprobe cpufreq_stats
    • cat /sys/devices/system/cpu/cpu*/cpufreq/stats/*
      and you will see how much time was spent on each freq and how many switches occured.

cf also package cpufreqd especially for kernels 2.4

Networking

  • apt-get install ifscheme ifplugd
    • when using ifplugd to monitor an interface, this interface should not be "auto" in /etc/network/interfaces

Some problems:

  • At boot time, ifscheme is called between ifupdown_clean and ifupdown, so /etc/default/ifscheme BOOT_SCHEME=my_scheme does not work, hack: put this instead in the /etc/default/ifscheme file:
    • echo my_scheme > /etc/network/run/scheme
  • interface seems up but left unconfigured at boot time -> if the cable is already plugged ifplugd does not configure the interface
  • after a suspend-to-ram, ifplugd does not configure the interface

Wireless:

  • waproamd?

Suspend-to-ram

  • first, try:
    • sync
    • echo "mem" >> /proc/power/state
  • ongoing...

Suspend-to-disk

  • first, try:
    • sync
    • echo "disk" >> /proc/power/state
  • ongoing...

HD

spin down:

  • laptop-mode-tools (preferred)
    • apt-get install laptop-mode-tools hdparm
    • seems to work even with SATA and seems more efficient than noflushd (and can handle CPU scaling and other tweaks as well)
  • noflushd
    • does not work with SATA controller
    • requires a better sata passthrough for hdparm

smartmon:

  • smartmon with SATA?
  • cf also HardDrives

Hotkeys

  • apt-get install hotkey-setup
  • Use the keys via the Gnome preferences->Keyboard shortcuts (gnome-keybinding-properties)
  • You can try setup the keys yourself with e.g. lineak, cf LaptopDell

Screen

If you have a Radeon video card, it does not turn off when you close your LID and if you have e.g. a Dell D610 with an Intel 915GM card, id does turn off but doesn't turn on anymore when opened, even worse!!
Here is a script backlight_install.sh to solve both problems:

#!/bin/bash

# Version: 0.04
# Copyright:
#    2006 Philippe Teuwen &lt;phil-debian _at_ teuwen.org&gt;
# License:
#    GPL
# Usage:
#    Install radeontool if you have an ATI Radeon  video card
#    or install vbetool if you have an Intel 915GM video card
#    To install this script, run it without params

# For printing extra messages -&gt; /var/log/acpid
DEBUG=false

# Supported card_handlers: radeon/vbepost/vbestate
# You are not supposed to change this yourself but rather run this script
# without parameters for a proper installation!!
card_handler=undef

###########################################################################
# read permanent states
lid_state="unknown"

function read_lid_state() {
    case $(cat /proc/acpi/button/lid/LID/state) in
        *open)
            lid_state=open
        ;;
        *closed)
            lid_state=closed
        ;;
    esac
}

function check_installed() {
    tool=$1
    if which $tool &gt;/dev/null; then
        echo "Good! $tool found."
    else
        echo "Please install $tool and run this script again"
        exit 1
    fi
}

function install() {
    EVENT_NAME=backlight_handler
    echo "Installation of this script..."
    echo -n "Which card handler do you want to use? [radeon/vbepost/vbestate/none]: "
    #TODO: detect radeon automatically?
    read mycard
    case "$mycard" in
        radeon)
            check_installed radeontool
            ;;
        vbepost)
            check_installed vbetool
            ;;
        vbestate)
            check_installed vbetool
            echo "Saving current video hardware data..."
            mkdir -p /var/lib/vbetool
            save_vt_nr=$(fgconsole)
            chvt 1
            vbetool vbestate save &gt; /var/lib/vbetool/vbestate
            chvt $save_vt_nr
            echo "Done."
            ;;
        none)
            echo "Then you probably don't need this script! Exiting."
            exit 0
            ;;
        *)
            echo "Error: unsupported card handler!: $mycard. Exiting."
            exit 1
            ;;
    esac
    echo "Installation of the script"
    ACTION_DEST=/etc/acpi/actions
    EVENT_DEST=/etc/acpi/events
    me="$(basename $0)"
    cd "$(dirname $0)"
    if [ ! -d $EVENT_DEST ]; then
        echo "Error! Did you install acpid?"
        exit 1
    fi
    cat &gt; $EVENT_DEST/$EVENT_NAME &lt;&lt; EOF
event=button[ /]lid
action=$ACTION_DEST/$EVENT_NAME.sh %e
EOF
    /etc/init.d/acpid reload
    if [ "$(pwd)/$me" != "$ACTION_DEST/$EVENT_NAME.sh" ]; then
        mkdir -p "$ACTION_DEST"
        sed "s/^\(card_handler=\).*/\1$mycard/" $me &gt; "$ACTION_DEST/$EVENT_NAME.sh"
        chmod 755 "$ACTION_DEST/$EVENT_NAME.sh"
    else
        # In-place re-configuration
        sed -i "s/^\(card_handler=\).*/\1$mycard/" $me;
    fi
    echo "Installation finished!"
    exit 0
}

###########################################################################
# Main()

[ "$1" = "" ] &amp;&amp; install
read_lid_state
$DEBUG &amp;&amp; echo "LID: $lid_state"
case "$lid_state" in
    open)
        $DEBUG &amp;&amp; echo "Setting light on";
        case "$card_handler" in
            radeon)
                radeontool light on;
            ;;
            vbepost)
                save_vt_nr=$(fgconsole)
                chvt 15
                vbetool post
                sleep 1
                chvt $save_vt_nr
            ;;
            vbestate)
                save_vt_nr=$(fgconsole)
                chvt 15
                if [ -e /var/lib/vbetool/vbestate ]; then
                    vbetool vbestate restore &lt; /var/lib/vbetool/vbestate
                else
                    $DEBUG &amp;&amp; echo "Error: unconfigured vbestate, fallback to vbepost";
                    vbetool post
                fi
                sleep 1
                chvt $save_vt_nr
            ;;
            *)
                $DEBUG &amp;&amp; echo "Error: unknown card_handler: $card_handler";
            ;;
        esac
        ;;
    closed)
        $DEBUG &amp;&amp; echo "Setting light off";
        case "$card_handler" in
            radeon)
                radeontool light off;
            ;;
            vbe*)
            ;;
            *)
                $DEBUG &amp;&amp; echo "Error: unknown card_handler: $card_handler";
            ;;
        esac
        ;;
    *)
        $DEBUG &amp;&amp; echo "Error: LID state not recognized: $lid_state"
        ;;
esac

If you know what you are doing, you can achieve much smaller script, cf LaptopDellD610 step-by-step

Low battery warning

As I mostly use icewn and there is no alert mechanism forseen in it, I use my own script: /etc/acpi/events/warn_battery:


event=battery.*
action=/etc/acpi/actions/warn_battery.sh %e

/etc/acpi/actions/warn_battery.sh (chmod +x):

#! /bin/bash

# Automatically warns when the battery almost runs out.
# Version: 0.03
# Copyright:
#       2006 Philippe Teuwen &lt;phil-debian _at_ teuwen.org&gt;
# License:
#       GPL

BATT_INFO=/proc/acpi/battery/$2

MINIMUM_BATTERY_MINUTES=7
MINIMUM_BATTERY_CHARGE_MAH=500
MINIMUM_BATTERY_CHARGE_MWH=500
CRITICAL_BATTERY_MINUTES=1
CRITICAL_BATTERY_CHARGE_MAH=100
CRITICAL_BATTERY_CHARGE_MWH=100
#WARNING_SOUND=/usr/share/sounds/pop.wav
WARNING_SOUND=/usr/share/kismet/wav/new_network.wav

if [ -f $BATT_INFO/state ] ; then
    [[ $(cat /proc/acpi/ac_adapter/AC/state) = *on-line* ]] &amp;&amp; exit
    if cat $BATT_INFO/state | grep -q discharging ; then
        REMAINING=`cat $BATT_INFO/state | grep "remaining capacity:.*m.h" | sed  "s/.* \([0-9][0-9]* \).*/\1/" `
        REMAINING=${REMAINING:-0}
        FULL=`cat $BATT_INFO/info | grep "last full capacity:.*m.h" | sed  "s/.* \([0-9][0-9]* \).*/\1/" `
        FULL=${FULL:-0}
        IN_MAH=0
        IN_MWH=0
        ( cat $BATT_INFO/state | grep mWh &gt;/dev/null ) &amp;&amp; IN_MWH=1 &amp;&amp; UNIT=mW
        ( cat $BATT_INFO/state | grep mAh &gt;/dev/null ) &amp;&amp; IN_MAH=1 &amp;&amp; UNIT=mA
        DO=0
        DO_CRIT=0
        PRESENT_RATE=`cat $BATT_INFO/state | grep "present rate:.*m" | sed  "s/.* \([0-9][0-9]* \).*/\1/" `
        PRESENT_RATE=${PRESENT_RATE:-0}
        [ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
            REMAINING_MINUTES=$(($REMAINING * 60 / $PRESENT_RATE))
        [ "$REMAINING" -ne 0 -a "$FULL" -ne 0 ] &amp;&amp; \
            REMAINING_PERCENT=$(($REMAINING * 100 / $FULL))
        [ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
            (($REMAINING_MINUTES &lt; $MINIMUM_BATTERY_MINUTES)) &amp;&amp; DO=1
        [ "$IN_MAH" -ne 0 -a "$REMAINING" -lt "$MINIMUM_BATTERY_CHARGE_MAH" ] &amp;&amp; DO=1
        [ "$IN_MWH" -ne 0 -a "$REMAINING" -lt "$MINIMUM_BATTERY_CHARGE_MWH" ] &amp;&amp; DO=1
        [ "$PRESENT_RATE" -ne 0 -a "$REMAINING" -ne 0 ] &amp;&amp; \
            (($REMAINING_MINUTES &lt; $CRITICAL_BATTERY_MINUTES)) &amp;&amp; DO_CRIT=1
        [ "$IN_MAH" -ne 0 -a "$REMAINING" -lt "$CRITICAL_BATTERY_CHARGE_MAH" ] &amp;&amp; DO_CRIT=1
        [ "$IN_MWH" -ne 0 -a "$REMAINING" -lt "$CRITICAL_BATTERY_CHARGE_MWH" ] &amp;&amp; DO_CRIT=1
        if [ $DO -ne 0 ] ; then
            text="WARNING!!!\n"
            text=$text"Remaining: $REMAINING${UNIT}h ($REMAINING_PERCENT%)\n"
            [[ $PRESENT_RATE -ne 0 ]] &amp;&amp; text=$text"You have about $REMAINING_MINUTES mins left (discharging at $PRESENT_RATE$UNIT)\n"
        # Send to /var/log/acpid
            echo -e -n $text
        # Send to all terms
            #echo -e -n $text | wall
        # Send an X pop-up
            eval $(w -s -h|grep --max-count=1 "\(startx\|dm\?\)"|sed 's/^\([^[:space:]]\+\)[[:space:]]\+\([^[:space:]]\+\).*$/XUSER=\1;XDISP=\2;/')
            [[ "$XDISP" != :* ]] &amp;&amp; XDISP=:0
            echo -e -n $text | su - $XUSER -c "DISPLAY=$XDISP /usr/X11R6/bin/xmessage -center -timeout 10 -file - " &amp;
        # Play a sound
            aplay $WARNING_SOUND
        fi
        if [ $DO_CRIT -ne 0 ] ; then
        # Shutdown
            shutdown -h now
        # Sleep if you prefer and have an adequate script
            #/etc/acpi/actions/acpi_handler.sh button_sleep
        fi
    fi
fi

/etc/init.d/acpid reload


Useful packages

Some packages I found useful, especially on laptops:

  • backuppc (to be installed on a server, requires only ssh and rsync on the laptop, cf also some notes on HardDrives)
  • OfflineImap
  • cron-apt

Miscellaneous

  • Disable devices you don't use often in the BIOS to get longer battery life.

todo

  • Stop services such as cupsys, cron, sysklogd, klogd, and inetd when on battery power to get more battery life --- create a script to stop these automatically when on battery and restart them when on AC power.
  • sleepd
  • suspend-to-ram and suspend-to-disk
  • lm-profiler