20 - 04 - 2024

Use suspend-freeze with hibernation instead of suspend-to-ram

In somecases you would like to have suspend working but the system is unable to recover from suspend to ram. From Linux Kernel 3.9 we have a chance to configure the new option called 'suspend-freeze'. It's diffrent suspend mode, it does not turn off the computer but it's better than nothing.

My problem was on openSUSE I couldn't get it working after specified timeout via Power management or dconf. But it seems there is an workaround.

Configure systemd to use suspend-freeze

vi /etc/systemd/sleep.conf
[Sleep]
SuspendMode=freeze

Define idle time after going to suspend

vi /etc/systemd/logind.conf
[Login]
IdleAction=suspend
IdleActionSec=10min

In my environment based on openSuse 13.1 with Cinnamon and GDM it was required to remove pm-suspend binary. Without it the default suspend mode under Cinnamon/Gnome/GDM was suspend-to-ram which is ofcourse broken with my nvidia properiaty modules.

$ rm -f `which pm-suspend` 

Add script for going to hibernate after specified amount of time, under /usr/lib/systemd/system-sleep directory

#!/bin/bash
# Purpose: Auto hibernates after a period of sleep
# Edit the "autohibernate" variable below to set the number of seconds to sleep.
lockfile=/var/run/systemd/rtchibernate.lock
curtime=$(date +%s)
# 30 min
autohibernate=1800

case $1/$2 in
  pre/suspend)
    # Suspending. Record current time, and set a wake up timer.
    echo "Suspending until" `date -d "$autohibernate seconds"`
    echo "$curtime" > $lockfile
    rtcwake -m no -s $autohibernate
    ;;
  post/suspend)
    # Coming out of sleep
    sustime=$(cat $lockfile)
    echo -n "Back from suspend... "
    rm $lockfile
    # Did we wake up due to the rtc timer above?
    if [ $(($curtime - $sustime)) -ge $autohibernate ]
    then
        # Then hibernate
        echo "hibernate"
        /usr/bin/systemctl hibernate
    else
        echo "wake-up"
        # Otherwise cancel the rtc timer and wake up normally.
        rtcwake -m disable
    fi
    ;;
esac

I didn't write the script. The source of it comes from ArchLinux forum: https://bbs.archlinux.org/viewtopic.php?id=161053#4