Hibernation only triggers lockscreen with swapfile (likely selinux problem)

Hi there, i am not sure if my issue is similar to Hibernation with a swap file, however, i am coming from archlinux, where i used to use a swapfile inside an encrypted partition for hibernation … and swap. I didn’t read anywhere how to add / if i need to add the resume hook, so i assume it is not needed. My goal is to let my laptop hibernate automatically after suspend.

So on the installation, i did not add a swap partition (otherwise it would work out of the box as i read?), instead i’ve created the swapfile in an additional step (and swap works just fine).

This is what my grub looks like now:

GRUB_CMDLINE_LINUX="
rd.lvm.lv=fedora_localhost-live/root rd.luks.uuid=luks-bc11...74c 
rhgb quiet resume=/dev/disk/by-uuid/bc1...874c    # my root partition
resume_offset=1398784"                            # offset to locate the swapfile

When i’ve tried to confirm my setup, i ran systemctl hibernate and the only thing that happened was, that the lockscreen popped up. I couldn’t find any error on my logs so i kinda have nothing to work with.

Help would be very appreciated. :pray:

Hi @milanihl! Welcome to the community! Please do take a few minutes to go over the introductory posts in #start-here when you have the time. They contain lots of useful information.

If someone with some knowledge won’t chime in, and if you’re ready to troubleshoot the problem yourself, then I’d suggest looking at man systemd-sleep – that’s systemd’s units whose output you need to look for.

If there’s nothing in the logs for these units, then I’d try increasing systemd’s log/verbosity level – for these units or in general. Here and here seems to be some clues, in particular systemd.log_level=debug may be of interest.

Just a suggestion for a general direction of inquiry. Also if you can agree to easier ways, then maybe adding swap partition instead would be faster and simpler.

Also I heard that hibernation support in Linux (not in Fedora in particular, across all distribution) is still quite flaky, it depends on a multitude of factors such as hardware you have, kernel compilation flags, settings, etc. I.e. it can work good for you on one machine but not on another and also it can work good in one distribution but not in another on the same machine. If I remember correctly, that was the opinion of a person close to Ubuntu development (in a podcast I think), and that’s why they don’t enable hibernation by default (I haven’t checked do they or not). It sort of hit or miss )

That doesn’t mean you shouldn’t try it yourself, it could work perfectly for you once you configure it correctly. It just could mean that your configuration working on Arch doesn’t automatically guarantee it working on Fedora.

Also maybe you need to clarify the name of the post to indicate that you use a swapfile, not the swap partition (as in default installation) – so that newer users with hibernation problems won’t be confused by your post.

1 Like

Make sure you disconnect all network filesystems/shares beforehand.

1 Like

I am sorry, i did a mistake and somehow did not notice the logentry / i checked the journal log falsely. This time i checked the entire file ((with journalctl --file) journalctl -xe is way more useless with the limited buffer in debug). Even without debug, there is an entry.

It appears that selinux does not like me to do this action.
The fedora docs recommend chcon -t swapfile_t /swapfile, but this has no effect on the issue, i did some more research and also tried

semanage fcontext -a -t swapfile_t "/swapfile"
restorecon /swapfile

As well… without success.

systemd[1]: Reached target Sleep.
systemd[1]: Starting Hibernate
audit[]: AVC avc:  denied  { read } for  pid=3130 comm="systemd-sleep" name="swapfile" dev="dm-1" ino=5477 scontext=system_u:system_r:init_t:s0 tcontext=>
systemd-sleep[]: Failed to write hibernation disk offset: Permission denied
systemd[1]: systemd-hibernate.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: systemd-hibernate.service: Failed with result 'exit-code'.
systemd[1]: Failed to start Hibernate.
systemd[1]: Dependency failed for Hibernate.
systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
systemd-logind[]: Operation 'sleep' finished.
audit[1]: SERVICE_START pid=1 uid=0 auid=429...295 ses=429...295 subj=system_u:system_r:init_t:s0 msg='unit=systemd-hibernate comm="systemd" exe="/usr/lib/>
systemd[1]: Stopped target Sleep.
#############################################
unconfined_u:object_r:swapfile_t:s0 /swapfile

If i run entirely out of options, i may try out the swap partition instead, but i really really prefer a swapfile… :frowning:

Please post the output of ls -Z /swapfile.

Also you need to find out which SELinux contexts systemd-sleep is actually allowed to read, and change swapfile to it instead.

There’s a graphical SELinux troubleshoot helper (may be not installed by default on F30, always was previously, I use it). It – along with other useful info – is described here, please check it:

unconfined_u:object_r:swapfile_t:s0 /swapfile, this was the last line in my codeblock. :slight_smile:

Also thanks, the tool gave me commands to paste and the system hibernated :tada:
Now i try to figure out why it doesn’t resume (it just boots), but this would be oot and i am confident to find the solution myself - thanks again. :ok_hand:

I’ve missed it, it just sort of looked like another of log file)

And that’s may be due to you incorrectly specifying resume target (I’m not sure).

There was a common Fedora bug several versions ago, the installed didn’t add resume= kernel boot parameter at all, as far as I remember it produced the same effect: system hibernated, but performed normal boot upon poweron. All that was with default configuration and with swap partition, not file.

And of course. the reason in your case can be something completely different, still the symptoms are alike.

1 Like