Linux.com

Feature

Put your laptop to sleep

By Jonathan Oxer, Kyle Rankin, and Bill Childers on August 01, 2006 (8:00:00 AM)

Share    Print    Comments   

Part of proper power management is the ability to put your laptop to sleep. ACPI sleep is defined as a state where the system is still technically powered on, but the screen and hard disk are powered down and the computer is using just enough power to keep the contents of RAM alive. The Ubuntu development team has devoted an immense amount of effort toward getting ACPI power management working properly. As it stands, Ubuntu is power-management-friendly right out of the box, thanks to the recent addition of the gnome-power-manager package. It turns out there's not much required to get most modern laptops to sleep and wake up correctly.

This article is excerpted from the newly published book Ubuntu Hacks , copyright 2006 Kyle Rankin, Jonathan Oxer, and Bill Childers. All rights reserved. Used with permission.

The Dapper Drake release of Ubuntu Linux includes the new gnome-power-manager package, which enables ACPI sleep much like the system-tray power applet in Windows. Finally, sleep "just works" in Linux. The gnome-power-manager applet is configured to start automatically, and it lives in GNOME's panel notification area. If you right-click on the little battery icon, you'll see a menu pop up with choices to Suspend or Hibernate, and a Preferences choice.

This deceptively simple little application gives you a lot of control over your laptop's sleep behavior. If you click on Preferences, you'll see the Power Management Preferences dialog box. In this dialog's Sleep tab, you can configure different behavior depending on whether you're plugged into AC power or running on battery. One of the most interesting features is your ability to control the backlight brightness of your laptop's screen depending on the machine's power state. A large consumer of power in a laptop is the screen's backlight, so being able to automatically turn down that lamp while on battery will help squeeze more runtime out of the system while it's unplugged.

