Hibernation on Fedora Workstation 42

Tadios Abebe | Sep 26, 2025 min read

Hibernation is a process where the entire contents of the computer’s RAM (volatile memory) are written to disk (non-volatile storage) before powering off. When the computer turns back on, it loads the previously saved memory data from disk back into RAM, preserving whatever you were doing before hibernation.

One essential component for hibernation is swap space. Swap refers to a portion of a computer’s storage (typically non-volatile) used as virtual memory to temporarily hold data when the system’s physical memory is insufficient to handle all active processes. The OS uses the MMU (Memory Management Unit) to swap pages between RAM and swap space, controlled by algorithms such as the Least Recently Used (LRU) policy.

On Fedora Workstation systems, enabling hibernation is not a trivial task. Starting with Fedora 33, Fedora moved away from creating a disk-based swap partition and instead uses ZRAM, a Linux kernel module that creates a compressed swap space in RAM. While efficient, this creates a problem if you want to use hibernation on your Fedora Workstation.

Below is a step-by-step guide on how to enable hibernation on Fedora Workstation. I tested this on Fedora Workstation 42 with KDE, running on a UEFI system with Secure Boot disabled and a Btrfs filesystem.

Essentially, these are the steps we need to take to enable hibernation on Fedora 42:

  • Create a swap space
  • Disable CoW on the swap space
  • Restore SELinux context
  • Create a swap file
  • Add the swap file to /etc/fstab
  • Activate swap
  • Configure Dracut to include the resume module
  • Rebuild initramfs

1. Creating a Swap Space

  • First, decide how big your swap space should be. Generally, swap must be large enough to hold the contents of RAM plus some overhead.
  • You can use the following formula to calculate an optimal swap size and store it in a Bash variable called SWAPSIZE:
SWAPSIZE=$(free | awk '/Mem/ { x = $2/1024/1024; printf "%.0fG", (x < 2 ? 2*x : x < 8 ? 1.5*x : x) }')
  • Then create a Btrfs subvolume where the swap file will reside:
sudo btrfs subvolume create /var/swap

2. Disable CoW on the Subvolume

  • In a CoW (Copy-on-Write) filesystem, every modification creates a new version of a data block.
  • Swap files need to be physically contiguous and directly writable because the kernel expects stable block addresses. Otherwise, the swap file could become fragmented, making it unusable.
  • Disable CoW on the subvolume with:
sudo chattr +C /var/swap

3. Restore SELinux Context

  • On SELinux-enabled distributions, files have security labels that enforce access rules.
  • The following command resets the SELinux security context to the default for /var/swap:
sudo restorecon /var/swap

4. Create a Swap File

  • Now create the swap file with the size we computed earlier:
sudo mkswap --file -L SWAPFILE --size $SWAPSIZE /var/swap/swapfile

5. Add the Swap File to /etc/fstab

  • Make the swap file persistent across reboots:
sudo bash -c 'echo /var/swap/swapfile none swap defaults 0 0 >>/etc/fstab'

6. Activate Swap

  • Activate the swap with:
sudo swapon -av

7. Configure Dracut to Include the Resume Module

  • Fedora uses Dracut to generate initramfs. To enable resume from hibernation, add the resume module:
sudo bash -c 'echo add_dracutmodules+=" resume " > /etc/dracut.conf.d/resume.conf'

8. Rebuild initramfs

  • Rebuild the initramfs with:
sudo dracut -f

9. Test Hibernation

  • Run:
systemctl hibernate
  • This will initiate hibernation and your computer will power down. Power it back on and check if it resumes correctly.

No additional configuration is required because systemd automatically stores the location of the swap file in a UEFI variable before hibernation. Once the machine is powered back on, that variable instructs the kernel to resume from this swap location.

If you are using KDE as your desktop environment and you want to get the hibernate button on the power options restarting the system is enough. The you will see the hibernate option.

comments powered by Disqus