You are not logged in.

#1 2013-04-07 14:05:49

cjlano
Member
From: France
Registered: 2013-04-07
Posts: 7

[solved] Suspend to RAM and later to disk

Hello,

I am a new laptop owner (and new Archlinux user).
On its original operating system, my laptop has a feature which basically does:
1- suspend to RAM
2- after 1 hour in this suspend mode, it wakes up briefly and suspend to disk

I found many wiki pages about suspending either to disk or to RAM or even both, like https://wiki.archlinux.org/index.php/Su … _Hibernate and that works fine with my laptop.
But none gave me a solution with this kind of behavior.

Note that this is different from "hybrid-sleep" which suspend to RAM and disk at the same time and use disk save in case the battery if emptied.

I see many benefits from what I look for:
- very fast suspend (on lid close for instance);
- if I re-open the lid within the hour, very quick restore;
- if I let the laptop as it is, I know it will automatically suspend to disk and thus I do not worry about battery usage;
- compared to hybrid-sleep, if I forget my laptop in sleep mode, the battery state will be about the same as when I stopped working, whereas hybrid-sleep needs a recharge.

So, do you know if it is possible to suspend to RAM and later to disk on Archlinux?
Any pointers on how to do so?

Thanks!

Last edited by cjlano (2013-04-08 20:53:38)

Offline

#2 2013-04-07 15:09:41

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: [solved] Suspend to RAM and later to disk

Recently https://bbs.archlinux.org/viewtopic.php?id=160895 was posted - it links to a pm-utils script.

Last edited by lucke (2013-04-08 21:28:14)

Offline

#3 2013-04-07 16:32:32

cjlano
Member
From: France
Registered: 2013-04-07
Posts: 7

Re: [solved] Suspend to RAM and later to disk

Thanks for the link, I did not see it.
However, no answers for him yet about a systemd way to deal with "suspend sedation".

Does anybody made a systemd "script" to make that very function?

Offline

#4 2013-04-08 20:52:10

cjlano
Member
From: France
Registered: 2013-04-07
Posts: 7

Re: [solved] Suspend to RAM and later to disk

Hello,

Here is my solution for a Archlinux / systemd "suspend sedation" based on http://askubuntu.com/questions/12383/ho … -hibernate

The following script is a Systemd sleep hook. It uses a RTC wake up event (rtcwake) to get out of suspend state and go to hibernate state. If the system leaves suspend state before the RTC event, the RTC wake is cancelled.

Save the following code in /usr/lib/systemd/system-sleep/suspend-sedation.sh, and make it executable.

#!/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

This script outputs some log you can view using

journalctl -b -u systemd-suspend

Any improvements welcome!

Offline

#5 2013-07-25 22:01:28

mr_hangman
Member
Registered: 2010-08-13
Posts: 2

Re: [solved] Suspend to RAM and later to disk

Thanks, cjlano! The script works really great!

Offline

#6 2014-01-27 06:24:33

miktore
Member
Registered: 2014-01-26
Posts: 16

Re: [solved] Suspend to RAM and later to disk

I copied the script and made it executable but it is not working, should I add it as a service at startup or what?

Offline

#7 2014-05-29 06:44:18

frantom
Member
Registered: 2014-05-29
Posts: 1

Re: [solved] Suspend to RAM and later to disk

For anyone else following along, I did the same thing, but in a systemd unit, and without rtcwake:

[Unit]
Description=delayed hibernation trigger
Before=suspend.target
StopWhenUnneeded=true

[Service]
Type=oneshot
RemainAfterExit=yes
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"
ExecStart=-/bin/sh -c 'echo -n "alarm set for "; date +%%s -d+1hour | tee $WAKEALARM'
ExecStop=-/bin/sh -c '\
  alarm=$(cat $WAKEALARM); \
  now=$(date +%%s); \
  if [ -z "$alarm" ] || [ "$now" -ge "$alarm" ]; then \
     echo "hibernate triggered"; \
     systemctl hibernate; \
  else \
     echo "normal wakeup"; \
  fi; \
  echo 0 > $WAKEALARM; \
'

[Install]
WantedBy=sleep.target

Drop that into '/etc/systemd/system/suspend-to-hibernate.service' and then 'systemctl enable suspend-to-hibernate'.

It's been working well for me.

Offline

#8 2015-05-02 03:53:50

e12e
Member
Registered: 2015-05-02
Posts: 2

Re: [solved] Suspend to RAM and later to disk

