Skip to content

Instantly share code, notes, and snippets.

@smoser
Last active March 11, 2024 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoser/287bccb755944a24cae4e57ad9ced5aa to your computer and use it in GitHub Desktop.
Save smoser/287bccb755944a24cae4e57ad9ced5aa to your computer and use it in GitHub Desktop.
suspend-then-hibernate and ubuntu 22.04

suspend-then-hibernate on Ubuntu 22.04

Recently I have had the opportunity/necessity to use Windows for a bit. Windows, expecially with WSL (Windows Subsystem for Linux) is much better than it used to be. One thing that I really liked was "susped to hibernate".

When closing the lid on the laptop, the system would suspend, and then after some time it would power off. This is really nice behavior for someone who often comes to find a laptop they've suspended a couple days ago and that they have no power.

So... How to do that on linux? Specifically Ubuntu 22.04

Ubuntu 22.04 suspend-then-hibernate

To suspend-then-hibernate, there are 2 sticking points

  1. Configuration of hibernate. There is good documentation on Arch wiki that is also relevant to Ubuntu. There is also an askubuntu post here that shows how to configure hibernation.

  2. No secure-boot - At least on Ubuntu, you cannot hibernate while booted into secure-boot. This is unfortunate.

  3. Configuration of suspend-then-hibernate on Lid close. I want this to work when I close the lid. I don't want to have to type 'sudo systemctl suspend-to-hibernate'. Unfortunately, I have not gotten this part to work yet. I'm not sure if gnome is causing issue here or not. You should be able to:

    • edit /etc/systemd/logind.conf link
    • sudo systemctl kill --signal=HUP systemd-logind

Also you can tweak how long that waits before Hibernate by editing the HibernateDelaySec setting in /etc/systemd/sleep.conf. [doc].

@jllaneras
Copy link

jllaneras commented Mar 10, 2024

Hi Scott! What I did to configure suspend-then-hibernate when closing the laptop lid is to replace the suspend service by the suspend-then-hibernate one as follows:

cd /usr/lib/systemd/system
sudo mv systemd-suspend.service systemd-suspend.service.backup
sudo ln -s /usr/lib/systemd/system/systemd-suspend-then-hibernate.service systemd-suspend.service

Since by default Ubuntu 22.04 suspends when closing the lid, now it suspends-then-hibernates. It's a bit of a hack but it's good enough for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment