Ubuntu Diary : Suspend and Hibernate with µswsusp

Intro

The original suspension and hibernation functions in Ubuntu 7.04 does not work well on my laptop (IBM Thinkpad T42). After searching WWW, I found a better package, µswsusp, for supporting these functions. However, several problems occurred when I tried to use it. I could find solutions of some problems in Ubuntu forum. For those problems that I couldn’t find solutions, I had to solve them by myself. Finally I succeeded after a lot of try and error. Hope I don’t miss any step in the following.

Suspension

The following method works on my laptop.

  1. Install uswsusp.
    $ sudo apt-get install uswsusp
  2. Edit /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux. Replace the whole content with the following two lines.
    #!/bin/sh
    /sbin/s2ram
  3. Try it.

Some users in the Ubuntu forum suggest the following way to use µswsusp.

  1. Install uswsusp.
    $ sudo apt-get install uswsusp
  2. Remove all packages that appear before s2ram in /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux. Otherwise, s2ram will not be the first choice when suspending. Here we don’t really uninstall those packages but use dpkg-divert to rename necessary files. For example, I have /etc/acpi/sleep.sh before s2ram. So I execute the following command.
    $ sudo dpkg-divert --rename --divert /etc/acpi/sleep.sh.disabled /etc/acpi/sleep.sh
  3. In /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux, it assumes s2ram is in /usr/sbin. However, Ubuntu installs it in /sbin. Thus we have to make a symbolic link.
    $ sudo ln -s /sbin/s2ram /usr/sbin/s2ram

However, this method does not work on my laptop. Every time it resumes from a suspension state, the Gnome desktop restarts and I lose the previous session.

Hibernation

  1. Install uswsusp.
    $ sudo apt-get install uswsusp
  2. It seems that the package in Ubuntu’s repository is too old. In this step, we want to use some scripts from Ubuntu’s repository to generate initrd with the latest uswsusp.
    1. Download the source code suspend-0.7.tar.gz of uswsusp.
    2. Extract suspend-0.7.tar.gz.
    3. Modify config_parser.h and Makefile. Replace “suspend.conf” with “uswsusp.conf. For example, in config_parser.h, we have the following line.
      #define CONFIG_FILE     "/etc/uswsusp.conf"

      In Makefile, we have the following line.

      CONFIGFILE=uswsusp.conf

      I have to change this such that the command resume can find configuration file after resuming.

    4. Compile the source code.
      $ make
    5. Install the executables.
      $ sudo cp s2both /sbin/s2both
      $ sudo cp s2ram /sbin/s2ram
      $ sudo cp s2disk /sbin/s2disk
      $ sudo cp resume /usr/lib/uswsusp/resume
    6. Copy the configuration in conf/suspend.conf to /etc/uswsusp.conf and modify it. Below is my /etc/uswsusp.conf.
      # /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both
      snapshot device = /dev/snapshot
      resume device = /dev/sda3
      #compress = y
      early writeout = y
      image size = 365106872
      #RSA key file = /etc/uswsusp.key
      shutdown method = platform
      splash = y

      In this configuration file, you have to specify your resume device. For example, my swap partition is /dev/sda3. Some lines are commented out because they are not recognized by uswsusp-0.7.

  3. Like suspend, we want s2disk to be the first choice when hibernating. Thus replace /usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux with the following.
    #!/bin/sh
    /sbin/s2disk

    Another way is to rename all files that appear before s2disk in /usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux. for example,

    $ sudo dpkg-divert --rename --divert /etc/acpi/hibernate.sh.disabled /etc/acpi/hibernate.sh

    and create a symbolic link because hal-system-power-hibernate-linux assumes s2disk is in /usr/sbin.

    $ sudo ln -s /sbin/s2disk /usr/sbin/s2disk

    Although /etc/acpi/hibernate.sh supports s2disk, it passes wrong arguments to s2disk. However, after I fix it, there is still other problem with /etc/acpi/hibernate.sh, for example, Gnome desktop restarts and previous session is lost. That’s why I want to disable hibernate.sh.

  4. Update /etc/initramfs-tools/conf.d/resume. Again you have to set the resume device to your real swap partition. For example,
    RESUME=/dev/sda3
  5. Update initrd.
    $ sudo update-initramfs -u
  6. Try it now.

Troubleshooting

Q: s2disk complains that it could not use the resume device.
A: Execute the following command first.

$ free

If your output looks like:

             total       used       free     shared    buffers     cached
Mem: 775100 422044 353056 0 448 227016
-/+ buffers/cache: 194580 580520
Swap: 0 0 0

This is because the swap partition has new UUID, but it does not update /etc/fstab. If this happens,
you can mount the swap partition by

$ sudo swapon /dev/sda3

Then change the UUID of the swap parition by the real path in /etc/fstab, for example

/dev/sda3        swap    sw              0       0

Q: After resuming, Gnome desktop restarts.
A: Be sure to use s2disk directly without /etc/acpi/hibernate.sh.

Q: When resuming, it stops in the boot logo.
A: This may be caused by setting wrong resume device or wrong configuration file such that the resuming procedure could not find where to load previous state. Press Ctrl+F1 to see if it asks you to enter the resume device, enter the path to your swap partition, for example /dev/sda3, and then press Enter. It should continue to resume. Make sure that the name of configuration file in config_parser.h and Makefile is set correctly. Also make sure to set correct resume device in /etc/uswsusp.conf and /etc/initramfs-tools/conf.d/resume. You may need to update initrd by

$ sudo update-initramfs -u

Reference

Since everyone could have different problems, I list some references below.

0 意見: