Problems setting up Swapfile, contains holes or unsupported extents

Hello everyone.

I have tried setting up a Swapfile using this guide: Swap - Manjaro

I have no Swap Partition but realised I need a Swap because I ran out of memory a couple of times, due to a software with a memory leak.
I followed every step in the guide from 1 to 4, skipping 5 (Swap Partition), starting again at 6. I altered the command to create a Swapfile to create one with 6 GB (instead of 4 as in the example) because that’s what I calculated using the information in the guide.
As far as I can tell, the Swapfile was created uneventful and I can also see it in Dolphin. I then set permission as in the guide and tried to format it. This is when I encountered my problem. I used the command sudo mkswap /swapfile from the guide but got the following in return:

mkswap: /swapfile contains holes or other unsupported extents.
        This swap file can be rejected by kernel on swap activation!
        Use --verbose for more details.

mkswap: /swapfile: warning: wiping old swap signature.
Setting up swapspace version 1, size = 6 GiB (6442446848 bytes)
no label, UUID=9f1d0366-c807-45dc-bccf-04a884afd66f

I cannot continue with the guide using sudo swapon /swapfile, as when I use that command I get the following:

swapon: /swapfile: swapon failed: Invalid argument

I did search for the issue but only found the advice to recreate the swapfile using dd instead of fallocate. This doesn’t help much since the command in the guide used dd already so that’s what I used. The only time I deviated from the guide was when I changed count=4096 to count=6144 during the creation of the Swapfile, I did not change any other part of any command.

Please note that I am very new to Linux in general, I tried my best to follow every step of the guide but it is very possible the guide might require some form of common knowledge I didn’t acquire yet. I am grateful for any help, more detailed explanations might certainly help me understand what is going on better though. Thank you in advance.

My first guess is that your filesystem is BTRFS, which means that you would need to follow slightly different instructions. If unsure, you can check your filesystem with something like df -Th or inxi --partitions.

In addition to the Swapfiles on BTRFS instructions on the Manjaro Wiki, you may also want to consult the Arch Wiki, whose instructions are different. I don’t have enough experience with BTRFS to guide you, but one of our resident experts will likely chip in soon.

6 Likes

The swap file must be created with both compression and copy-on-write disabled. :backhand_index_pointing_down:

[ -f /path/to/swapfile ] && sudo rm -f /path/to/swapfile
sudo touch /path/to/swapfile && sudo chattr +C +m /path/to/swapfile && sudo mkswap -F /path/to/swapfile
1 Like

Thank you both.

Unfortunately, with that command (file paths adjusted) I get the following error:
mkswap: error: swap area needs to be at least 40 KiB

And I’ve checked, my filesystem is indeed BTRFS. In Addition to the command from Aragorn (which failed as mentioned above), I tried the instructions on the guide using these commands:

sudo truncate -s 0 /swapfile
sudo chattr +C /swapfile
sudo btrfs property set /swapfile compression none

Which also failed with the following error:
ERROR: failed to set compression for /swapfile: Invalid argument

I’ve not needed to do this myself, but I see some people say that step is no longer required: Can't create swap file: swapon failed: Invalid argument - #7 by dalto - Newbie - EndeavourOS

You could do it that way.. But your size is 0, and the last command isn’t a proper command.

I used 8G here, but put in your size you want.

sudo btrfs filesystem mkswapfile --size 8g --uuid clear /swapfile

This will set the no-CoW attribute for you as well.

If you do not want to make a swap partition to make everything easier and faster, at least put /swapfile in its own subvolume, like @swap, off the top-level subvolume; isolated from your @ or root subvolume.

The reason being that you don’t want your swapfile to be included in any snapshot of the “/” subvolume. :wink:

Of course, this would bloat snapshots with garbage.

Even assuming no snapshots, there are still reasons to put it in its own subvolume.

A lot of the btrfs tools you have at your disposal work on either subvolumes or folders. Doing it this way also removes that functionality, since the swap file resides in: /. Very different type of workloads, root and swap.

I also dislike the idea of pinning a pre-allocated swap file in the middle of your root subvolume. (For the most part, that’s just me just liking to be clean.)

1 Like

