(Using GRUB and systemd.)
A more extensive explanation can be found on the ArchWiki.
Requirements
In order to use hibernation, a swap partition or swap file has to be created. Then a special parameter has to be passed to the linux kernel. Lastly, initramfs has to be configured, so that the system can resume from hibernation.
Kernel parameters
The resume=swap_uuid
parameter has to be passed to the kernel. Get the UUID of the swap partition with the following command:
lsblk -f
Copy the UUID of the partition which has the FSTYPE of swap. After that, open /etc/default/grub
with a text editor and locate the following line:
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet"
This line is where parameters are passed to the kernel. Add the resume
option, using the previously obtained UUID. The correct syntax looks like this:
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet resume=UUID=51bce307-d233-4abd-a3e4-50fb56010bff"
To apply the changes, regenerate the GRUB config file:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Modify the initramfs
Open /etc/mkinitcpio.conf
with a text editor and locate the following line:
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)
The resume
hook has to be added to this array, somewhere after udev, so the line will be:
HOOKS=(base udev autodetect modconf block filesystems keyboard resume fsck)
To apply the changes, regenerate the initramfs presets:
sudo mkinitcpio -P
Using hibernation
Reboot for the changes to take effect, then use the following command to hibernate the system:
systemctl hibernate