Report this

What is the reason for this report?

How To Add Swap on CentOS 7

Posted on December 9, 2019
KFSys

By KFSys

System Administrator

Hi all,

Recently we got a feedback on our tutorial - https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-7

It stated the following :

sudo swapon /swapfile swapon failed: invalid argument

Shout out to @Vault108 for pointing this out! I want to confirm we are in the process of updating the tutorial to avoid this error



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
0

Accepted Answer

This error is created due to the usage of fallocate in the article.

The problem with fallocate 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.

To move forward with this, replace the command that uses fallocate the create the file with this:

sudo dd if=/dev/zero of=/myswap count=4096 bs=1MiB

Once you do, follow every step of the tutorial as it’s written.

Thanks again to @Vault108 for mentioning this!

Regards, KDSys

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.