How to hibernate with BTRFS SwapFile + LUKS2 + Systemd-Boot + Dracut?

I have been trying to figure out how to solve the question in the title, but it seems each of them have their own issues with hibernation and I have not found any guide that can put them all together. Has anyone managed to do it?

Assuming you have the EndeavourOS “default” btrfs layout with a subvolume named @swap:

  1. Create a 8GB swap file:
sudo btrfs filesystem mkswapfile --size 8g --uuid clear /swap/swapfile
sudo swapon /swap/swapfile
  1. Edit /etc/fstab and add
/dev/mapper/luks-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /swap          btrfs   subvol=/@swap,defaults,compress=no 0 0
/swap/swapfile                            swap           swap    defaults,noatime 0 0

Make sure to use your mapped luks-device! Check with sudo blkid

  1. Take note of the resume offset
sudo btrfs inspect-internal map-swapfile -r /swap/swapfile
  1. Add resume device and offset to /etc/kernel/cmdline
resume=/dev/mapper/luks-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx resume_offset=xxx

You could alternatively use the UUID of your mapped luks device, e. g. resume=UUID=a3d83cc0-84e0-4673-af97-742921cda13f

sudo reinstall-kernels
  1. Add resume hook to dracut. Edit /etc/dracut.conf.d/resume.conf
add_dracutmodules+=" resume "

Edit: @Cubicle7595 reported in post #5 that the following workaround wasn’t needed anymore
You may also need to additionally add the following as a workaround for a recent bug; I don’t know if this has been resolved.

install_items+=" /usr/lib/systemd/system/systemd-hibernate-resume.service "

sudo dracut-rebuild
4 Likes

What about enabling zram as well with it?

https://wiki.archlinux.org/title/Zram

https://wiki.archlinux.org/title/Zswap

zram should be unrelated to this.

1 Like

Thank you so much! I really needed a noob-friendly guide like this <3 It works perfectly.

You may also need to additionally add the following as a workaround for a recent bug; I don’t know if this has been resolved.

I tried it without using it, I don’t know where the bug is/was, but everything seems fine.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.