That’s just what the guide recommends here: Swap - Manjaro

The guide also recommends putting it in its own subvolume which I saw way too late. I don’t mean to be insolent but I think this one is due for an overhaul. Especially if what @Phemisters said is true.

This is what I did for now. Basically just using the other two commands and then moving on with the dd command in the guide. I got no other errors but I haven’t tested filling up my RAM either so I’m just hoping it’s fine. I’ll mark this as the solution for now. If it’s wrong and might lead to problems further down the road please do tell me. Until then thank you everyone for the help.

That is a little dated unfortunately.

The Arch wiki even needs some polishing.

When they say..

Consider creating the subvolume directly below the top-level subvolume

It is simply..

sudo mount -o subvol=/ /dev/vda2 /mnt
# or 
sudo mount -o subvolid=5 /dev/vda2 /mnt
# then
sudo btrfs subvolume create /mnt/swap

They leave out adding one extra /etc/fstab line to mount this subvolume upon reboots, most likely simply copying your @ and @home lines, and changing the subvol name and mount location.

If you just added the new fstab line, then you can.

# Easier to delete and remake your swap than move it
sudo rm /swapfile
sudo systemctl daemon-reload
sudo mount /swap
sudo btrfs filesystem mkswapfile --size 16g --uuid clear /swap/swapfile

And your swap file is moved to a top-level subvolume under the subvolume swap, in the folder /swap


Meaning what exactly?

The EndeavourOS forum post has the classic way of making swap files, also dated!

It’s not only that btrfs fi mkswapfile does 3 or 4 of the steps for you..

You generally don’t have to pad out those files with dd or fallocate anymore.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.

Edit: I’ve marked this as the solution because it has all info of what I did and lead me to finishing this. If you stumbled upon this thread I suggest reading the rest as well as there is some more information about this and my solution might not be the best practice.

This thread closed automatically (I was busy and couldn’t reply in time) so I messaged @Molski privately because I was worried I might’ve messed something up. Molski was kind enough to reopen it and then continued to answer my questions (thank you very much) which made reopening not super necessary but I might as well leave this message here in case another lost user comes across the same problem as long as the guide isn’t updated. But there is a warning now so maybe this’ll help someone in the meantime.

What I ended up doing before your reply came in was setting up a subvolume called @swapfile and creating the swapfile in there. This is my line in fstab:
/@swapfile/swapfile none swap defaults 0 0
As far as I remember I’ve set up the swapfile as described in Swap - Manjaro but skipped the compression command (sudo btrfs property set /swapfile compression none) as it was suggested that this step can be skipped on the EndeavourOS thread Phemisters linked to. After that the setup went uneventful using the dd command and all the rest described in Swap - Manjaro.

Molski mentioned

But this came after I already set it up and was a reason for my concern. It doesn’t seem to be an issue though. Molski shared a script with me to test and the swapfile seems to be working just fine for me now.
It might not have been the cleanest or “best” way to do things now but at least the result seems to be the same.

Thank you everyone once again for helping me out. Glad this has been sorted out. =)

There is just one last unknown, I think.

Can you post your:

sudo btrfs sub list /

(We just want to see the swap related volume, and what its parent is.)

1 Like

Sure:

Summary
ID 256 gen 231590 top level 5 path timeshift-btrfs/snapshots/2025-12-15_15-10-53/@
ID 257 gen 231593 top level 5 path @home
ID 258 gen 230842 top level 5 path @cache
ID 259 gen 231593 top level 5 path @log
ID 292 gen 231593 top level 5 path @
ID 294 gen 231590 top level 5 path timeshift-btrfs/snapshots/2025-12-15_15-59-23/@
ID 330 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-01-10_09-00-00/@
ID 338 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-01-16_11-24-11/@
ID 375 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-02-10_09-00-00/@
ID 389 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-02-18_19-29-40/@
ID 410 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-04_21-56-49/@
ID 412 gen 230171 top level 292 path @swapfile
ID 413 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-05_20-54-09/@
ID 418 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-10_09-00-00/@
ID 420 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-11_07-00-00/@
ID 423 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-13_21-00-00/@
ID 424 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-14_21-00-01/@
ID 425 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-15_00-13-12/@
ID 426 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-15_21-00-00/@
ID 427 gen 231590 top level 5 path timeshift-btrfs/snapshots/2026-03-16_21-00-00/@
ID 428 gen 231591 top level 5 path timeshift-btrfs/snapshots/2026-03-17_21-00-00/@

