Ubuntu 18.04 LTS – Hibernate to Swapfile

This is a short summary for the following instruction: https://ubuntuforums.org/showthread.php?t=1042946

Swapfile activation

# create swapfile (XX stands for your RAM size e.g. 32GB + 1GB => XX=33)
sudo dd if=/dev/zero of=/swapfile bs=1G count=XX

# change swapfile permissions
sudo chmod 600 /swapfile

# make this file as swapfile (ignore UUID)
sudo mkswap /swapfile

# disable all current active swaps
sudo swapoff -a

# activate the new swapfile 
sudo swapon /swapfile

# add the new swapfile to the file system table
sudo -b gedit /etc/fstab

# inside fstab: comment out all swap entries and add the following new line:
/swapfile   none   swap   sw   0   0

Hibernate activation

# get partition of the root path
mount | grep " / "

# get UUID of the root partition from above
sudo blkid

# get the UUID of the swapfile
sudo swaplabel /swapfile

# get the "resume_offset"
sudo swap-offset /swapfile

# edit grub
sudo -b nano /etc/default/grub

# set the resume and resume_offset behind "quiet splash"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=xxxx resume_offset=xxxxx"

# activate the new grub configuration
sudo update-grub

# test hibernate
sudo systemctl hibernate