Automatic creation of SWAP on Linux – VULTR VPS

After writing the article How do I add a swap partition in Linux Centos on VPS VULTR was faced with the fact that some users are having difficulty with creating a swap file. Decided to write a little script, but rather a set of commands to fully automate the process.
Automatically create swap file in CentOS


If you got a server without partition or swap file, to restore justice, namely to create the SWAP size is 512 MB, run the following code in the console with root privileges:


Copy the entire text and paste into the console at once. It is not necessary to enter all commands individually.


Then restart the MySQL server reboot and make sure that everything works.


Description of the used script commands, that is that what does, read the previous article How do I add a swap partition in Linux Centos on VPS VULTR.
Testing and where it works


I tested this code on the virtual server of VULTR. It should also run on other virtual servers with hardware virtualization system type of KVM and VmWare. Of course it works on dedicated servers.


The script will not run on virtual servers for virtualization OpenVZ. But here the case is not in the script, and that you cannot create by definition OpenVZ a virtual memory file.


The script checks for the existence of virtual memory as a swap partition and the swap file. Please check with the commands:



It is desirable to make this test and after the script and the server restarts, make sure that everything works.
In particular the swapon-s must issue the following

Leave a Reply

Your email address will not be published. Required fields are marked *