03.06.12

Use hybrid suspend method by default with pm-utils/Linux (suspend to RAM and disk)

There is this nice method of suspending a computer to RAM (which is quick to suspend and resume, but still uses some battery) and after a given amount of time to disk, if it has not been waken up since then (e.g. after 15 minutes).

Ubuntu (and any other distribution using pm-utils) supports this via the pm-utils package and its pm-suspend-hybrid script.

Unfortunately this is not used by default (even hibernation is not available from the menu by default), but only normal suspend.

The following configuration snippet will make pm-utils use the "suspend_hybrid" method instead of "suspend" when being invoked:

You have to create a file like /etc/pm/config.d/00-use-suspend-hybrid and add the following code (e.g. via sudo -e /etc/pm/config.d/00-use-suspend-hybrid):

Code:

# Always use suspend_hybrid instead of suspend
if [ "$METHOD" = "suspend" ]; then
    METHOD=suspend_hybrid
fi

I came up with this solution after having asked for a method to do so at Ask Ubuntu.

This way hybrid suspend will be used automatically if you select e.g. "Suspend" from the menu or close your laptop's lid (both actions call pm-suspend which then gets remapped).

You can configure the amount of time before hibernation (Suspend To Disk) is being invoked with the PM_HIBERNATE_DELAY variable (in seconds), which you can just configure in the same file, too:

Code:

# Always use suspend_hybrid instead of suspend
if [ "$METHOD" = "suspend" ]; then
    METHOD=suspend_hybrid
fi
PM_HIBERNATE_DELAY=300  # invoke hibernation to disk after 5 minutes (300 seconds)

You might want to make sure that the hybrid method is supported on your system via the following code. If it says "0" it should work:

Code:

sudo pm-is-supported --suspend-hybrid && echo $?

Happy suspending.

Update (2013-10-09): I have updated my own answer at AskUbuntu with another (really hybrid, often preferred method), which you can use with Linux 3.6+.

12 comments

Comment from: Patrick Dickey [Visitor] Email
Patrick DickeySo, in order to set a specific hibernate delay, you would add this code instead of the code mentioned in the article (under the sudo -e /etc/pm/config.d/00-use-suspend-hybrid command)


# Always use suspend_hybrid instead of suspend
if [ "$METHOD" = "suspend" ]; then
PM_HIBERNATE_DELAY=xx
METHOD=suspend_hybrid
fi

where, xx is the number of seconds that you want (for example "PM_HIBERNATE_DELAY=86400" for 24 hours)
2012-06-03 @ 03:40
Comment from: Daniel [Member] Email
Yes, Patrick. But you have missed the equal sign after PM_HIBERNATE_DELAY.
I have fixed your comment and added the example to the blog post itself.
Also, you do not want to set this timeout only when using suspend-hybrid instead of suspend, but also when invoking suspend-hybrid directly. Therefore, it should not be in the "if" block.
2012-06-03 @ 13:41
Comment from: Gonzalo [Visitor]
GonzaloVery usefull Daniel.
I am using it in my debian laptop.
But I have one question. As far as I now, hybrid suspend have the benefit that if you dont go out of power it resume like from suspend very fast...and If yo go out of power it acts like hibernate and you dont loose the data (http://mjg59.livejournal.com/100643.html). Isn't it?
So my question is:
Should I put the "PM_HIBERNATE_DELAY=xx" variable or it is not necesary and I wil not loose my data if I let the power off?.
Because the normal proccess for me is to close the lid, and forget the laptop one day or more and when i came back the battery is was out and the laptop is turned off.
2012-07-05 @ 21:25
Comment from: Daniel [Member] Email
@Gonzalo: the method I describe here is different from what you seem to expect: it will unconditionally hibernate to disk after the configured delay (defaulting to 15 minutes).

You may want to look at the s2both tool from the uswsusp package, which does what you want (from reading the man page): suspend to disk, but do not power off (but do suspend to RAM "forever").
Just install the "uswsusp" package and the default configuration of SLEEP_MODULE="auto" should pick it up (i.e. use it) automatically.
2012-07-06 @ 16:17
Comment from: Otus [Visitor]
OtusThis is not such a good idea when you need to carry the laptop with you: with RAM suspend you expect all the moving parts to be off until you restore, but this causes those to start moving after PM_HIBERNATE_DELAY.

Is there a way to suspend2both and then have the machine just turn off (without further HDD activity) after some time? That would seem to be the best of both worlds.
2012-09-09 @ 19:51
Comment from: FT [Visitor]
FTQuote from pm-is-supported:

"--suspend-hybrid
Test whether hybrid-suspend is supported. Hybrid-suspend is the process where first the state of the system is saved to disk -- just like with hibernate -- but instead of
poweroff, the system goes in suspend state, which means it can wakeup quicker than for normal hibernation. The advantage over suspend is that you can resume even if you run out
of power. s2both is a hybrid-suspend implementation."
2012-09-15 @ 21:01
Comment from: Mike [Visitor] Email
MikeWhat is right? Doesn't work by me...

~$ sudo pm-is-supported --suspend-hybrid ; echo $?
0
~$ pm-is-supported --suspend-hybrid ; echo $?
1
2012-10-14 @ 01:24
Comment from: Daniel [Member] Email
@Mike: you need sudo probably to test for this. And the test with sudo returns "0" (no error).
Considering this "--suspend-hybrid" should be supported on your system.
2012-10-15 @ 21:29
Comment from: bo-what [Visitor] Email
bo-whatFYI -- in 12.04 I noticed that when hibernation is triggered (using PM_HIBERNATE_DELAY=XX), the resume/thaw the shell scripts do not unset the grub recordfail variable. Therefore grub does not autoboot -- timeout is set to -1 and it awaits user selection. I am guessing this requires some editing of scripts in /etc/pm/sleep.d/10_grub-common. Am a novice so I haven't dabbled to figure out the exact change unfortunately.
2012-10-31 @ 11:15
Comment from: shaneonabike [Visitor]
shaneonabikeWeird.... I seem to have two problems here...

1) The suspend option in the user menu doesn't work... 2) closing my lid puts it into "suspend" i think but it won't come back alive after that. If I invoke suspend from sudo pm-suspend it's happen and returns

Any ideas?
2012-11-22 @ 18:23
Comment from: Morrie [Visitor]
Morrie@shaneonabike - Take a look at my answer to this question on SE. Some of the info referenced may help answer 2)... http://askubuntu.com/questions/219633/#305667

P.S Daniel - Catcha errors are displayed in new page. Prior to my installing https://addons.mozilla.org/en-us/firefox/addon/lazarus-form-recovery/ having to retype/c&p my comment would have made me rather annoyed. Please consider using AJAX for this functionality going forward.
2013-06-08 @ 16:36
Comment from: Felix [Visitor] Email
FelixDo you have any idea whether it's possible to use the "true" hybrid method and have the system power down after some time? That is, use it as an improved "suspend_hybrid"?
2014-12-16 @ 14:16

Leave a comment


Your email address will not be revealed on this site.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
You can just use your OpenID to provide your name, e-mail and url.
Seitenleiste