Hibernate after suspend (on Fedora)

I recently found out that Windows has this nice feature where, after suspending your laptop, it’ll go to hibernate after a while to preserve battery. Seems like a really cool feature, saves your battery too, so I wanted it on my linux installation. I’m using Fedora 27 right now.

To get it working, you’ll first need to verify that your suspend to ram and suspend to disk actually work. There are plenty of articles on the web that can guide you through it.

The solution is relatively easy, thanks to the internet ;) I got most of the info here, on the ArchLinux forums / wiki. create the following systemd unit file (in /etc/systemd/system), called suspend-to-hibernate.service. After some testing I ended up with this file:

[Unit]
Description=Delayed hibernation trigger
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279
Documentation=https://wiki.archlinux.org/index.php/Power_management
Conflicts=hibernate.target hybrid-sleep.target
Before=sleep.target
StopWhenUnneeded=true

[Service]
Type=oneshot
RemainAfterExit=yes
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"
Environment="SLEEPLENGTH=+30min"
ExecStart=-/usr/bin/sh -c 'echo -n "alarm set for "; date +%%s -d$SLEEPLENGTH | tee $WAKEALARM'
ExecStop=-/usr/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

Afterwards, enable it through systemctl enable suspend-to-hibernate.service; start it through systemctl start suspend-to-hibernate.service and you should be good to go.

XPS13, Linux, suspend and Intel Rapid Start Technology

As an addendum to my previous post on how to install Debian Sid on the XPS13, I’ve been having issues with suspend – the laptop would sporadicaly not go to sleep properly on lid close, or it wouldn’t come out of suspend afterwards.

I seem to have found a solution for both:

  • The laptop suspends correctly after upgrading the xserver-xorg-video-intel driver to the version available in experimental, and upgrading the kernel to kernel 3.9 rc 6 (which contains a bunch of fixes for Ivy Bridge, and the touchpad driver comes built-in). You’ll need to manually build this kernel as detailed in the Debian Kernel Handbook.
  • The not waking up part seems to have been caused by the Intel Rapid Start Technology (iRST in short), which basically is an (S4) hibernate triggered from the BIOS a short while after you put the laptop in (S3) suspend (you never see this from the OS side). The laptop will dump the memory contents to a special partition on the harddisk and shutdown completely. Very good for battery life, less so for waking up from suspend – sometimes it would be instantaneously, sometimes it would take a minute or two, and at other times it just wouldn’t do anything.
    After disabling this in the BIOS the laptop works as expected.
    (you can find more about iRST and Dell here)