Hibernation with a swap file

Hi, I am having some trouble enabling hibernation when using a swap file rather than a swap partition on Fedora 30.

Journalctl output:

May 18 09:33:07 edgar polkitd[771]: Registered Authentication Agent for unix-process:3352:14875363 (system bus name :1.494 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale>
May 18 09:33:07 edgar NetworkManager[821]: <info>  [1558168387.3004] manager: sleep: sleep requested (sleeping: no  enabled: yes)
May 18 09:33:07 edgar NetworkManager[821]: <info>  [1558168387.3011] device (p2p-dev-wlp2s0): state change: disconnected -> unmanaged (reason 'sleeping', sys-iface-state: 'managed')
May 18 09:33:07 edgar NetworkManager[821]: <info>  [1558168387.3031] manager: NetworkManager state is now ASLEEP
May 18 09:33:07 edgar polkitd[771]: Unregistered Authentication Agent for unix-process:3352:14875363 (system bus name :1.494, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_GB.UTF-8) (disconnected from bus)
May 18 09:33:11 edgar systemd[1]: Starting TLP suspend/resume...
May 18 09:33:11 edgar systemd[1]: Started TLP suspend/resume.
May 18 09:33:11 edgar audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=tlp-sleep comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
May 18 09:33:11 edgar systemd[1]: Reached target Sleep.
May 18 09:33:11 edgar systemd[1]: Starting Hibernate...
May 18 09:33:11 edgar audit[3443]: AVC avc:  denied  { read } for  pid=3443 comm="systemd-sleep" name="swapfile" dev="mmcblk0p2" ino=13 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:swapfile_t:s0 tclass=file permissi>
May 18 09:33:11 edgar systemd-sleep[3443]: Failed to write hibernation disk offset: Permission denied
May 18 09:33:11 edgar systemd[1]: systemd-hibernate.service: Main process exited, code=exited, status=1/FAILURE
May 18 09:33:11 edgar systemd[1]: systemd-hibernate.service: Failed with result 'exit-code'.
May 18 09:33:11 edgar systemd[1]: Failed to start Hibernate.
May 18 09:33:11 edgar systemd[1]: Dependency failed for Hibernate.
May 18 09:33:11 edgar audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=systemd-hibernate comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'
May 18 09:33:11 edgar systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
May 18 09:33:11 edgar systemd-logind[787]: Operation 'sleep' finished.
May 18 09:33:11 edgar systemd[1]: Stopped target Sleep.
May 18 09:33:11 edgar NetworkManager[821]: <info>  [1558168391.9551] manager: sleep: wake requested (sleeping: yes  enabled: yes)

I believe this is an SELinux issue but have only recently switched to Fedora so don’t know how to troubleshoot it.

I’ve followed the advice here and used the command:

chcon -t swapfile_t /swapfile

Set the correct security context but still no luck. Any help would be appreciated.

3 Likes

I can confirm that.
SELinux message (sudo ausearch -c 'systemd-sleep' --raw) is:

type=AVC msg=audit(1558172191.011:864): avc: denied { read } for pid=20610 comm="systemd-sleep" name="swapfile" dev="dm-1" ino=17 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:swapfile_t:s0 tclass=file permissive=0

$ ls -Z /swapfile
unconfined_u:object_r:swapfile_t:s0 /swapfile
1 Like

Apart SELinux, it seems that hibernation to a swap file is a bit complex. Have a look here: https://unix.stackexchange.com/questions/434177/why-a-file-as-swap-cant-be-used-for-hibernation-in-linux