How to enable hibernation in Bazzite Linux

PHASE 1: Create the swap subvolume for hibernation.
Create a swap subvolume (for example, due to Snapper):
sudo btrfs subvolume create /var/swap sudo semanage fcontext -a -t var_t /var/swap sudo restorecon /var/swap
Create swap file (size should be equal to or greater than your PC’s RAM):
SIZE=26G sudo btrfs filesystem mkswapfile --size $SIZE /var/swap/swapfile sudo semanage fcontext -a -t swapfile_t /var/swap/swapfile sudo restorecon /var/swap/swapfile
Sanity check validation:
sudo swapon /var/swap/swapfile
Backup your fstab file with:
sudo cp /etc/fstab /etc/fstab.bak
Then, edit fstab with this command:
sudo nano /etc/fstab
Then add the following line of code to fstab:
/var/swap/swapfile none swap defaults,nofail 0 0
Disable zram:
echo "" | sudo tee /etc/systemd/zram-generator.conf
Reboot.
In case of any error, you can restore from your backup with this:
sudo cp /etc/fstab.bak /etc/fstab
Revert changes and restore zram. If you want to restore the default, copy zram-generator.conf from /usr/etc/systemd/zram-generator.conf:
sudo cp /usr/etc/systemd/zram-generator.conf /etc/systemd/zram-generator.conf
PHASE 2: Tell the system where to find the hibernation volume.
Verify that the swapfile is active (should show path and size):
cat /proc/swaps
Get the UUID of the partition containing /var (should display an alphanumeric code):
findmnt -no UUID -T /var/swap/swapfile
Get the offset of the swapfile in Btrfs (should display a numeric code, we’ll need it for resume_offset):
sudo btrfs inspect-internal map-swapfile -r /var/swap/swapfile
Add parameters to the kernel (Bazzite uses rpm-ostree) Replace <UUID> and <OFFSET> with what you got earlier and remove the <> symbols:
sudo rpm-ostree kargs --append-if-missing="resume=UUID=<UUID>" --append-if-missing="resume_offset=<OFFSET>"
Reboot the system:
systemctl reboot
Check that the parameters are active (You should see resume=UUID=… resume_offset=… in the line.):
cat /proc/cmdline
KDE should show the “Hibernate” option in the shutdown menu.
Part of the content taken from https://docs.bazzite.gg/Advanced/swapfile/