sudo swapon /swapfile error

November 23, 2017 102 views
Applications CentOS

Following tutorial: https://www.digitalocean.com/community/tutorials/additional-recommended-steps-for-new-centos-7-servers

When I get to the swapon command it fiels.

$ sudo swapon /swapfile
swapon: /swapfile: swapon failed: Invalid argument

Docs should be fixed to tell people to use: sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB instead of fallocate. Anyway another tutorial also says its bad idea to use swapfile for SSD systems

1 Answer
gparent November 23, 2017
Accepted Answer

fallocate works fine on other OSes (in fact it's literally recommended in the mkswap man page), so I'm guessing the reason for this is because the root partition is using xfs on the CentOS 7 images.

I'd also agree with you that if you're up to adding 4 gigabytes of swap, you're way better off upgrading the droplet :)

Have another answer? Share your knowledge.