My top recommendation if you need disk-based swap is to create a swap partition. In particular for the hibernation use case.
However, if you’re committed to swapfiles on Btrfs, see man 5 btrfs
and make sure you can live with the limitations. And then continue:
Fedora doesn’t have an official location for swapfiles yet, so this is subject to change.
btrfs subvolume create /var/swap
chattr +C /var/swap
fallocate -l 4G /var/swap/swapfile1
mkswap /var/swap/swapfile1
swapon /var/swap/swapfile1
You can also add this swapfile to fstab for automatic enabling during startup.
If you snapshot /
then the swap
subvolume will not be snapshot. That’s good. But if you rollback to a snapshot, then this subvolume won’t be present, and thus swap activation files and thus boot fails. So you might want to add nofail
to the fstab entry. The gotcha with that is it becomes a silent failure. You get no swap, but at least startup completes.
There are alternatives being explored, that will make this more elegant.