Disable secure boot in BIOS
Create swap partition (2x ram size) and mount it in /etc/fstab
UUID=<swap-partition-uuid> none swap defaults 0 0
Create the file /etc/dracut.conf.d/resume.conf
and paste in it:
add_dracutmodules+=" resume "
After we save the file, we must regenerate the existing initramfs. We do it by running the following command:
sudo dracut --regenerate-all --force
To be sure the “resume” module has been added to the initramfs, we can run:
sudo lsinitrd -m
Take a look at the “Modules” section of the output generated by the command. The “resume” module should appear in the list:
========================================================================
Early CPIO image
========================================================================
drwxr-xr-x 3 root root 0 Oct 28 21:55 .
-rw-r--r-- 1 root root 2 Oct 28 21:55 early_cpio
drwxr-xr-x 3 root root 0 Oct 28 21:55 kernel
drwxr-xr-x 3 root root 0 Oct 28 21:55 kernel/x86
drwxr-xr-x 2 root root 0 Oct 28 21:55 kernel/x86/microcode
-rw-r--r-- 1 root root 208896 Oct 28 21:55 kernel/x86/microcode/GenuineIntel.bin
========================================================================
Version: dracut-055-6.fc35
dracut modules:
systemd
systemd-initrd
systemd-sysusers
nss-softokn
dbus-broker
dbus
i18n
network-manager
network
ifcfg
drm
plymouth
crypt
dm
kernel-modules
kernel-modules-extra
kernel-network-modules
lvm
resume
rootfs-block
terminfo
udev-rules
dracut-systemd
usrmount
base
fs-lib
shutdown
========================================================================
The last thing we need to do in order to allow hibernation on our machine, is to add the “resume” parameter to the kernel command line and use a reference to the swap partition as its value. In order to do that we need to modify the /etc/default/grub file and append the following to GRUB_CMDLINE_LINUX:
GRUB_CMDLINE_LINUX="[...] resume=UUID=<swap-partition-uuid>"
If using LVM setup, or LVM on LUKS, we also have to add another parameter to the grub command line if not already present:
GRUB_CMDLINE_LINUX="[...] rd.lvm.lv=<volume_group_name>/<swap_logical_volume_name> resume=UUID=<swap-partition-uuid>"
As reported in the kernel configuration, the rd.lvm.lv directive is used to specify what logical volumes must be activated on early boot. The directive can be specified multiple times, in fact if you are using that kind of setup, you should find the same directive used to activate the logical volume which hosts the root filesystem. After we save the file, we must regenerate the grub configuration, so we run:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Reboot and test:
systemctl hibernate