Using suspend to disk with eeeXubuntu on a eeePC

I got a eeePC almost two months ago and I really enjoy using that tiny little thing. It’s small enough to fit into the front pocket in my photo bag and at less than 1 kg it’s barely noticeable. The default OS is not that good however, it’s decent for a basic use of internet applications but otherwise it feels somehow antiquated and for someone used to Ubuntu it’s just not very comfortable.That’s why I installed eeeXubuntu, a custom Xubuntu made specially for the eee.

But I had an issue with the eeePC, the battery life during standby is atrocious: compared to the laptops I used before, putting the eeePC in standby will drain the battery in less than 24h. It’s not a software issue but an hardware one (that may be corrected in the future with a bios update). As I have a very on and off utilization of the eeePC, it wasn’t very practical to either shut it down if I didn’t plan on using it in the next few hours or letting the battery drain in my bag. There is a simple way to correct that: using suspend to disk (also called hibernate).

Under hibernation, the content of the RAM will be written to disk and restored upon wake up. The issue is that the default system for hibernation for the 2.6 linux kernel needs to have a swap partition that is bigger than the total RAM installed.On a system with a 4GB SSD, with the default install of eeeXubuntu already taking more than 2GB, I had some reticences repartitioning the SSD just for hibernation purposes.

As the swap space would not be used for swap anyways as it seems that using swap on a SSD is apparently not a good idea (there is an ongoing debate on whether modern SSD like the one used in the eee can take the abuse).Anyway that’s enough introduction, here is a simple way to use hibernation on the eee without having to create a swap partition. The only thing you need is to create a swap file that’s half the size of the installed RAM in the eeePC. It actually works better for me compared to suspend to ram as I had some issues with the graphic controller not waking up sometimes. Click below for the howto.

UPDATE: a similar but more clever way of achieving the same goal: Hibernate fix on the eee-ubuntu wiki.

DSC_2059.jpg

shot.png

How-to

First, create a swap file:

dd if=/dev/zero of=/swap bs=1024k count=256mkswap /swap

256MB for the 512MB eeePC.Add this to /etc/fstab:

/swap	swap	swap	defaults	0	0

Then, tell the kernel to not use the swap file for swapping:

sysctl -w vm.swappiness=1

Modify the last line of /etc/sysctl.conf so it sticks:

vm.swappiness=1

You can now activate the swap file:

swapon /swap

And now the magic ingredient: µswsusp, an alternative suspend method for the linux kernel that can use swap file instead of swap partition and also support other neat features like compression and encryption.Install it:

aptitude install uswsusp

(don’t forget to enable memory compression).To test it:

s2disk

It will write the content of the RAM to the swap file and shutdown the eee.Press the power button on the eee to wake it up.To enable this method as the default system for hibernation, edit the following file: /usr/lib/hal/linux/scripts/hal-system-power-hibernateThere is a bug in this script, it will look for s2disk in the wrong place, you’ll have to edit it so it looks like this:

/sbin/s2disk

As this script is part of the HAL package, it means that it WILL break if this package is updated, you’ll have to reedit the above file if hibernate doesn’t work after an update.

Caveats

The console is apparently completely fubared, not a big loss for me.

References

Fixing software suspend / hibernate with uswsusp in Ubuntu Feisty (and Edgy)

by Reefab / February 22, 2008
categories: Software

8 Comments

  1. Arnaud says:

    I tried your method, but I get an error when trying s2disk :
    “Invalid resume device”

    I checked in /etc/uswsusp.conf, and I have “resume device = /swap”, so it looks OK to me ?

    My swapfile is 256MB (created using your command line), so that is 268435456 bytes.

    My uswsusp.conf file looks fine to me :

    # /etc/uswsusp.conf(8) — Configuration file for s2disk/s2both
    resume device = /swap
    compress = y
    early writeout = y
    image size = 238941634
    RSA key file = /etc/uswsusp.key
    shutdown method = platform
    resume offset = 8288

    What could be wrong here ?

  2. Arnaud says:

    I’ve got it working !
    “resume device” must be the partition and not the swap file, so :
    resume device = /dev/sda1
    … works !!!
    The “resume offset = 8288″ is here to tell where the swapfile is located.

  3. Andrew says:

    Don’t forget to add yourself to the powerdev group.

  4. Anonymous says:

    Console is fubared? In which way exactly? I use the console all the time and would rather not fubar it too bad if I can avoid it…

  5. simon linden says:

    Hello,

    can you please correct your commands to create the swap-file!?

    There are two commands to create a swap-File. First:
    “dd if=/dev/zero of=/swap bs=1024k count=256″

    Second:
    “mkswap /swap”

    You put the two commands in one line without a blank between so it looks like one command that doesn’t work.

    Thank you very much!

  6. uncle says:

    hi,
    i am running debianeee on my 701 with XFCE, and i really like that theme in your screenshot, can you tell me what it is please?

  7. Alexey says:

    Hm. It would be nice to include all the commands into hibernation script. I.e. not to have permanently 256M file “just for a case”, but to create it in the moment of hibernation – and delete (optionally) after resuming.

  8. gaston says:

    Hey, i wondered how did you get eeexubuntu to look like that! thanks
    Greetings form Argentina.

Leave a Reply

delicious
Last.fm

  • Obsessions

    Obsessions

    by Rafale

    Played 568 times.

    Sword & Sworcery LP - The Ballad of the Space Babies

    Sword & Sworcery LP - The Ballad of the Space Babies

    by Jim Guthrie

    Played 397 times.

    Drink the Sea

    Drink the Sea

    by The Glitch Mob

    Played 300 times.

    Fahrenheit Fair Enough

    Fahrenheit Fair Enough

    by Telefon Tel Aviv

    Played 296 times.


  • Röyksopp

    Röyksopp

    Played 759 times.

    Telefon Tel Aviv

    Telefon Tel Aviv

    Played 725 times.

    Modeselektor

    Modeselektor

    Played 589 times.

    Rafale

    Rafale

    Played 568 times.