I was hoping this was not the case, we want it to say top level 5.

So this subvolume is off your root subvolume, you can see ID 292 is your root:

ID 292 gen 231593 top level 5 path @

Everything will work as is, but your swapfile is in the same subvolume as your root.

Even if you don’t use snapshots… These are very different type workloads, even the Arch wiki recommends you make this off your top level subvolume. It’s just cleaner isolation.

If you do use snapshots, then you will bloat them up with garbage in this configuration.

Even an optimal swap file is over 10x worse compared to a swap partition, but if you want to stick with a swap file, and want to move this swap file off your root subvolume. Here is how..


btrfs has a top level volume, I did paste it above on to how to mount it.

sudo mount -o subvol=/ /dev/vda2 /mnt
# or 
sudo mount -o subvolid=5 /dev/vda2 /mnt

You can just ls -l /mnt to see your subvolumes off the top level, and this is where you want your @swapfile subvolume.

Create it only when the above is mounted.

sudo btrfs sub create /mnt/@swapfile

Now when you do a btrfs sub list /, you should see top level 5 on @swapfile.

Someone was telling me you don’t need this next step, but I do not understand exactly how it works without this mount.

But I know this way works!

Add one line to your fstab, it’s just like your other btrfs mounts with a different subvol name and mount location.

/etc/fstab


UUID=xxxx-xx-xx-xx-xxxx /swapfile btrfs subvol=/@swapfile 0 0

With the same UUID as your root btrfs file system.

Set the changes:

sudo systemctl daemon-reload

It’s easier to re-create the swap file, than move it. So just delete it, and remove that subvolume.

sudo rm /swapfile/swapfile
sudo btrfs subvolume remove /swapfile

Now you can create swap file on the new subvolume.

sudo mount /swapfile
sudo btrfs filesystem mkswapfile --size 16g --uuid clear /swapfile/swapfile

Or what ever size you want in there.

And of course..

sudo swapon /swapfile/swapfile
# or
reboot

Subvolumes can be moved around, just like directories, because to the top-level subvolume, that’s exactly what they are. A simple mv command on the directory that the subvolume is mounted at will do the job — no need for deleting and recreating the subvolume.

Also, a subvolume nested inside the @ subvolume will not be snapshotted. The snapshot will only contain an empty directory with the name of the nested subvolume.

2 Likes

I guess it’s a hard habit to break, not moving many gigs of swap aka garbage around. (Now that happens in seconds, on a nice NVMe drive.)

But you’re right @Aragorn, the instructions could be a lot easier. It’s so easy when you put it like that.

Myself, I am just walking out the door now. :worried:

1 Like

Here are the simplified instructions (by hauling the whole subvolume over).

If you did not do the above already, it should yield the same result.

I did forget this command first before (oops!):

sudo swapoff /swapfile/swapfile

Mount top level, and move the subvolume.

sudo btrfs -o subvolid=5 /dev/.. /mnt
sudo mv /swapfile /mnt

Edit:

/etc/fstab


UUID=xxxx-xx-xx-xx-xxxx /swapfile btrfs subvol=/@swapfile 0 0

With the same UUID as your root btrfs file system.

Mount the moved swap subvolume.

sudo systemctl daemon-reload
sudo mount /swapfile

Enable swap.

sudo swapon /swapfile/swapfile
# or
reboot
1 Like

I should’ve known this story isn’t over yet. :sweat_smile:

Shouldn’t that have /@swapfile/swapfile instead? I admit I don’t fully understand the whole @-thing here but it seems to exclude it from snapshots according to Aragorn:

I’m all for clean solutions and it doesn’t seem too complicated but it seems like I should be fine and not bloating my snapshots as it is right now, so this is more an optional cleanup than a fix, right?
Still I’d like to be absolutely sure about when to use the @ and when to not use it before I start using any of these commands.