Trouble with swapon

Thanks for the quick reply. I do have that in my /etc/fstab, but I don’t know why I can’t activate the swapfile.

[philo@Spooner ~]$ sudo free -h
              total        used        free      shared  buff/cache   available
Mem:          7,7Gi       4,9Gi       413Mi       826Mi       2,4Gi       1,7Gi
Swap:            0B          0B          0B

I"m not sure why. Have you logged out and back in or rebooted? You do have fallocate installed?

Just as a reminder, there was a recent issue with kernel 5.7.2 not recognizing swapfiles (it will correctly recognize a swap partition). There is a patch forthcoming, but it has not reached mainline yet. (There is another thread on this issue.)

Suggestion: drop to the current LTS kernel and see if your swapfile is recognized.

Not sure if this is related, but a thought …

Edit: there were reports that swapfiles created with dd work okay with the 5.7.2 kernel; however, those created with fallocate failed. That may also be a possible avenue for resolution.




Yes, i forgot about that. :upside_down_face:

Edit: Well the 5.7.3 kernel is out but not down the pipe yet.

1 Like

Thanks so much! So, I just do a yay -S linux-lts?

I just read that there is a problem with fallocate sometimes and it is better to use the dd command to create the swap file. Maybe that is the issue. Do you know how to create a swap file using dd?

Do in terminal:

sudo pacman -S linux-lts linux-lts-headers

1 Like


If you want to remove the swap file you have created and start over. You can use dd to create it. Same procedures but just using dd instead of fallocate.

sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

You still have to edit the fstab also.
Edit: I’m not sure when using dd if you have to do this other stuff?

#20 In the link

1 Like

Bingo! We have a winner. Thanks for your help!

[philo@Spooner ~]$ sudo rm /swapfile 
[philo@Spooner ~]$ sudo dd if=/dev/zero of=/swapfile count=8192 bs=1MiB
8192+0 records in
8192+0 records out
8589934592 bytes (8,6 GB, 8,0 GiB) copied, 81,3466 s, 106 MB/s
[philo@Spooner ~]$ sudo chmod 600 /swapfile 
[philo@Spooner ~]$ sudo mkswap /swapfile 
Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)
no label, UUID=86aa8626-304d-424e-9830-b681d5ac614b
[philo@Spooner ~]$ sudo swapon /swapfile
[philo@Spooner ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7,7Gi       4,7Gi       268Mi       828Mi       2,7Gi       1,9Gi
Swap:         8,0Gi          0B       8,0Gi

Glad that works. How has the audio jack been working for you?


1 Like

Not so much, I’ve given up and disabled it at this point.

My laptop having 3 GB RAM. Is it sufficient?. If not how to make swap file. Is it possible to create Swap file in EOS partition ?. I need simple step by step instruction.

No :hugs:

1 Like


1 Like

Please see the error :-

sudo fallocate -l 2G/sswapfile
[sudo] password for ramesh:
fallocate: no filename specified
[ramesh@ramesh ~]$ sudo fallocate -l 2G/swapfile
fallocate: no filename specified
[ramesh@ramesh ~]$ sudo fallocate -l 2G /swapfile
[ramesh@ramesh ~]$ sudo chmod 600 /swapfile
[ramesh@ramesh ~]$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=e23cf8a8-1312-4ca3-a4e3-2d034b0aaf33
[ramesh@ramesh ~]$ sudo swapon /swapfile
swapon: /swapfile: swapon failed: Invalid argument
[ramesh@ramesh ~]$

Note: Using dd to allocate a swap file is the most portable solution, see swapon(8) for details.

achwiki says


It is beyond my knowledge and capacity. How to delete the swap file created now

sudo rm /swapfile will delete it.

You can just repeat the same steps the OP posted, substituting the value in count in dd to the amount of MiB you want for your swapfile. I’d go for at least 4096 if you are planning to hibernate (I guess it is a laptop).

Don’t forget to add a corresponding entry to the /etc/fstab as well.