Skip to content

Instantly share code, notes, and snippets.

@Cryptophobia
Last active July 5, 2026 05:13
Show Gist options
  • Select an option

  • Save Cryptophobia/e304a04fcb156dd0959fbba6b7a26106 to your computer and use it in GitHub Desktop.

Select an option

Save Cryptophobia/e304a04fcb156dd0959fbba6b7a26106 to your computer and use it in GitHub Desktop.
Fedora 43 Hibernation Setup

Enabling Hibernation on Fedora 43

A complete guide to enable hibernation on Fedora 43 (Workstation) with UEFI and btrfs filesystem, including fixes for Secure Boot and SELinux issues.

Complete Command Reference

Run these commands in sequence to enable hibernation:

# Calculate swap size (RAM-based formula)
SWAPSIZE=$(free | awk '/Mem/ {x=$2/1024/1024; printf "%.0fG", (x<2 ? 2*x : x<8 ? 1.5*x : x) }')
SWAPFILE=/var/swap/swapfile

# Create btrfs subvolume and swap file
sudo btrfs subvolume create /var/swap
sudo btrfs filesystem mkswapfile --size $SWAPSIZE --uuid clear $SWAPFILE

# Enable swap file
echo $SWAPFILE none swap defaults 0 0 | sudo tee --append /etc/fstab
sudo swapon --all --verbose

# Configure dracut for resume
echo 'add_dracutmodules+=" resume "' | sudo tee /etc/dracut.conf.d/resume.conf
sudo dracut --force --verbose

# Fix SELinux permissions (critical!)
sudo semanage fcontext --add --type swapfile_t $SWAPFILE
sudo restorecon -RF /var/swap

# Test hibernation
sudo systemctl hibernate

Prerequisites

1. UEFI Boot Required

Verify your system uses UEFI:

bootctl

If this prints "Not booted with EFI", this method won't work.

2. Disable Secure Boot (Required)

Important: Hibernation requires Secure Boot to be disabled in BIOS/UEFI settings.

With Secure Boot enabled, you'll get:

Call to Hibernate failed: Sleep verb 'hibernate' is not configured or configuration is not supported by kernel

To disable: Reboot → BIOS/UEFI settings (F2/F10/F12/Del) → Security/Boot menu → Disable Secure Boot → Save and exit.

Why? Kernel lockdown (enabled with Secure Boot) prevents hibernation to unencrypted swap for security reasons.

Step-by-Step Explanation

Step 1: Create Swap File on btrfs

The command btrfs filesystem mkswapfile automatically:

  • Disables copy-on-write (COW) for the swap file
  • Creates the file with proper attributes
  • Avoids the "swapfile must not be copy-on-write" error

Using standard mkswap will fail on btrfs without additional COW disabling steps.

Step 2: Enable Swap File

The swap file is added to /etc/fstab for persistence across reboots and activated immediately. Verify with swapon --show - you should see both your swap file and the existing zram device.

Step 3: Configure dracut

The --verbose flag is important - without it, dracut appears to hang with no output for 2-5 minutes. It shows progress and confirms the command is working.

Step 4: Fix SELinux Permissions

Critical step often missed! Without proper SELinux labeling, you'll get "Access denied" errors even when running as root. These commands tag the swap file with the swapfile_t type that SELinux expects.

Verification

Check System Status

# Verify swap is active
swapon --show

# Check security configuration
fwupdmgr security

# Verify SELinux context
ls -Z /var/swap/swapfile

Expected fwupdmgr security output:

✔ UEFI secure boot: Disabled
✘ Linux kernel lockdown: Disabled (expected for hibernation)
✘ Linux swap: Invalid (unencrypted swap present)

Troubleshooting

"Sleep verb 'hibernate' is not configured"

Cause: Secure Boot is still enabled
Solution: Disable Secure Boot in BIOS/UEFI settings

"Call to Hibernate failed: Access denied"

Cause: SELinux policy not configured
Solution: Run the SELinux commands from the reference above and verify with ls -Z /var/swap/swapfile (should show swapfile_t)

dracut Appears Stuck

Cause: No progress output by default (takes 2-5 minutes)
Solution: Use --verbose flag as shown in the command reference

"swapfile must not be copy-on-write"

Cause: Using standard mkswap instead of btrfs-specific command
Solution: Use btrfs filesystem mkswapfile as shown in the command reference

Additional Notes

  • zram remains active: The existing zram swap device continues to work alongside the swap file. zram has higher priority for normal swap operations; the disk-based swap file is used primarily for hibernation.

  • Swap file location: The swap file is in /var/swap/ as a separate btrfs subvolume, isolating it from snapshots.

  • Suspend vs Hibernate:

    • Suspend: RAM stays powered, fast resume, drains battery slowly
    • Hibernate: RAM saved to disk, complete power off, slower resume, no battery drain
    • Suspend-then-hibernate: systemctl suspend-then-hibernate (suspends first, hibernates after timeout)

