Thursday, October 11, 2007

Suspending your IBM Thinkpad T40

For this I had to upgrade the kernel to the latest, 2.6.23, since my previous kernel doesn't inherently support suspend feature unless I patch it with tuxonice. To check whether your kernel version support suspend:
cd /usr/src/linux
make xconfig
Under "Power management options (ACPI, APM)" tab, check whether "suspend to RAM and standby" exists. If it doesn't, I suppose suspend is not supported by your kernel.
After downloading the kernel and compiling it, by right, suspend should work.
echo -n "mem" > /sys/power/state
Press Fn button on your thinkpad to resume.
During the compilation process, typically we would want to do make oldconfig, and we should enable all the suspend related features whenever asked. Also we might want to enable ibm_acpi
I also needed to install initrd in order to mount root partition using ext3 modules:
cd /boot
mkinitrd -c -k 2.6.23-smp -m ext3 -f ext3 -r /dev/hda2
It will create /boot/initrd.tgz file, that we'll want to load it along with the kernel at boot time. Now edit the /etc/lilo.conf :
kedit /etc/lilo.conf
The linux part should look like this :
image = /boot/vmlinuz
initrd = /boot/initrd.gz
root = /dev/hda2
label = newLinux
read-only
image = /boot/vmlinuz-huge-smp-2.6.21.5-smp
root = /dev/hda2
label = oldLinux
read-only
Then, run lilo and reboot to check whether it works.
In order to automate the suspend process whenever we close laptop lid, we have to configure acpid. Excerpted from the link:
Basically, acpid just executes scripts residing in /etc/acpi/actions. Which script to launch at which event is configured in several files in /etc/acpi/events. All actions are documented in /var/log/acpid.
The event script needs to be created within /etc/acpi/events and can have any name you like. In this case we call it lid because it will trigger the lid event. Do # vi /etc/acpi/events/lid and make it look like this:
event=button/lid
action=/etc/acpi/actions/sleep.sh %e

The "event" line is a regular expression specifying the events we're interested in. You can determine what the event strings are from looking at /var/log/acpid after trying to suspend, close the lid, etc. . You can find information about the event strings ibm-acpi generates for certain keys at the Special Keys HOWTO.

The "action" line is the command to be executed when these events are dispatched. In this example we call the sleep.sh script residing in /etc/acpi/actions and pass the event description text using the %e placeholder.
Our example /etc/acpi/actions/sleep.sh script looks as follows:
#!/bin/sh

# if launched through a lid event and lid is open, do nothing
echo "$1" | grep "button/lid" && grep -q open /proc/acpi/button/lid/LID/state && exit 0

# remove USB 1.1 driver
rmmod uhci_hcd

# sync filesystem and clock
sync
/sbin/hwclock --systohc

# switch to console
FGCONSOLE=`fgconsole`
chvt 6
/usr/sbin/radeontool light off

# go to sleep
sleep 5 && echo -n "mem" > /sys/power/state

# readjust the clock (it might be off a bit after suspend)
/sbin/hwclock --adjust
/sbin/hwclock --hctosys

# reload USB 1.1 driver
modprobe uhci_hcd

# turn on the backlight and switch back to X
radeontool light on
chvt $FGCONSOLE
Then reboot, to restart the acpi daemon.

More information is available at :
http://www.thinkwiki.org/wiki/How_to_configure_acpid
http://ibm-acpi.sourceforge.net/README
http://www.thinkwiki.org/wiki/How_to_make_ACPI_work
http://www.thinkwiki.org/wiki/ThinkWiki
http://ibm-acpi.sourceforge.net/
http://www.linux.com/articles/54610

No comments: