Skip to content

Instantly share code, notes, and snippets.

@krisraich
Last active May 8, 2025 20:30
Show Gist options
  • Save krisraich/b69d9771b5c72e81aeebb3ce5071ce2e to your computer and use it in GitHub Desktop.
Save krisraich/b69d9771b5c72e81aeebb3ce5071ce2e to your computer and use it in GitHub Desktop.
Enable Hibernate on BTRFS and LUKS

Enable Hibernate on BTRFS and LUKS using a Swap file

This is a setup on how to enable Hibernate on an LUKS encrypted Volume using a swap file. Why? Because if you are using an encrypted Swap partition, you'll have to enter your decryption password twice... and that's lame.

Tested on Manjaro.

1. Create Swap subvolume

btrfs subvolume create /swap

check: btrfs subvolume list /

2. Mount Subvolume

mount /dev/mapper/luks-79f8dd77-b3a6-4d9f-803c-0d5b3f2fe621 /swap -o subvol=/@/swap Note: Manjaro uses /@ as BTRFS root, this may vary on your setup

check: mount | grep swap

3. Add to fstab

/dev/mapper/luks-79f8dd77-b3a6-4d9f-803c-0d5b3f2fe621 /swap btrfs subvol=/@/swap,noatime,nodiratime,nodatacow,compress=no 0 0

and

/swap/swapfile swap swap defaults 0 0

4. Make swapfile

fallocate -l 64G /swap/swapfile

chmod 600 /swap/swapfile

5. Enable swap

mkswap /swap/swapfile

swapon /swap/swapfile

check: cat /proc/swaps

6. Update iniframes

in /etc/mkinitcpio.conf append resume on hooks. Note that it must be after dm-crypt and lvm (see: https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Configure_the_initramfs)

execute mkinitcpio -p linux614 afterwards to generate initframes. Note: 614 is the target kernel version and may differ.

7. Retrieve resume offset and swap uuid

resume offset: btrfs inspect-internal map-swapfile -r /swap/swapfile

swap uuid: blkid /swap/swapfile

Note the results.

8. Update grub config

Add GRUB_CMDLINE_LINUX="RESUME=UUID=99856d6e-4b5d-4d25-8404-aae68fd33108 RESUME_OFFSET=194570203" to /etc/default/grub with your own values from step 7 obviously...

Finally execute update-grub

9. Reboot to load config

10. Try it with: sudo systemctl hibernate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment