Fedora + Laptop + Suspend then Hibernate

Recently I discovered that Windows has a pretty cool feature – after sleeping for a while the system will automatically hibernate. This is a pretty nice feature for a laptop, you just close the lid and after a while it will automatically turn off.

Yes it will take longer to boot, but at least your session is saved. I wanted to figure out how to do this on Linux (Fedora), and I was surprised to find out that systemd already supports this.

https://www.freedesktop.org/software/systemd/man/systemd-sleep.conf.html

Per the documentation, I attempted to edit /etc/systemd/sleep.conf. I changed SuspendMode to suspend-then-hibernate however this appeared to break GNOME’s suspend. Closing the laptop lid did nothing, and then in the power setting suspend was completely gone.

I found out that this feature has been kicking around for a while, however its been debated if it should be used or not.

https://lwn.net/Articles/764841

I was just looking for a simple solution, I don’t really want to modify how my distribution handles suspending. Luckily I found a simple solution, using /etc/systemd/system directory to override the default behavior.

sudo ln -s /usr/lib/systemd/system/systemd-suspend-then-hibernate.service /etc/systemd/system/systemd-suspend.service

So the systemd-suspend-then-hibernate service already exists, creating a symlink to /etc/systemd/system/systemd-suspend.service causes the default systemd service to be overridden.

Since nothing was actually edited, I’m only referencing (symlinking) system files, I figure this method should survive an upgrade unless something fundamental changes.

At this point, the only thing changing in /etc/systemd/sleep.conf is HibernateDelaySec= which I set to 30min. All other settings should be left commented out. After testing, it works perfectly.

Note: I found out later that using a swap file requires extra steps, when I did this I was using a swap partition.