Dracut resume module-setup enhancement

After system install, I noticed my system wasn’t resuming from hibernation.

After some reading, I learnt dracut resume module wasn’t being included in my initrd image. That’s because the way it checks whether my system supports hibernation or not, is not working with a default install (using UEFI, systemd) where systemd “automatically picks a suitable swap space to hibernate into” (see https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Pass_hibernate_location_to_initramfs).

I made a change in the resume module-setup, adding an additional check, trying to enhance the current behavior, but I’m not experienced enough to say it’s ok or not.

I’ve forked and committed here: https://github.com/snifer1981/dracut-ng/commit/628da3aec76ce14b8a043101fc93991bca5581ce

Perhaps someone with more expertise could review it and give me their opinion. If it’s okay, I might submit a pull request.

@snifer ,
If you are lazy select swap+hibernation during installation.
In that case it works out-of-the-box.
So, check up these:

 cat /etc/fstab 
# <file system>             <mount point>  <type>  <options>  <dump>  <pass>
UUID=2579-8E8E                            /efi           vfat    fmask=0137,dmask=0027 0 2
UUID=8dcc5dca-2344-4e93-a648-c11543e0da04 /              ext4    noatime    0 1
UUID=a3ee812a-ece5-44e6-91e7-1d1af28d43f8 swap           swap    defaults   0 0
tmpfs                                     /tmp           tmpfs   defaults,noatime,mode=1777 0 0
cat /etc/kernel/cmdline 
nvme_load=YES nowa/etc/dracut.conf.d/resume.conf 44-4e93-a648-c11543e0da04 resume=UUID=a3ee812a-ece5-44e6-91e7-1d1af28d43f8
cat /etc/dracut.conf.d/resume.conf 
add_dracutmodules+=" resume "

systemctl status systemd-hibernate-resume

should contain a SUCCESS after systemctl hibernate
Here it takes 130 sec to write the RAM to external disk.
When the lights are out you can restart by power-on.

journalctl -b 0 | grep -e "hibernate" -e "resume"
tells the story.

@eso, I forgot to mention I chose swap file during install, which is hardcoded to create a 512M file on /swapfile (see https://codeberg.org/Calamares/calamares/issues/1722). I later replaced it with a file at least the size of my RAM to be able to hibernate.

But the point is not how to be able to hibernate, the point is dracut trying to guess if you need the resume module, which should be true if systemd is able to hibernate; the current guess being “if /sys/power/resume = 0:0 then hibernation is not enabled”, which is not accurate IMHO.

@snifer ,
I switched to /swapfile just for you :face_with_raised_eyebrow:

sudo fallocate -l 16G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

fstab is modified like this

#UUID=f8543a9b-fd83-4291-9969-085ec35c3237 swap           swap    defaults   0 0
/swapfile none swap defaults 0 0

rebooted
Find the UUID of the partition containing the swap file:

df /swapfile
findmnt -no UUID -T /swapfile

Find the resume_offset:

filefrag -v /swapfile | awk '{ if($1=="0:"){print substr($4, 1, length($4)-2)} }'

and they are inserted to
cat /etc/kernel/cmdline
nvme_load=YES nowatchdog rw root=UUID=9b9bee00-aa24-462a-af48-f035bc889e94 resume=UUID=9b9bee00-aa24-462a-af48-f035bc889e94 resume_offset=12150784
and similarly to
/efi/loader/entries/*.conf

sudo dracut-rebuild
is also needed
having tested hibernation (it seems to work)
Checked

cat /sys/power/resume 
8:2

@eso, I’m sorry, you don’t have to hack your system just for me. It would have been easier just pointing me to https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Manually_specify_hibernate_location

But, as the last paragraph says before that section, “the following steps are not necessary unless the system is using legacy BIOS or you want to choose a different swap space from the automatically-selected one”. It’s just dracut’s resume module setup doesn’t know yet.

I’ve test systems / sandcastles I regularly nuke. No worries.