DEV Community

Le Vuong
Le Vuong

Posted on

Ubuntu hibernate

When working on Linux/Ubuntu, have you ever gotten tired of reopening tons of apps and workspaces again and again when you bring your laptop somewhere, especially when the battery runs out?

It’s much cooler when you can open your machine with all your apps already running.

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 (0)