May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

swapon: swapfile: swapon failed: Invalid argument

fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile

swapon /swapfile
swapon: /swapfile: swapon failed: Invalid argument

echo “/swapfile swap swap sw 0 0” >> /etc/fstab
echo “vm.swappiness = 10” >>/etc/sysctl.conf
echo “vm.vfs_cache_pressure = 50” >> /etc/sysctl.conf

The problem with fallocate(1) is that it uses filesystem ioctls to make the allocation fast and effective, the disadvantage is that it does not physically allocate the space but swapon(2) syscall requires a real space. Reference : https://bugzilla.redhat.com/show_bug.cgi?id=1129205

I had faced this issue earlier with my box too. So instead of using fallocate, I had used dd as per the link suggests
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>