I had some issues with getting this to work without rtcwake, probably beacuse my system dualboots windows (and Debian Jessie) - and so the real-time clock isn't in UTC. I documented a solution that works for me, here: https://wiki.debian.org/SystemdSuspendSedation.

Offline

#9 2015-05-02 13:49:06

ijanos
Member
From: Budapest, Hungary
Registered: 2008-03-30
Posts: 443

Re: [solved] Suspend to RAM and later to disk

Hi!

First of all this is a necrobump but no one posted the right answer to the original question, so here it is, maybe someone will find it useful after stumbling on this thread.

What cjlano was interested in is called Intel Rapid Start and this is how you enable it on Linux:

http://mjg59.dreamwidth.org/26022.html

Offline

#10 2015-05-03 03:25:53

e12e
Member
Registered: 2015-05-02
Posts: 2

Re: [solved] Suspend to RAM and later to disk

Thank you for the link to Rapid Start. As pointed out in that link, it doesn't work (in a sane/safe) way with full disk encryption. While the drive is "at risk" for as long as the laptop is in "suspend", and for a while after (cold boot attack) with either solution -- after having been powered off for a while with classic hibernation (assuming swap is on an encrypted volume, like lvm on top of luks) -- the solution with systemd is better.

I really do appreciate the link - but personally I consider not using full disk encryption to be deprecated. It can be convenient on servers, but as personal computers of all sizes increasingly have SSDs, which (depending on internal details) can be hard or impossible to erase with confidence -- not using encryption simply isn't a very sound idea.

Offline

#11 2015-10-30 16:30:15

aweb
Member
Registered: 2010-12-18
Posts: 25

Re: [solved] Suspend to RAM and later to disk

I'd been using the rtcwake technique for a while, but in October 2015, after updating my system, it stopped working.  My other scripts in /usr/lib/systemd/system-sleep run fine, so I'm wondering if something changed with rtcwake.  If anyone has made this approach work with an up-to-date version of arch, please share what you had to do.  Thanks.

Offline

#12 2015-11-05 19:26:24

Henry78
Member
From: Vienna
Registered: 2012-01-23
Posts: 65

Re: [solved] Suspend to RAM and later to disk

The rctwake version (the version from the wiki) workes fine for me on an up to date arch.

Nov 04 23:20:56 hostname systemd[1]: Starting Delayed hibernation trigger...
Nov 04 23:20:56 hostname systemd[1]: Reached target Sleep.
Nov 04 23:20:56 hostname systemd[1]: Starting Suspend...
Nov 04 23:20:56 hostname sh[4429]: alarm set for 1446677456
Nov 04 23:20:56 hostname systemd[1]: Started Delayed hibernation trigger.
Nov 04 23:20:56 hostname systemd-sleep[4430]: rmmod: ERROR: Module i915 is in use
Nov 04 23:20:56 hostname systemd-sleep[4431]: /usr/lib/systemd/system-sleep/suspend-modules failed with error code 1.
Nov 04 23:20:56 hostname systemd-sleep[4430]: Suspending until Mit Nov 4 23:50:56 CET 2015
Nov 04 23:20:56 hostname systemd-sleep[4430]: rtcwake: assuming RTC uses UTC ...
Nov 04 23:20:56 hostname systemd-sleep[4430]: rtcwake: wakeup using /dev/rtc0 at Wed Nov  4 22:50:58 2015
Nov 04 23:20:56 hostname systemd-sleep[4430]: Suspending system...

Offline

#13 2015-11-21 14:40:45

Kabbone
Member
Registered: 2009-02-06
Posts: 32

Re: [solved] Suspend to RAM and later to disk

I have another problem with the script. It seems it executes right, but after the wakeup it doesn't hibernate due to a already running sleep operation.

# systemctl status -l suspend-to-hibernate.service
Nov 21 12:38:19 kabbonenote systemd[1]: Starting Delayed hibernation trigger...
Nov 21 12:38:19 kabbonenote sh[1279]: alarm set for 1448106019
Nov 21 12:38:19 kabbonenote systemd[1]: Started Delayed hibernation trigger.
Nov 21 12:40:19 kabbonenote systemd[1]: suspend-to-hibernate.service: Unit not needed anymore. Stopping.
Nov 21 12:40:19 kabbonenote systemd[1]: Stopping Delayed hibernation trigger...
Nov 21 12:40:19 kabbonenote sh[1390]: hibernate triggered
Nov 21 12:40:29 kabbonenote sh[1390]: Failed to hibernate system via logind: There's already a shutdown or sleep operation in progress
Nov 21 12:40:29 kabbonenote systemd[1]: Stopped Delayed hibernation trigger.

