Fedora 42 is a leading-edge Linux distribution, but hibernation isn’t enabled out of the box. Here’s a step-by-step guide to enable hibernation, resolve common SELinux issues, and add a Hibernate button to the GNOME power menu.
Why Hibernation?
Hibernation saves your entire session by writing RAM to disk and powering off. Next time you boot, everything resumes exactly where you left off—perfect for laptops and desktop users who want to save battery or avoid losing work during shutdowns.
Prerequisites
- UEFI System: Hibernation setup is simpler on UEFI. Run bootctl to confirm; if you see “Not booted with EFI,” a more manual approach is needed.
- Adequate Disk Space: You’ll need a swap file at least as large as your RAM.
- SELinux Consideration: SELinux can block hibernation; check the troubleshooting below.
Step 1: Create and Enable Swap
Open your terminal and enter:
SWAPSIZE=$(free | awk '/Mem/ {x=$2/1024/1024; printf "%.0fG", (x<2 ? 2*x : x<8 ? 1.5*x : x) }')
sudo btrfs subvolume create /var/swap
sudo chattr +C /var/swap
sudo restorecon /var/swap
sudo mkswap --file -L SWAPFILE --size $SWAPSIZE /var/swap/swapfile
sudo bash -c 'echo /var/swap/swapfile none swap defaults 0 0 >>/etc/fstab'
sudo swapon -av
This ensures a reliable swap setup compatible with Btrfs and systemd.
Step 2: Configure Dracut for Hibernation
To make systemd aware of your new swap location:
echo 'add_dracutmodules+=" resume "' | sudo tee /etc/dracut.conf.d/resume.conf
sudo dracut -f
Test it with:
systemctl hibernate
After reboot, your session should restore automatically.
Step 3: Fix “Access Denied” (SELinux)
If you get Call to Hibernate failed: Access denied, fix permissions:
sudo semanage fcontext -a -t swapfile_t '/var/swap(/.*)?'
sudo restorecon -RF /var/swap
If issues persist, generate and install a SELinux policy:
sudo setenforce 0 # Temporarily disable enforcement for testing
sudo systemctl hibernate
sudo setenforce 1 # Return to enforcing mode
# If hibernate works, make it permanent
sudo audit2allow -b -M systemd_hibernate
sudo semodule -i systemd_hibernate.pp
This sets the required access permissions for hibernation and keeps SELinux enabled for security.
Step 4: Add Hibernate Button to Power Menu (GNOME)
Fedora’s GNOME desktop doesn’t show Hibernate by default. Here’s how to add it:
Install the GNOME browser connector:
sudo dnf install gnome-browser-connector
Visit Hibernate Status Button Extension in your browser and toggle ON.
Enable the extension in the Extensions app, or via CLI:
gnome-extensions enable hibernate-status@dromi
Restart GNOME Shell (Alt+F2, type r, press Enter).
You’ll now see Hibernate in the top-right Power menu, making it easy to hibernate from the GUI.
Step 5: Configure Power Button for Hibernate
Want the physical power button to hibernate? Edit /etc/systemd/logind.conf:
HandlePowerKey=hibernate
Restart logind to apply:
sudo systemctl restart systemd-logind
Troubleshooting
Swap too small? Use at least as much as your RAM, possibly up to 1.5x for systems under 8 GB.
Button won’t appear? Ensure systemctl hibernate works, and GNOME Shell extension is compatible.
SSD concerns: Hibernation writes the entire RAM to disk—great for convenience, but means more SSD writes over time. If worried, use suspend instead.