Hibernate on Linux
Source: https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Instantaneous_wakeups_from_suspend
To be able to put your PC in hibernate, you will need some things to do: 1. Have a swap the same size or bigger than your RAM. 2. Set the kernel parameters. 3. Configure the initramfs to include the resume hook.
Set the kernel parameters
If you are using a swap file, it is required to set the resume=swap_device
and additionally a resume_offset=swap_file_offset
kernel parameters.
The swap_device
can be identified with the following command:
findmnt -no UUID -T /swapfile
This will give you the UUID of the swap file, and this is what you should be putting in your kernel parameters:
resume=UUID=4209c845-f495-4c43-8a03-5363dd433153
The following command may be used to identify swap_file_offset
:
filefrag -v /swapfile | awk '{ if($1=="0:"){print substr($4, 1, length($4)-2)} }'
Then you put that in the /etc/default/grub
file between the quotes of the GRUB_CMDLINE_LINUX_DEFAULT
line. For example:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=4209c845-f495-4c43-8a03-5363dd433153 resume_offset=4392394"
After that, regenerate the grub.cfg file with:
grub-mkconfig -o /boot/grub/grub.cfg
Configure the initramfs
When an initramfs with the base hook is used, which is the default, the resume hook is required in /etc/mkinitcpio.conf
. Whether by label or by UUID, the swap partition is referred to with a udev device node, so the resume hook must go after the udev hook. This example was made starting from the default hook configuration:
HOOKS=(base udev autodetect keyboard modconf block filesystems resume fsck)
Remember to regenerate the initramfs for these changes to take effect:
mkinitcpio -p linux