Create SWAP in Existing Server

You can create a swap file and add new swap space in Linux by the following way.


Create 4 GB SWAP:

dd if=/dev/zero of=/swapfile bs=1024 count=4194304


Or, Create 8 GB SWAP:

dd if=/dev/zero of=/swapfile bs=1024 count=8388608


Or, Create 16 GB (Maximum) SWAP:

dd if=/dev/zero of=/swapfile bs=1024 count=16777216


Set the file permission;

chmod 600 /swapfile


Add swap partition;

mkswap /swapfile


Enable swap in the server;

swapon /swapfile


Enable swap on startup; nano /etc/fstab

/swapfile none swap sw 0 0


Enjoy the swap space, reboot the server.

Post a Comment