Hibernate Zorin
I’ve been using Zorin 16 since around August 2021 on an external SSD. But, out-of-the-box Zorin does not support hibernation. As a result, I have to restart my work environment on every restart.
My daily driver is Windows 10, so hibernation is something I use often, especially when I switch to my Zorin installation. Would Linux support hibernation?
Enabling hibernation
I’m happy to find hibernation is indeed supported and can be installed later.
This answer on AskUbuntu.com tells how for Ubuntu 20.04. As Zorin 16 is based on
Ubuntu 20.04, this also works for Zorin.
These instructions switch from a swap partition to a swapfile, adjusts the size if needed and configures Grub to enable starting using hibernation.
Increase swapfile
size to match RAM size up to 16GB
First check if swapping is in use and whether it is a partition or file
sudo swapon -s
Switch it off swapping
sudo swapoff -a
Disable the partition by editing fstab
sudo nano -Bw /etc/fstab
and adding #
before the UUID
of the swap partition
# UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX none swap sw 0 0
Add a line for the swapfile
, if a partition was used
/swapfile none swap sw 0 0
Create or update the swapfile
sudo fallocate -l XG /swapfile
where X
is swapfile
’s size in GB.
Create the swapfile
it does not yet exist, make sure the file permissions are correct and enable swapping
sudo mkswap /swapfile
sudo chmod 0600 /swapfile
sudo swapon /swapfile
Reboot the machine
sudo reboot
Add the resume
location and offset to grub.cfg
to enable resuming from hibernation by editing /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=<drive UUID> resume_offset=<swapfile offset>"
Get the UUID
from the root drive using
$ blkid
/dev/sdb2: UUID="<drive UUID>" TYPE="ext4" PARTUUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
and the swapfile using
$ sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}'
34816..
where <swapfile offset>
in this case is 34816.
Next, update the Grub configuration
sudo update-grub
Test hibernation using
sudo systemctl hibernate
When adding this command to the sudoers file, you can remove the need for a password and make it easier to use
sudo visudo
and add to the end
username ALL=(ALL:ALL) NOPASSWD: /bin/systemctl hibernate
Finally, adding an alias makes it even easier to use. Add to ~/.bashrc
alias hibernate='sudo /bin/systemctl hibernate'
Conclusion
With these steps, switching between my Windows and Zorin environment is made as easy as possible.
January 6, 2022