I had already posted about enabling hibernation in Linux, particularly in Ubuntu.
Thanks to the script hibernator, the procedure is much more straightforward in Arch-based distros (including Manjaro and EndeavourOS).
First of all, make sure you first install the package update-grub.
The package hibernator is available from AUR, but currently, there’s a problem with the build instructions. Thus, we must install it manually. There’s no need to install the script anywhere: it’s just a matter of cloning the script from GitHub and running it once:
1 2 3 |
git clone https://github.com/Chrysostomus/hibernator.git cd hibernator chmod +x hibernator |
Then, before running the script (as a superuser), we must decide where we want the suspend-to-disk to take place: either in a swap partition or in a swap file (please keep in mind that currently, the script cannot handle hibernation into a swap file of a BTRFS partition).
If we want a swap file, the script can create that for us, and we can also specify the size of the swap file. Here’s the quote from the home page of the project
Hibernator accepts desired size of swapfile as arguments. Running hibernator 2G creates 2 Gb swapfil, hibernator 1000M creates 1000 Mb swapfile. The script defaults to 4G if no arguments are given.
If we want a swap partition, we must ensure the partition is already in place and that our /etc/fstab already refers to that (i.e., it mounts it appropriately).
When we’re ready, we just run the script with sudo. The script will update the GRUB command line with the resume option and a resume hook to /etc/mkinitcpio.conf. Finally, it will update the GRUB configuration (with update-grub, that is why you need to install this package beforehand).
Here’s an example of the output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
> sudo ./hibernator Adding the necessary kernel parameters to your bootloaders Generating grub configuration file ... Found linux image: /boot/vmlinuz-linux Found initrd image: /boot/intel-ucode.img /boot/initramfs-linux.img Found fallback initrd image(s) in /boot: intel-ucode.img initramfs-linux-fallback.img Adding boot menu entry for UEFI Firmware Settings ... done Adding resume hook to /etc/mkinitcpio.conf ==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default' -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img ==> Starting build: 5.18.0-arch1-1 -> Running build hook: [base] ... -> Running build hook: [fsck] ==> Generating module dependencies ==> Creating zstd-compressed initcpio image: /boot/initramfs-linux.img ==> Image generation successful ==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'fallback' -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-fallback.img -S autodetect ==> Starting build: 5.18.0-arch1-1 ... ==> Generating module dependencies ==> Creating zstd-compressed initcpio image: /boot/initramfs-linux-fallback.img ==> Image generation successful |
And that’s all: we just reboot, and hibernation is ready to be used!
Before rebooting, you might want to check that the GRUB_CMDLINE_LINUX_DEFAULT variable in /etc/default/grub has been set with a valid resume entry (if you rely on a swap partition, which has been properly specified in /etc/fstab, it should contain a reference to the UUID of the swap partition):
1 |
GRUB_CMDLINE_LINUX_DEFAULT="... resume=/dev/disk/by-uuid/<UUID of your swap partition>" |
You can test that, as usual, with
1 |
sudo systemctl hibernate |
You may also want to refer to the older post enabling hibernation in Linux, particularly in Ubuntu, for other mechanisms related to hibernation, like suspend and then hibernate.
Pingback: Enabling Hibernation in EndeavourOS (with dracut) | Lorenzo Bettini