Any ideas?

EDIT: I already tried a 10 sec sleep before the execution of hibernate, but also didn't work.

Last edited by Kabbone (2015-11-21 14:42:22)

Offline

#14 2015-12-05 17:54:38

nOrNIc
Member
Registered: 2015-12-05
Posts: 1

Re: [solved] Suspend to RAM and later to disk

Kabbone wrote:

I have another problem with the script. It seems it executes right, but after the wakeup it doesn't hibernate due to a already running sleep operation.

# systemctl status -l suspend-to-hibernate.service
Nov 21 12:38:19 kabbonenote systemd[1]: Starting Delayed hibernation trigger...
Nov 21 12:38:19 kabbonenote sh[1279]: alarm set for 1448106019
Nov 21 12:38:19 kabbonenote systemd[1]: Started Delayed hibernation trigger.
Nov 21 12:40:19 kabbonenote systemd[1]: suspend-to-hibernate.service: Unit not needed anymore. Stopping.
Nov 21 12:40:19 kabbonenote systemd[1]: Stopping Delayed hibernation trigger...
Nov 21 12:40:19 kabbonenote sh[1390]: hibernate triggered
Nov 21 12:40:29 kabbonenote sh[1390]: Failed to hibernate system via logind: There's already a shutdown or sleep operation in progress
Nov 21 12:40:29 kabbonenote systemd[1]: Stopped Delayed hibernation trigger.

Any ideas?

EDIT: I already tried a 10 sec sleep before the execution of hibernate, but also didn't work.

The problem you mentioned had been introduced in Systemd 227 (still broken in 228).

As this topic comes quite high on google, I thought I post the answers here.

Arch wiki been updated:  https://bbs.archlinux.org/viewtopic.php?id=204346

Full description and solution is here: https://bbs.archlinux.org/viewtopic.php?id=204346

TL;DR for those busy people out there:

# cp -p /usr/lib/systemd/system/suspend.target /etc/systemd/system/
# echo 'Requires=suspend-to-hibernate.service' >> /etc/systemd/system/suspend.target
# systemctl daemon-reload

be sure you use the latest suspend-to-hibernate.service from wiki. The one with:

Conflicts=hibernate.target hybrid-suspend.target

Offline

#15 2015-12-06 19:00:06

Kabbone
Member
Registered: 2009-02-06
Posts: 32

Re: [solved] Suspend to RAM and later to disk

Thanks, it worked smile. Actually I saw the other thread and I don't know why I haven't tried it :-/

Offline

#16 2016-02-18 20:16:52

bocki
Member
Registered: 2013-05-15
Posts: 7

Re: [solved] Suspend to RAM and later to disk

for anyone wondering (and since this thread is given as the 'official' url for this service): systemd 229 which has been in [core] since yesterday breaks the unit, because the '%%' specifier is currently broken. the issue has been fixed upstream and will likely be in the next release. in the meanwhile, downgrading seems to be the only workaround (putting this into a separate script might work as well?).

Offline

#17 2016-02-29 11:39:17

NME
Member
Registered: 2004-10-13
Posts: 25

Re: [solved] Suspend to RAM and later to disk

bocki wrote:

for anyone wondering (and since this thread is given as the 'official' url for this service): systemd 229 which has been in [core] since yesterday breaks the unit, because the '%%' specifier is currently broken. the issue has been fixed upstream and will likely be in the next release. in the meanwhile, downgrading seems to be the only workaround (putting this into a separate script might work as well?).

Thank you so much for this. I've been pulling my hair out trying to fix hibernation on my laptop.

Seems like every update to systemd introduces new quirks to my system. Almost brings out the debian-user in me.

Offline

#18 2016-04-20 13:06:10

wast3
Member
Registered: 2012-01-26
Posts: 28
Website

Re: [solved] Suspend to RAM and later to disk

Hi,

is this still an issue with the current systemd (229-3)? Should I keep ignoring the update until 230?


Thanks

Offline

#19 2016-05-17 05:53:51

wast3
Member
Registered: 2012-01-26
Posts: 28
Website

Re: [solved] Suspend to RAM and later to disk

wast3 wrote:

Hi,

is this still an issue with the current systemd (229-3)? Should I keep ignoring the update until 230?


Thanks

I answer myself. The script seems to be working again with systemd-229-3

Offline

Board footer

Powered by FluxBB