How to enable hibernation in EndeavourOS+BTRFS+swapfile
First, we need to make sure that the swap file is at least of the size of the ram.
|
|
|
|
Ok, so it is larger than the memory. If it is not, then we need to recreate the swap file with a larger size. To do that, first stop and remove the existing swapfile (is this case, the default location of swapfile is in /swap/swapfile
).
|
|
Then we create a new swapfile. Usually it can be done with the dd
command, but btrfs has a special command already for this.
|
|
Now we should be a swapfile that is larger than our memory.
Next, we need to enable the resume hook for our initramfs generator. The most common generator is mkinitcpio. In that case, we can add resume
in /etc/mkinitcpio.conf
like below:
|
|
But endeavourOS has switched to Dracut. In this case, we edit the file /etc/ostree-mkinitcpio.conf
and add the resume
flag like below:
|
|
Then we rebuild the initramfs with sudo dracut-rebuild
.
Next we grab two important variables about the swapfile in btrfs filesystem. The first one is the UUID of the swapfile:
|
|
Then we get the offset of the swapfile. For non-btrfs partitions, it can be obtained with findmnt as well, but for btrfs, it does not work. For btrfs, we need to obtain the offset by:
|
|
After getting these two information, we need to add these to /etc/default/grub
in the GRUB_CMDLINE_LINUX_DEFAULT
variable like below:
|
|
Then create the grub configs by running sudo grub-mkconfig -o /boot/grub/grub.cfg
.
Finally reboot the system. Now test if hibernation works by running sudo systemctl hibernate
. This will turn your computer off. Then upon starting, this will boot straight to the last session you were.