Quite old question but I just ran into the same problem an nothing that was discussed here worked for me, but i found this in the btrfs filesystem manpage :
mkswapfile [-s size] file
Create a new file that's suitable and formatted as a swapfile. Default size is 2GiB, fixed page
size 4KiB, minimum size is 40KiB.
A swapfile must be created in a specific way: NOCOW and preallocated. Subvolume containing a
swapfile cannot be snapshotted and blocks of an activated swapfile cannot be balanced.
Swapfile creation can be achieved by standalone commands too. Activation needs to be done by com‐
mand swapon(8). See also command btrfs inspect-internal map-swapfile and the Swapfile feature de‐
scription.
NOTE:
The command is a simplified version of 'mkswap', if you want to set label, page size, or other
parameters please use 'mkswap' proper.
Options
-s|--size SIZE
Create swapfile of a given size SIZE (accepting k/m/g/e/p suffix).
-U|--uuid UUID
specify UUID to use, or a special value: clear (all zeros), random, time (time-based ran‐
dom)
So i did this :
sudo btrfs filesystem mkswapfile --size 12g --uuid clear /swapfile/path
And it worked perfectly
Obviously your filesystem must be btrfs, which is the default in Fedora if I'm not mistaken
swapon
program, but it can provide more information in its log.sudo
.swap
. You can write pretty much anything there.swapon: swapfile has holes
and the answer below worked.