LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Laptop and Netbook (http://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/)
-   -   From suspend to hibernate when battery is low (http://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/from-suspend-to-hibernate-when-battery-is-low-4175467842/)

andreas-r 06-29-2013 01:59 PM

From suspend to hibernate when battery is low
 
I'm running Crunchbang (Debian Wheezy + OpenBox, basically) on a Lenovo Thinkpad Edge 13. I don't have a power manager, instead I'm using apcid, pm-utils and xautolock to get my computer to suspend when lid is closed or it has been idle for some time, and to hibernate when battery is critically low. It's fine, only problem is:

When my computer is in suspend mode and I leave until the battery is dead, it shuts down.

I would like it to stay on suspend as long as possible and go into hibernation if the battery level gets critically low.

I do not want it to:
- change from suspend to hibernate after a predetermined amount of time as can be done like this ...
- nor do I want it to go into hybrid mode (saving both to ram and drive and resuming from the latter if battery dies) as can be done with the s2both feature of uswsusp.

In suspend mode I would like my computer to detect when the battery level gets critical and then hibernate.

How could this be done?

Thanks

business_kid 06-29-2013 02:52 PM

Didn't know about s2both, etc. but what you want can not universally be done, AFAICT.

Suspend - cpu goes into S3 power saving state = is dead. It needs an interrupt to wake it.
ACPI stuff won't do it - Catch 22. It needs a cpu. If the battery critical signal can be mapped to a hardware interrupt, just maybe. With the sys interface, the battery critical signal is extremely difficult to find as it comes too late to use for a big wake up then compress & disk write.

andreas-r 06-29-2013 05:33 PM

But some conventional power managers like the one in Unity manages going from suspend to hibernate when the computer runs out of battery though I don't know how ...

TobiSGD 06-30-2013 08:14 AM

You don't need s2both to have mixed suspend/hibernate, you can use pm-tools for that, the command is pm-suspend.hybrid. That would be the only option that I think would work, for the reasons business_kid already pointed out. I would suspect that Unity's power-manager just uses hybrid suspend by default.

andreas-r 06-30-2013 09:30 AM

Quote:

Originally Posted by TobiSGD (Post 4981163)
You don't need s2both to have mixed suspend/hibernate, you can use pm-tools for that, the command is pm-suspend.hybrid.

You mean pm-suspend-hybrid? Tried that before installing uswsusp and thereby s2both. It works but seems to do exactly the same as pm-suspend. I tried taking the battery out after executing the command and it just started up again like after normal power-down (eg. the swap image wasn't restored ...)

The man page says that: "s2both(8) is an hybrid-suspend implementation." I take that do mean that is the only implementation. Am I wrong?

OK, I think I got it now:
- the default pm-suspend-hybrid command suspends and after a given time wakes up and hibernates. Can be set like this.
- s2both offer another implementation in which the computer both suspend to disk and ram, and resumes from disk only if it can't resume from ram (that is, if the computer has been powered down in the meantime).

So they are to different methods of combining suspension and hibernation. Am I right?

TobiSGD 06-30-2013 11:14 AM

Quote:

Originally Posted by andreas-r (Post 4981174)
- the default pm-suspend-hybrid command suspends and after a given time wakes up and hibernates.

Nope. From the pm-utils manpage:
Quote:

pm-suspend-hybrid
Hybrid-suspend is the process where the system does everything it needs to hibernate, but suspends instead of
shutting down. This means that your computer can wake up quicker than for normal hibernation if you do not run
out of power, and you can resume even if you run out of power.
Regarding this:
Quote:

Can be set like this.
I don't know, that link seems to be broken.
Quote:

Tried that before installing uswsusp and thereby s2both. It works but seems to do exactly the same as pm-suspend. I tried taking the battery out after executing the command and it just started up again like after normal power-down (eg. the swap image wasn't restored ...)
Have you added the needed resume= parameter to your kernel command line in the boot-loader?

andreas-r 06-30-2013 11:23 AM

Quote:

Originally Posted by TobiSGD (Post 4981215)
I don't know, that link seems to be broken.

Fixed it.

Quote:

Originally Posted by TobiSGD (Post 4981215)
Have you added the needed resume= parameter to your kernel command line in the boot-loader?

No, how do I do that?

TobiSGD 06-30-2013 12:07 PM

Quote:

Originally Posted by andreas-r (Post 4981221)
No, how do I do that?

Assuming you use the Grub 2 bootloader (default on Ubuntu):
- Open the file /etc/default/grub as root in a text editor
- You should find a line
Code:

GRUB_CMDLINE_LINUX_DEFAULT="quiet"
in there, maybe with other options than "quiet". Add the resume= parameter to it, so that it looks for example like
Code:

GRUB_CMDLINE_LINUX_DEFAULT="quiet resume=/dev/sdXY"
where /dev/sdXY is your swap partition (note that your swap partition should be at least as large as your physical RAM to get hibernate working).
- Save the file and run
Code:

sudo update-grub
Now your bootloader is configured correctly and waking up from hibernation should work.

andreas-r 06-30-2013 01:25 PM

Thanks for the guide TobiSGD, but I think we misunderstood each other. My computer hibernates with pm-hibernate and wakes up just fine both before and after installing the package needed to s2both. pm-suspend-hybrid, though, does the exact same as pm-suspend, unless I use s2both. This is the full description of pm-suspend-hybrid from the man page:

Hybrid-suspend is the process where the system does everything it needs to hibernate, suspends instead of shutting down. This means that your computer can wake up quicker than for normal hibernation if you do not run out of power, and you can resume even if you run out of power. s2both(8) is an hybrid-suspend implementation.

I take that to mean that s2both is a way of making pm-suspend-hybrid work. The only other implementation I've found is the one in the aforementioned link that uses:
Code:

PM_HIBERNATE_DELAY=900
... to set a time after which suspend switches to hibernate. s2both does something else, it suspends to disk and ram, and resumes from disk only if it can't resume from ram, that is, the behavior described in the quotation from the man page.

My claim is that the only way to get this behavior is by way of s2both.

business_kid 07-01-2013 04:35 AM

Yeah, just tried pm-suspend-hybrid right now, as follows: Ran pm-suspend-hybrid, removed psu, removed battery, replaced power & powered on.It did a fresh start, not a resume from hibernation. I really don't think it wrote the disk image (But I've an ssd, so it's hard to be sure).

pm-suspend-hybrid might works for folks having video issues or something with suspend, as it pretends to hibernate, but suspends instead.


All times are GMT -5. The time now is 12:23 AM.