Can't seem to swapon to a swapfile I created

I am not too sure why I can’t swapon to a swapfile I created.

Here are the commands I am using.

sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

The error message I get is:
swapon: /swapfile: swapon failed: Invalid argument

Any idea why this is happening?

I always installed the swap file without sudo and if as root and it never gave me problems.

I thought you need root privilages if I am adding files to the / area?

Edit: I am getting an error without root privilages:

fallocate: cannot open /swapfile: Permission denied

Judd probably meant creating swapfile directly as root.

What filesystem do you have? Btrfs? Ext4?
And what kernel version?


Did you update fstab after?

Edit the fstab configuration to add an entry for the swap file:


/swapfile none swap defaults 0 0

to check:

swapon --show

From the EndeavourOS wiki:

For instance my fstab looks like this with swapfile:



There was a discussion about fallocate being deprecated for use with newer kernels (I’ll see if I can find the links, but I know there were discussions in our EOS forum on this topic a month or so ago). I also had this issue, so I can verify that this solution will work:

Please use ‘dd’ to create your swapfile, not ‘fallocate.’ That should solve this issue. The instructions are on the arch wiki under the swap file topic.

Let me know if you can’t find the links.







Interesting, I have no idea about newer kernels, but I did create this today on the LTS kernel. So it does work at least there still.

I am using ext4.

I know I am supposed to do this but that is after I can get swap to work.

fallocate still worked just fine for me. It was when I used the swapon command it failed.

I will give it a try, thanks.

Just one quick question, what does 0, 0 tell Linux exactly to the /swapfile?

0 1 is /root boot
0 0 there is swap


Are you sure it’s not working? What is the output of:

swapon --show

It works now without any errors after using @ricklinux 's solution


man fstab

1 Like

duckduckgoDOTcom suggested this article.

To save you some time:

• The fifth field (dump)

Specifies the option that need to be used by the dump (backup utility) program. If the value is set to 0, then the partition is excluded from taking backup and if the option is a nonzero value, the filesystem will be backed up.

• The sixth field (fsck)

Mentions the fsck option. That is if the value is set to zero, the device or partition will be excluded from fsck check and if it is nonzero the fsck check will be run in the order in which the value is set.

The root partition will have this value set to one (1) so that it will be checked first by fsck. If you set to two (2) that means the system to do fsck on all rest partition marked ‘2’ in sequence on system reboot.

1 Like