Hibernation on LUKS with keyfile does not resume

I’m struggling to get hibernation working. My system is LUKS-encrypted and with the help of SDB:Encrypted root file system - openSUSE Wiki the partitions are decrypted fine with the key file. But resuming from hibernation does not work, no matter what I tried so far.
The swap partition is decrypted on boot just fine (SWAP is available afterwards)

# lsblk -o +uuid | grep -iE 'n1p3|swap'
└─nvme0n1p3 259:3    0  15.5G  0 part                               0a77e4b4-ecfe-495f-b66b-2554bcd320f8
  └─cr_swap 254:1    0  15.5G  0 crypt [SWAP]                       8589e972-0658-4809-9814-c5e188534da9
# grep resume /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="splash=silent resume=UUID=8589e972-0658-4809-9814-c5e188534da9 quiet randomize_kstack_offset=off mitigations=auto ibt=off"
# cat /etc/crypttab 
cr_root  UUID=767692ec-d630-4b20-8377-01f5605076bf /.root.key
cr_swap  UUID=0a77e4b4-ecfe-495f-b66b-2554bcd320f8 /.root.key
# cat /etc/dracut.conf.d/99-swap-partition.conf 
add_device+=" UUID=0a77e4b4-ecfe-495f-b66b-2554bcd320f8 "
# grep swap /etc/fstab 
UUID=8589e972-0658-4809-9814-c5e188534da9  swap                    swap   defaults                      0  0

In the journal of the previous boot, when hibernating, I see:

[...]
Jul 02 09:36:52 local systemd[1]: Reached target Sleep.
Jul 02 09:36:52 local dns-dnsmasq.sh[5235]: <debug> NETWORKMANAGER_DNS_FORWARDER is not set to "dnsmasq" in /etc/sysconfig/network/config -> exit
Jul 02 09:36:52 local systemd[1]: Starting Hibernate...
Jul 02 09:36:52 local dns-dnsmasq.sh[5250]: <debug> NETWORKMANAGER_DNS_FORWARDER is not set to "dnsmasq" in /etc/sysconfig/network/config -> exit
Jul 02 09:36:52 local kernel: PM: Image not found (code -22)
Jul 02 09:36:52 local systemd-sleep[5254]: INFO: running /usr/lib/systemd/system-sleep/grub2.sleep for hibernate
Jul 02 09:36:52 local systemd-sleep[5254]: INFO: Running prepare-grub ..
Jul 02 09:36:53 local systemd-sleep[5254]:   running kernel is grub menu entry openSUSE Tumbleweed (vmlinuz-6.3.9-1-default)
Jul 02 09:36:53 local systemd-sleep[5254]:   preparing boot-loader: selecting entry openSUSE Tumbleweed, kernel /boot/6.3.9-1-default
Jul 02 09:36:53 local systemd-sleep[5254]:   running /usr/sbin/grub2-once "openSUSE Tumbleweed"
Jul 02 09:36:53 local systemd-sleep[5254]:     time needed for sync: 0.1 seconds, time needed for grub: 0.2 seconds.
Jul 02 09:36:53 local systemd-sleep[5254]: INFO: Done.
Jul 02 09:36:53 local systemd-sleep[5233]: Entering sleep state 'hibernate'...
Jul 02 09:36:53 local kernel: PM: hibernation: hibernation entry

In the boot journal after hibernation:

Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x00000000-0x00000fff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x0009f000-0x000fffff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x5df99000-0x5e898fff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x631c4000-0x631c4fff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x6321d000-0x63310fff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x63317000-0x63317fff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x674af000-0x692fefff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x692ff000-0x69b2efff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x69b2f000-0x69bfefff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x69c00000-0x737fffff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0x73800000-0xfe00ffff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0xfe010000-0xfe010fff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0xfe011000-0xfed1ffff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0xfed20000-0xfed7ffff]
Jul 02 09:37:34 local kernel: PM: hibernation: Registered nosave memory: [mem 0xfed80000-0xffffffff]

What am I mixing up here?

Does it work if you do not use encryption?

In the wiki Doc, missing an important point:
On opensuse, by default, dracut is not configured to allow boot from a resume partition.
To allow it, you need asking dracut to load a specific additional module.
In the .99-swap-partition.conf file you have created in /etc/dracut.conf.d, add a other line at the beggining:
add_dracutmodules+=" resume "

1 Like

Thanks, that was very helpful! Now it tried to mount the swap at boot time and failed to do so :smiley: with

...
Reached target Remote File Systems.
A start job is running for /dev/disk/by-uuid/8589e972... (... / no limit)

blocking the boot process. Maybe I find the cause for this when I have time to look at it.

I’m hesitant to add it to the docs now before getting it to work for me.

But what wonders me is: Why is there no timeout limit for this filesystem mount? That blocks the boot entirely; mounting the swap (as opposed to, e.g. the root directory) is not required to get the system up.

I think you missed something.
To make it work, you need 3 things:
1 - you need to configure all the encrypted partition to be decrypted with the same key file (not mandatory but easier). In your case, the / and the swap. In the wiki its the step 3&4. Do it for all the crypted partitions [seems ok in your /etc/crypttab - except the UUID see below].
2 - you need to ask dractut to load the resume module
3 - you need to ask dracut to decrypt the / and the swap partition using the key file.
4 - Grub should be configured with resume=UUID…

In your first post you indicate:
└─nvme0n1p3 259:3 0 15.5G 0 part 0a77e4b4-ecfe-495f-b66b-2554bcd320f8
└─cr_swap 254:1 0 15.5G 0 crypt [SWAP] 8589e972-0658-4809-9814-c5e188534da9

In your fstab you have swap UUID=8589e972… and in your crypttab you have cr_swap UUID=0a77e4b4…

I think you have something wrong in your UUID (check how you have configured your ‘/’ partition - compare lsblk info for ‘/’ and /etc/crypttab and /etc/fstab - I guest you should have the same UUID everywhere. It should be the same for swap).

I am using default installation and dracut includes resume module without any manual intervention and system performs resume (without LUKS).

You understand the difference between 'UUID of LUKS container" and “UUID of decrypted LUKS volume”, do not you?

It sounds like dependency problem between systemd services. Normally resume should be performed as the very first action, but to resume from encrypted partition it has to be decrypted first. Which is why I asked you from the very beginning - did it work without encryption?

First, swap partition is not “mounted”. As for your question - because decryoting of LUKS partition needs human intervention and it can take arbitrary amount of time.

Someone have the same problem and solution here

Enable Hibernation in openSUSE Tumbleweed (linux32bituefi.blogspot.com)

I am using default installation and dracut includes resume module without any manual intervention and system performs resume (without LUKS).

Your right. you don’t need the resume module if you don’t use a encrypted swap. I’ve struggled with this 3 ou 4 month ago.
And I’m also remember that I have struggled with UUID (something was not intuitive beetween the physical partition and the logical crypted volume but in don’t remember what…). I don’t have anymore the laptop with this config so I can’t check where exactly was the trouble.

reading again the wiki, I’m asking myself if the problem was not in the UUID used in the grub menu command

Don’t forget to add the line resume=UUID=.... (using the UUID of the encrypted partition containing swap) to the bootloader kernel-paramter using Yast.