Hibernation not working, need help

I want to use hibernation with a LUKS encrypted main partition. Problem is, the machine state is not saved. After selecting “Hibernation” in the logout screen, the disk light shows much activity, then the machine is off. After pressing the power button LUKS asks for its passphrase, but then the GRUB boot happens and the saved state has not been restored.

I had run (in several solving attempts) hibernator, then mkinitcpio -P and update-grub, each time successfully.

Early on in the search for a solution I observed a brief “ERROR: resume: hibernation device 'y' not found” message and checked UUIDs, offset, and hooks.

The setup is a laptop with up-to-date Manjaro stable, kernel 5.10.34-1, KDE Plasma 5.21.4. The LUKS partition holds a btrfs with several subvolumes, swap is on /swap/swapfile.

Here are the (edited) backgrund data – I’m banging my head but can’t see what I’m doing wrong.

Details:
# ⬤  lsblk -f
NAME           FSTYPE      FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda                                                                                        
├─sda1         vfat        FAT32       1111-1111                             510,3M     0% /boot/efi
└─sda2         crypto_LUKS 1           22222222-2222-2222-2222-222222222222
  └─crypt_sda2 btrfs                   33333333-3333-3333-3333-333333333333  894,6G     4% /run/timeshift/backup
sr0                                                                                        

# ⬤  df
Filesystem              Size    Used Avail  Use% Mounted on
dev                     3,9G       0  3,9G    0% /dev
run                     3,9G    1,5M  3,9G    1% /run
/dev/mapper/crypt_sda2  932G     34G  895G    4% /
tmpfs                   3,9G    128K  3,9G    1% /dev/shm
tmpfs                   4,0M       0  4,0M    0% /sys/fs/cgroup
/dev/sda1               511M    720K  511M    1% /boot/efi
/dev/mapper/crypt_sda2  932G     34G  895G    4% /var/cache
/dev/mapper/crypt_sda2  932G     34G  895G    4% /home
/dev/mapper/crypt_sda2  932G     34G  895G    4% /swap
tmpfs                   3,9G     51M  3,8G    2% /tmp
tmpfs                   784M    148K  784M    1% /run/user/1000
/dev/mapper/crypt_sda2  932G     34G  895G    4% /run/timeshift/backup

# ⬤  /etc/fstab:
# /dev/sda1
UUID=1111-1111                             /boot/efi   vfat  rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro    0 0

# /dev/mapper/crypt_sda2
UUID=33333333-3333-3333-3333-333333333333  /           btrfs  rw,noatime,compress=zstd:3,ssd,space_cache,commit=120,subvol=@       0 0

# /dev/mapper/crypt_sda2
UUID=33333333-3333-3333-3333-333333333333  /home       btrfs  rw,noatime,compress=zstd:3,ssd,space_cache,commit=120,subvol=@home   0 0

# /dev/mapper/crypt_sda2
UUID=33333333-3333-3333-3333-333333333333  /var/cache  btrfs  rw,noatime,compress=zstd:3,ssd,space_cache,commit=120,subvol=@cache  0 0

# subvol @swap is mounted in /swap and used for swapfile
UUID=33333333-3333-3333-3333-333333333333  /swap       btrfs  subvol=@swap,compress=no                                             0 0
/swap/swapfile                             none        swap   defaults                                                             0 0

# ⬤  etc/crypttab:
# ... snipped ...
# <name>       <device>                                     <password>              <options>
# home         UUID=44444444-4444-4444-4444-444444444444    /etc/mypassword1
# data1        /dev/sda3                                    /etc/mypassword2
# data2        /dev/sda5                                    /etc/cryptfs.key
# swap         /dev/sdx4                                    /dev/urandom            swap,cipher=aes-cbc-essiv:sha256,size=256
# vol          /dev/sdb7                                    none

# ⬤  findmnt -no UUID -T /swap/swapfile
33333333-3333-3333-3333-333333333333

# ⬤  filefrag -v /swap/swapfile | awk '{ if(==0:){print substr(, 1, length()-2)} }'
1234567

# ⬤  /etc/default/grub | grep CMDLINE:
GRUB_CMDLINE_LINUX_DEFAULT="quiet udev.log_priority=3 resume=/dev/disk/by-uuid/33333333-3333-3333-3333-333333333333 resume_offset=1234567 resume= resume= resume= resume="   # I guess hibernator kept adding "resume=" -??
GRUB_CMDLINE_LINUX="cryptdevice=UUID=22222222-2222-2222-2222-222222222222:crypt_sda2"

