sudo apt install hibernate
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
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
sudo systemctl hibernate
https://extensions.gnome.org/extension/755/hibernate-status-button/