DEV Community

Le Vuong
Le Vuong

Posted on • Updated on

Ubuntu hibernate

When working on Linux/Ubuntu, have you ever gotten tired of reopening tons of apps and workspaces again and again?

It’s much cooler when you can open your machine with all your apps already running. Ubuntu has a lesser-known feature for this: hibernation.

Let’s try this guide to enable hibernation on your Ubuntu system.

Only 3 steps as below:

  1. Create and enable swap partition (swap file seem not working)

  2. Create Polkit action.

nano /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

# NEW entry since Ubuntu 18:
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

 # NEW entry since Ubuntu 18:
[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes
Enter fullscreen mode Exit fullscreen mode
  1. Create clean up hook

sudo nano /etc/systemd/system/use-10_grub_common.service

[Unit]
Description=Execute the /etc/pm/sleep.d/10_grub_common script after hibernation.
After=hibernate.target

[Service]
Type=oneshot
ExecStart=/etc/pm/sleep.d/10_grub-common thaw

[Install]
WantedBy=hibernate.target
Enter fullscreen mode Exit fullscreen mode

And enable this service: sudo systemctl enable use-10_grub_common

Enjoy using Ubuntu!

Top comments (2)

Collapse
 
josephj11 profile image
Joe

Nice. I haven't tried suspend in years. It used to fail to recover WiFi.
What I do instead is a hybrid approach.
First, I let KDE restore the last session. This used to have lots of bugs and shortcomings, but has gradually gotten better over the years.

After waiting a bit for that to complete, I have an autostart (bash) script that runs. It's table driven and has a list of applications to start if they are not running and then moves them to the desired virtual desktops if they are not already there. All done with xdotool. At some point, I may switch to ydotool if I switch from x11 to Wayland.

It took a long time to develop and debug the script getting past needed delays and application quirks, but it's worth it to me.

Collapse
 
patfinder profile image
Le Vuong

Hi Joe,
Good to know another approach to restore the working space.
Thank you for sharing πŸ‘