How to Increase Swap Memory on Linux/cPanel

How to Increase Swap Memory on Linux/cPanel

How to add Swap Memory on cPanel Server?

First of all, need to disable swap so the usage of swap move to main memory.
Before running this command, make it sure that your mem free space is larger that
the swap by using free -m command. If free showing larger than Swap used, then rung this command:

swapoff -a

This will take some time, once command prompt free, check if swap available?

free -m

You will see 0 swap memory, now use this command to create swap file: (I am creating 8 GB swap, so you can change it as per your need)

dd if=/dev/zero of=/swapfile bs=1G count=8

Now apply the correct permission to this file with this command:

chmod 0600 /swapfile

Now need to set this file as swap, so run this command:

mkswap /swapfile

Now we need to enable Swap again, this command will be used:

swapon /swapfile

Now check if swap is in use? run this:

free -m

You will see that your created swap memory is in use.

To make this work on reboot, add this in fstab:

vi /etc/fstab

at the end of the file, add these lines: (press i to enable editing)

/swapfile swap swap sw 0 0

All done!

Post Your Comment

Build Your Website with 2COHOST

Your dream website is waiting for you, just few clicks ahead.

Our web hosting company 2COHOST was established in 2015 and we are serving with quality of services to our valuable customers.

Contact Us