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:

Description=Delayed hibernation trigger
Conflicts=hibernate.target hybrid-sleep.target

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; \


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.

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.