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!

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

12 Useful “df” Commands to Check Disk Space in Linux

Useful df Command Examples This article explain a way to get the full information of Linux disk...

How to Disable SELinux

How to Disable SELinux You’ve setup a new system, or installed something new on your Linux...

How to set a Static IP in Ubuntu Linux

How to set a Static IP in Ubuntu LinuxOpen the terminal command line application or ssh into the...

Linux Check Disk Space Command To View System Disk Usage

Linux Check Disk Space Command To View System Disk Usage Linux command to check disk space...