How It Works

On UEFI systems, hibernation uses a streamlined process:

  1. systemd stores swap file location in a UEFI variable
  2. System writes memory contents to swap file
  3. Machine powers off completely
  4. On boot, bootloader reads the UEFI variable
  5. Kernel resumes from swap file location
  6. Memory is restored and execution continues

This is simpler than legacy BIOS systems that required manual boot parameter configuration.

References and Documentation

Based on: Fedora Magazine - Update on hibernation in Fedora Workstation

Additional references:

Key improvements over original article:

  1. Uses btrfs filesystem mkswapfile instead of standard mkswap (avoids COW issues)
  2. Includes SELinux configuration (prevents "Access denied" errors)
  3. Documents Secure Boot requirement (must be disabled)
  4. Uses --verbose flag for dracut (shows progress)
  5. Complete troubleshooting section

Tested on: Fedora 43 Workstation, UEFI boot, btrfs filesystem
Last updated: February 2026


This guide is provided as-is for the community. Feel free to share, modify, and improve.

@random-integer

Copy link
Copy Markdown

@Tobian42 Thanks! I see now.

I was asking because this sentence from the original post:

Why? Kernel lockdown (enabled with Secure Boot) prevents hibernation to unencrypted swap for security reasons.

made me thought that if you use encrypted swap, you would have no problem with secure boot.

@sirrahn

sirrahn commented Apr 25, 2026

Copy link
Copy Markdown

Hi, I have just run through these commands on Fedora 43 having disabled secure boot but when it goes to hibernate my system now turns off and if I hit a key or the power button with restart. I also notice that the boot options now come up on startup. Do you have any idea what might be happening here?

I should add that I saw no error messages and I ran through each of the steps which seemed to work as expected. This is what I get if I run swapon --show:

NAME TYPE SIZE USED PRIO
/dev/zram0 partition 8G 1G 100
/var/swap/swapfile file 15G 0B -1

@Tobian42

Copy link
Copy Markdown

@sirrahn My Guide tells how to Hibernate with a swap partition, you have a swapfile. I do not know if it could work with a swapfile

Guide: Encrypted Swap Partition

1: Create the Partition

...

@sirrahn

sirrahn commented May 3, 2026

Copy link
Copy Markdown

Thanks Tobian42,
I hadn't realised that you had introduced a completely alternative guide in the comments - when I said that I had run through these commands I meant the original process that was proposed. To be honest I didn't read carefully and didn't clock that one was discussing a swapfile and the other a partition. I seem to have reverted the changes I made relating to the swapfile and I may try your process - seems it is supposed to work with an encrypted drive.

@larryedwards

larryedwards commented May 29, 2026

Copy link
Copy Markdown

This is a wonderful guide; thanks!

I have hibernation working of f44 (and previously f43), but with one difficulty. In your How It Works section I have points 1, 2 and 4 through 6 working perfectly, but a difficulty with "3. Machine powers off completely." My P52 Thinkpad resumes from hibernation even if I remove the battery (which confirms all aspects of true hibernation work). BUT, when hibernated with the battery in place the computer is not shut off completely. It stays partly awake to monitor the lid sensor. This drains the battery over a long period, and even worse causes a dangerous(!) feature which wakes the computer if I bump or open the lid.

I have spent months trying to find a way to stop that, so that the computer will be completely powered off when hibernated. I have just discovered that one bit of advise that it ubiquitous online for fixing that does not work, at least in Fedora. That advice is to put "[Sleep] HibernationMode=shutdown" (or shutdown -P now) in /etc/systemd/sleep.conf and /etc/systemd.d/custom.conf.

However, I just now ran "journalctl -b -1 | grep ='Hibernate'", which produced "Unknown key 'HibernationMode' in section [Sleep], Ignoring." According to documentation for sleep.conf, actually the online advice is wrong. Only settings like "[Sleep] AllowHibernation=yes" are allowed, and HibernationMode is not an allowed setting.

So I'm kind of adrift on this at the moment. If you guide could be expanded to include these kinds of settings, I would be grateful. The problem I have with the lid-activated resume is apparently a "feature" called "Flip Start," for which the UEFI/BIOS of recent computers has a setting, but which my not-so-old P52 does not. So I need to find a settings way to fix the problem. Many others are in this boat with me. Hope you can help.

@sicktooth

Copy link
Copy Markdown

how do I undo all this and start afresh? I deleted my swapfile at /var/swap/swapfile
because I have been experiencing a lot of freezing from my laptop after booting up from hibernate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment