Adding swap to your KVM VPS after install

Once you've done this, we suggest limiting the use of SWAP as using a lot of SWAP affects the Disk I/O, we suggest using the maximum amount of RAM as possible.

Please click here to know how to limit the SWAP usage and maximize the use of RAM.

Creating the swap file

The following command creates a 512 MB swap file,

dd if=/dev/zero of=/swapfile1 bs=1024 count=524288

If you're running low on disk space or need a small swap file, create a 128 MB swap file with the following command,

dd if=/dev/zero of=/swapfile1 bs=1024 count=131072

or a 64 MB swap file with the following,

dd if=/dev/zero of=/swapfile1 bs=1024 count=65536

Now setup the swap space

mkswap /swapfile1

Setting up permissions for the swap file

chown root:root /swapfile1
chmod 0600 /swapfile1

Activating the swap file

swapon /swapfile1

Verify that the swap file is activated

free -m

Last Modified: January 09 2018 14:29:05