Sunday, October 01, 2006

howto sleep and hibernate on thinkpad

In Windows, we can use Fn-F4 to suspend system to memory, and Fn-F12 to suspend system to disk. It is really very expedite and useful. When using Linux as a desktop, we can also have such way to sleep and hibernate our system and even faciler.

Sleep is also called suspend (to memory), while hibernate is called suspend2 ( to disk). Here is the specific steps:

  1. It is necessary to compile your kernel with ibm-acpi support, if you do not want to download it by yourself, and make sure your kernel source version is new enough, because the latest kernel has contained it. Modify your kernel configure file, add this sentence, which means that ibm-acpi will be compiled as a module.

    CONFIG_ACPI_IBM=m

    If you wanna actuate this module when system startup, usually it is. You should add "ibm-acpi" into, for example, /etc/modules.autoload.d/kernel-2.6.

  2. Install the ACPI daemon "acpid", and let it run when your system boots.
  3. Download the ibm-acpi package from here: http://ibm-acpi.sf.net/. We only need its scripts. Decompress the package, and copy the directory "config" into the root directory.
  4. Download the tpb package from here: http://www.nongnu.org/tpb/. Complie and install it.
  5. To make hotkeys work, you should add this into the startup script, /etc/conf.d/local.start:
    echo enable,0xffff > /proc/acpi/ibm/hotkey

    In order to use tpb successfully, you should have the privilege to read the device nram. Thus, add this script into local.start also:

    chmod a+r /dev/nvram
    echo 1024 > /proc/sys/dev/rtc/max-user-freq
  6. Install hibernate-script, which can be found here: http://www.suspend2.net. If you just hope to sleep, you can write a script yourself. such as:
    echo "mem" > /sys/power/state
    

    It can also work successfully. If you want to use the whole functions of this hibernate-script, you have to patch your kernel source and recomplie it again. The patch can also be found at that website.

  7. Now, When you press ACPI key such as Fn-F4, then cat /var/log/acpid, you will find all ACPI events:
    [Sun Oct  1 17:54:44 2006] received event "ibm/hotkey HKEY 00000080 00001004"
    [Sun Oct  1 17:54:44 2006] executing action "/etc/acpi/default.sh ibm/hotkey HKEY 00000080 00001004"
    [Sun Oct  1 17:54:44 2006] BEGIN HANDLER MESSAGES
    [Sun Oct  1 17:54:44 2006] END HANDLER MESSAGES
    [Sun Oct  1 17:54:44 2006] action exited with status 0
    [Sun Oct  1 17:54:44 2006] executing action "/usr/sbin/hibernate -F /etc/hibernate/ram.conf"

    And this means you can use your function key to suspend your system. If everything is ok, your system will sleep into memory just now.

  8. There is some other tips to use xmodmap, touch ~/.Xmodmap, write this into it:
    keycode 227 = F35
    clear lock
    add mod4 = Caps_Lock

    The first line let you can use Fn key, and the next two lines let you use Caps_Lock key as Windows Key. Run xmodmap ~/.Xmodmap, try CAPS_LOCK, and check if its action has changed. So cool :)

The further detail can be found here: http://www.thinkwiki.org/wiki/How_to_get_special_keys_to_work#tpb_configuration

No comments: