Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

One of the windows features I miss in linux is the following: In windows you close the notebook lid and the system suspends to RAM, after a while (configurable) the computer automatically wakes up and proceed to suspend to disk. I know that in linux exists suspend2both mode but that works suspending to disk just before running out of battery which is what I'm trying to avoid.

EDIT: More detailed answer found after searching with the answer data

http://askubuntu.com/questions/12383/how-to-go-automatically-from-suspend-into-hibernate

EDIT2: Those are the steps I've followed using Ubuntu 11.04 on a MSI Wind U100.

First: I've installed tuxonice because hibernation wasn't working on my netbook. As a side-effect the hibernation and wake-up processes are quite fast and very stable. The unique drawback is that the display on hibernate/resume is in text-mode. The easiest way to install tuxonice is by adding the corresponding ppa: https://launchpad.net/~tuxonice/+archive/ppa

Once you have hibernation working this script does all the magic

#!/bin/bash
# Script name: /etc/pm/sleep.d/00rtchibernate
# Purpose: Auto hibernates after a period of sleep
# Edit the "autohibernate" variable below to set the number of seconds to sleep.
curtime=$(date +%s)
autohibernate=7200
echo "$curtime $1" >>/tmp/autohibernate.log
if [ "$1" = "suspend" ]
then
    # Suspending.  Record current time, and set a wake up timer.
    echo "$curtime" >/var/run/pm-utils/locks/rtchibernate.lock
    rtcwake -m no -s $autohibernate
fi

if [ "$1" = "resume" ]
then
    # Coming out of sleep
    sustime=$(cat /var/run/pm-utils/locks/rtchibernate.lock)
    rm /var/run/pm-utils/locks/rtchibernate.lock
    # Did we wake up due to the rtc timer above?
    if [ $(($curtime - $sustime)) -ge $autohibernate ]
    then
        # Then hibernate
        rm /var/run/pm-utils/locks/pm-suspend.lock
        /usr/sbin/pm-hibernate
    else
        # Otherwise cancel the rtc timer and wake up normally.
        rtcwake -m no -s 1
    fi
fi

By modifying the autohibernate value you change the sleep time after which the machine will wake-up and go instantly into hibernation

NOTE: You may have to install rtcwake, I had already installed but I can't remember if I've installed the package myself.

share|improve this question
Suspend2Both actually does the hibernation (what you're calling "suspend to disk") immediately, but it doesn't shut down until the battery is very low. – CarlF Jun 17 '11 at 21:00
Throw in an SSD, and then only suspend to disk: problem solved. Not solved cheaply, but solved nonetheless. – Lukasa Jun 17 '11 at 22:17

1 Answer

up vote 4 down vote accepted
+100

I'd guess what you'd want is something like http://www.linuxcertif.com/man/8/rtcwake/ which could be used instead of the default S2R (AKA sleep) program. This could then wake the machine if it has been asleep for more than (say) 20 minutes and trigger a hibernate.

share|improve this answer
I grant you the bounty because you pointed me on the right direction. – DrNoone Jun 28 '11 at 20:31
Thanks. I think you have to click something to award it. – Haqa Jun 29 '11 at 0:45
@DrNoone: you have to click the blue "+100" button next to this answer in order to award the bounty. – Wuffers Jul 3 '11 at 18:21

Your Answer

 
discard

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.