The Options tab is where you can set the default type of sleep you wish for the system to use, as well as what actions will engage the sleep mechanism. The default sleep type is set to Suspend, which refers to ACPI sleep. (Hibernate is a totally different type of sleep mechanism that we'll cover in a moment.) If you wish, under the Actions section of the dialog box, you can set the system to automatically sleep when the laptop lid is closed. This is a handy feature if you're on the go: simply shut the lid and run off to your next appointment; then open the lid later, and the machine will wake up without any intervention.

Ubuntu Hacks The Advanced tab of the dialog controls the notification icon's behavior. If you want the icon to appear only when you're charging or discharging, or you want to turn off the icon altogether, here's where you change those settings.

If you're not seeing the notification icon, perhaps it's because you're plugged into AC power. If you'd like to see the applet all the time, unplug your laptop for a moment and the icon should appear. You can then use the Advanced tab to change the notification icon settings.

When you have all your settings configured to your liking, simply click the Close button, and the dialog box will close, saving your configuration changes.

Your system is now ready for you to test sleep mode. Ensure that your system is running on battery; then simply shut the lid of the laptop and see what happens. You should hear the hard disk power down, and one of the power LEDs should indicate a power-state change by blinking or some other method.

Hopefully, your machine went to sleep properly. Now you need to see if it wakes up correctly. Simply open the lid, and the computer should start waking up. When it's ready for use, you'll be prompted for your system password by gnome-screensaver. Enter your password, and your system should be in the exact same state as it was when you powered it off.

Hibernate your laptop

Because ACPI sleep does require a trickle of power to keep the CPU and RAM alive, it may not be desirable in all situations. Hibernate has been designed as the complement to ACPI sleep. It takes the contents of RAM and saves them to the system's swap partition. As a result, it requires absolutely zero power to maintain that hibernated state.

There is a downside to hibernating a machine, however. Due to the fact that the system saves the contents of RAM before powering off, and then loads the contents of RAM after the kernel loads on reboot, it does take a fair amount of time to enter and exit the hibernated state. However, hibernating is still faster than powering off and restarting your machine, and there's the added benefit of saving application state.

Since hibernation saves the exact contents of RAM to your swap partition, the size of your swap partition must be larger than the amount of RAM you have in the machine. Ubuntu configures this automatically if you have done a default installation, but if you override the default partitioner during installation, you need to keep this point in mind.

Configuring and using hibernation

Since hibernation and sleep are similar and use the underlying Linux ACPI subsystem, they both use gnome-power-manager to configure and control their settings. You can adjust the default type of sleep to be hibernation from within the preferences of gnome-power-manager, but keeping the default set to Suspend makes sense due to the time involved in entering and exiting a hibernated state. If you do decide to adjust this setting, you can right-click on the gnome-power-manager icon, select Preferences, and click on the Options tab.

Now that you have your preferences set how you like them, it's time to test hibernation. Assuming you're using the stock Ubuntu preferences for gnome-power-manager, you'll need to engage hibernation by right-clicking on the gnome-power-manager applet and selecting Hibernate. Once you do, the system will immediately dim the screen, and you should hear a good deal of hard-disk activity. Once the disk stops churning, the system will power off. At this point, the system is in hibernate mode and can be left in this state indefinitely without using any battery power.

To exit the hibernated state, simply power on the system normally. The bootloader will come up, and the kernel will boot normally, until it detects a RAM image on the swap partition. At that point, the system will load up the RAM image and should return to where you left it. Typical times to enter hibernation run between 30 seconds and 1 minute, and times to exit hibernation (including the BIOS test) run about the same.

Warning -- if your system is configured to boot multiple operating systems, you need to be careful here. In theory, you should be able to hibernate your Ubuntu system and then boot into a different operating system. But this is fundamentally risky: if you change anything on the Ubuntu partition, you'll be in heaps of trouble. And if you're sharing a swap partition between Ubuntu and another Linux distribution, you'll be in a world of trouble if that other Linux distribution boots up, since it will erase your hibernated state (or may itself try to resume from that hibernated state). Play it safe: if you are hibernated, don't boot into anything except the system you hibernated from.

Between sleep and hibernation, you have all the great power management capabilities at your disposal.

Share    Print    Comments   

Comments

on Put your laptop to sleep

Note: Comments are owned by the poster. We are not responsible for their content.

Suspend in Ubuntu just works !

Posted by: Anonymous Coward on August 02, 2006 01:21 AM
Agree. I am using Ubuntu Dapper on my old laptop Toshiba Tecra 8200 PIII 850Mhz RAM256Mb.
Suspend to RAM and wake-up works perfectly and it always works, including the close/open lid.
With other distro there is always gotcha, e.g. only suspend works, but wake-up will fail etc.

#

Re:Suspend in Ubuntu just works !

Posted by: Anonymous Coward on August 02, 2006 06:49 PM
This only works for me if USB stuff isn't compiled in as a module, which really is a dealbreaker for me, because I love the moduleway of not having to laod stuff you don't use. Like I don't want to start my usb-storage module and usb mouse modules on boot, especially if I'm not gonna use it. And If I decide to put in a usbdisk og a mouse, it gets loaded. This saves boot-time and memory. However it breaks suspend horribly<nobr> <wbr></nobr>:/

#

Suspend/sleep

Posted by: Anonymous Coward on August 02, 2006 08:55 PM
I have not yet tried Ubuntu Dapper with my laptop, but the Ubuntu 5.x series ACPI implementation did not work at all on my Gateway 4024GZ: close lid, lock system solid. I used to have to comment out the call to the script that ran when the lid was closed just so the system wouldn't hard lock when I closed the lid. Maybe I'll give Dapper a try and see how it does. Mine isn't the most Linux-friendly laptop, but Ubuntu was the only disto where I could get nearly everything working.

#

Not always

Posted by: Anonymous Coward on August 02, 2006 10:13 PM
I'm running 6.06 on a Presario V2401 and it sometimes works. Sometimes it reboots with a cold start, and other times it restarts with the network broken (as in needs a reboot to work). Granted, the bcm43xx driver seems a bit flakey, but I wouldn't trust hibernate and suspend just yet.

#

Re:Not always

Posted by: Anonymous Coward on August 03, 2006 12:08 AM
I have an HP NX6125, which also has a broadcom wireless adapter. The problem really is with the bcm43xx driver, as Hibernate works if you
#modprobe -r bcm43xx
before you hibernate and then load it again after you resume.
There's probably some way (I hope) to make that automatic, but I haven't found out yet.

#

cashcrate

Posted by: Anonymous Coward on August 03, 2006 12:56 AM
Get a REAL check in the mail every month

<a href="http://gentleurl.net/LKJZZ/" title="gentleurl.net">http://gentleurl.net/LKJZZ/</a gentleurl.net>

You get money for filling out surveys, usually $1 each, but they add up. There are also free trials for more than $10 each. The surveys are really easy and only take a couple minutes. Each month they send u a real check in the mail for your earnings. This site is 100% legit. You can check the forums for proof of payment. Its just a good way to make some extra cash.

#

screen

Posted by: Anonymous Coward on August 03, 2006 04:31 PM
well done on the power mgt.
all we need now is easy gui based tools (and drivers) for setting screen resolutions and
setting up dual monitor and Ubuntu might be a
viable alternative to osx.

#

Suspend on T42

Posted by: Anonymous Coward on August 04, 2006 12:26 AM
Both suspend to RAM and hibernate are working fine with Ubuntu 6.06 on an IBM Thinkpad T42. For some reason, hibernate only works when selected from the keyboard, however, and not the gnome logout dialogue...

#

It's more about hardware than Ubuntu

Posted by: Anonymous Coward on August 04, 2006 05:29 AM
While the Ubuntu guys have done work in making the configuration easy for lid close/open etc, it's all about proper support from laptop manufacturers. If you have a DSDT that is hosed or tries to claim that it can only suspend under windoze (and *many* laptops do have such crappy DSDTs), then there's not much that you can do about it.

See... you define an ACPI specification and then all the manufacturers ignore it. Pity, really....

(Another article that falls into the "I wish people would stop telling me that Ubuntu has saved the world" category.)

#

Suspend when using mains

Posted by: Anonymous Coward on August 04, 2006 11:41 PM
"Ensure that your system is running on battery<nobr> <wbr></nobr>...".
Do you have to be on battery to use suspend?

#

Suspend assumes gnome/kde is running

Posted by: Anonymous Coward on August 11, 2006 03:37 AM
Pressing the suspend-key will call<nobr> <wbr></nobr>/etc/acpi/sleebtn.sh, which uses acpi_fakekey to generate an event on<nobr> <wbr></nobr>/dev/input/event*, which is received by gnome-power-manager or similar applications.

To get suspend to work without gnome-power-manager,
replace the acpi_fakekey line in sleepbtn.sh with the line:<nobr> <wbr></nobr>/etc/acpi/sleep.sh sleep

#

WTF? The descriptions in this article do not match

Posted by: Anonymous Coward on September 20, 2006 03:42 AM
The description of the gnome-powe-preferences applet do not at all match what I have on my Ubuntu 6.06 Dapper installation. There is no "advanced" tab, for example.

What is this article referring to????

#

Still no go

Posted by: Administrator on August 04, 2006 01:48 AM
It's still a no go on my Emachines Athlon 2800+. ACPI works, as the frequency scaling works perfectly (Scales between 500mhz and 2.1 Ghz). My laptop goes to sleep (sleep or hibernate), but it never wakes up when you hit the power button. I wind up having to hard power it off (hold power button for 5 seconds).

#

Put your laptop to sleep

Posted by: Anonymous [ip: 86.57.218.245] on December 14, 2007 11:03 AM
Sleep and hibernate doesn't work on my HP n610c and dv4000. Using Ubuntu Gutsy Gibbon 6.10. Does anybody know any way out? senkoslava (at) mail (dot) ru

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya