Skip to content

Instantly share code, notes, and snippets.

@yougg
Last active December 16, 2020 04:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yougg/bac70664f8cbf85a5e0b84665cb18ddf to your computer and use it in GitHub Desktop.
Save yougg/bac70664f8cbf85a5e0b84665cb18ddf to your computer and use it in GitHub Desktop.
Ubuntu 19.04 enable hibernate

Enable hibernate with swapfile on Ubuntu 19.04

Install hibernate and other dependencies which are needed to hibernate

sudo apt install hibernate

Create the swap file

sudo swapoff /swapfile
#sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrun
sudo fallocate -l $(sudo dmidecode -t 17 | awk '/Size.*MB/{s+=$2}END{print s"M"}') /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# add this line to /etc/fstab (if it was not exsit)
 echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab

Configure grub to resume from the swapfile by editing /etc/default/grub and modify the following line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=abcdefgh-1234-5678-ijkl-mnopqrst90uv resume_offset=34816"

Get your own UUID and offset by following commands

sudo findmnt -no SOURCE,UUID -T /swapfile | awk '{print $2}'
sudo swap-offset /swapfile | awk '{print $4}'

Add line to /etc/initramfs-tools/conf.d/resume

RESUME=UUID=abcdefgh-1234-5678-ijkl-mnopqrst90uv resume_offset=34816

Update grub and initramfs

sudo update-grub
sudo update-initramfs -u -k all

Enable hibernate in Menus

sudo mkdir -p /etc/polkit-1/localauthority/50-local.d/
echo '[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[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' > /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

Hibernate with command

sudo systemctl hibernate

After computer restarted, click the link to install the gnome extension: Hibernate Status Button.

https://extensions.gnome.org/extension/755/hibernate-status-button/

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