# ⬤  /etc/mkinitcpio.conf | grep -v ^#MODULES=()
BINARIES=()
FILES=(/crypto_keyfile.bin)
HOOKS=(base udev autodetect keymap modconf block encrypt filesystems keyboard resume)

# ⬤  mkinitcpio -P | grep '^==>.*'
==> Building image from preset: /etc/mkinitcpio.d/linux510.preset: 'default'
==> Starting build: 5.10.34-1-MANJARO
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-5.10-x86_64.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux510.preset: 'fallback'
==> Starting build: 5.10.34-1-MANJARO
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-5.10-x86_64-fallback.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux54.preset: 'default'
==> Starting build: 5.4.116-1-MANJARO
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-5.4-x86_64.img
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux54.preset: 'fallback'
==> Starting build: 5.4.116-1-MANJARO
==> Generating module dependencies
==> Creating gzip-compressed initcpio image: /boot/initramfs-5.4-x86_64-fallback.img
==> Image generation successful

# ⬤  update-grub 2>&1 | grep -v '^Found snapshot'
Generating grub configuration file ...
Found theme: /boot/grub/themes/poly-light/theme.txt
Found linux image: /boot/vmlinuz-5.10-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-5.10-x86_64.img
Found initrd fallback image: /boot/initramfs-5.10-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.4-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-5.4-x86_64.img
Found initrd fallback image: /boot/initramfs-5.4-x86_64-fallback.img
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
Detecting snapshots ...
Info: Separate boot partition not detected 
Found 20 snapshot(s)
Found memtest86+ image: /boot/memtest86+/memtest.bin
done

There’s your problem. You’re using a swap file which is located on an encrypted filesystem, so how would the kernel be able to restore the machine state when it first needs to decrypt the filesystem that your swap file is on?

Also ─ not that I think it matters in this particular situation, but it does matter with regard to the validity of your swap file ─ a swap file on btrfs must have both copy-on-write and compression disabled.

1 Like

:bulb: Ahhhhhhhhhhhhh! :bulb:

I guess I held an unaware assumption that there was something doing the decryption first, like the decryption that GRUB does on boot. :blush:

This has been driving me crazy. Thank you so much! Also for the swap/btrfs advice.

I’m not sure if btrfs is special this way, I have never used it, but:
the “hibernator” script should take care of finding the file offset (the location of the swap file) and will add it to /etc/default/grub

I have used the hibernator script and found that it alters /etc/default/grub each time it is run - appending to the GRUB_CMDLINE_LINUX line instead of leaving it alone the second time it is run.
Basically: if you run it multiple times it creates a mess

You should probably check the contents of /etc/default/grub whether it contains “resume” and “resume_offset” - and only once.
Also make sure that /etc/mkinitcpio.conf contains the resume HOOK.

to note:
I do run an encrypted system (except /boot) with ext4 filesystem
hibernation etc. is working just fine with the swapfile on the encrypted partition
of course one needs to provide the password when resuming …

1 Like

Actually it does work. The filesystem gets decrypted and then the session gets restored. All you need to do is provide UUID of the LUKS mapper instead of physical partition. I can use hibernation on a fully encrypted drive with a swapfile (ext4, not btrfs though).

As far as I know, hibernator can’t handle swapfiles on btrfs. It’s a bit more tricky:
https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file_on_Btrfs

2 Likes

I’ve cleaned it up. Thanks for the heads-up about hibernator.

At least in principle. :slight_smile: Found an explanation of the process (scroll down to ~8/9th of the page). I need to read more into this.

Solved.
In etc/default/grub the line GRUB_CMDLINE_LINUX_DEFAULT=… must contain the identifier as a device, not as a UUID. Even if that device has that UUID.

With the data from my OP:
I replaced
resume=/dev/disk/by-uuid/33333333-3333-3333-3333-333333333333
with
resume=/dev/mapper/crypt_sda2 and it works. :slight_smile:

Probably (?) because the UUID of /dev/mapper/crypt_sda2 (from blkid) points to all btrfs subvolumes (in fstab), and even if /swap would be correctly identified, the physical offset could be incorrect.

An equally lucky sunday to all you folks!
Thanks for the readiness to help!

1 Like

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