Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's my problem:

I have a laptop running Arch that I just keep on at home. It's got a good 4 hour battery life, but sometimes my daughter is playing near where it's kept and ends out pulling the plug. Well, when I get home 5 hours later, my laptop had a hard shutdown.

Additionally, sometimes I'll leave it suspended and forget about it for a day or so - same problem.

Here's my proposition:

So my thought was that I could make a cron job that runs every 15 or 30 minutes or something, checking the battery life. If the battery life is < N minutes left, I could just hibernate the laptop. This would work fine if my laptop is in normal 'on'. But if I'm suspended, not so much. So my question is two fold - is there a better way to do this, and if not, is it possible to do some sort of monitoring in suspend mode - basically just run that cron job?

Here's what worked:

Following the uswsusp instructions on the Arch wiki, I installed uswsusp from the AUR. Using the following command:

wayne@jughead:~$ swapon -s
Filename                Type        Size    Used    Priority
/dev/sda2                               partition   530140  56744   -1

I discovered /dev/sda2 was the name of my swap partition. So I set this in my /etc/suspend.conf

snapshot device = /dev/snapshot
resume device = /dev/sda2

I added uresume in my mkinitcpio.conf here:

HOOKS="base udev autodetect pata scsi sata resume uresume filesystems usbinput fsck"

I created /etc/pm/config.d/module and put


in it.

Since my laptop was not recognized (# s2ram --test displayed Machine unknown) I had to use the --force option.

In /usr/lib/pm-utils/module.d/uswsusp I also changed all of the s2ram options to s2both.

share|improve this question
You know rtcwake? This answer could be inspirational. – sr_ Sep 21 '12 at 11:54
See also askubuntu.com/questions/12383/… – derobert Sep 21 '12 at 13:49
Excellent solutions, if s2both doesn't work out! – Wayne Werner Sep 21 '12 at 16:40
up vote 7 down vote accepted

Sounds like you want suspend-to-both/hybrid suspend which should do all the steps of hibernating, including writing RAM to disk, but not actually turn the machine off; instead, it'll go into S3 (standby). If you wake the machine up before the battery dies, it'll be fairly quick; if the battery dies, it'll be just as if you'd hibernated it.

share|improve this answer
That looks highly promising - I'll be checking that out this evening! – Wayne Werner Sep 21 '12 at 16:38
Works perfectly! I set it up and yanked the battery and my session came back online. – Wayne Werner Sep 22 '12 at 13:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.