Introduction
If you wish to enable or recreate SWAP on your server, there are a handful of methods that can be used. The below examples assume you are using CentOS or RedHat RHEL OS.
Caution: cPanel support can not assist or support enabling SWAP on your server. The commands below are intended to show a method to accomplish it and to be used as a reference.
Procedure
For Centos (swapfile):
First, determine if SWAP is enabled on the server already. The output from the following command can tell you.
SWAP not enabled:
# swapon -s
No Output
If SWAP is not enabled, then used these commands CREATE it.
Using example swap mount point: /root/cp-swap, first create the disk image.
dd if=/dev/zero of=/root/cp-swap bs=1M count=2000
Then, set permissions on the disk image.
chmod 0600 /root/cp-swap
Now, verify the file exists and has the correct permissions.
ls -al /root/cp-swap
Then, format the disk image.
mkswap /root/cp-swap
After that, enable the system to use the swap space.
swapon /root/cp-swap
Finally, verify swap is enabled by running this command.
swapon -s
To make the change permanent, add the following line to your /etc/fstab file.
/root/cp-swap swap swap defaults 0 0
Please use extreme caution when modifying the /etc/fstab file. It is responsible for the mounting of the partitions on the server. If unfamiliar with the file, we would recommend having a qualified System Adminstor make the change.
Where do I find a system administrator?
----
If SWAP is already enabled, and you want to recreate it as a different size, you can use these commands:
First, check if SWAP is enabled:
SWAP is enabled:
# swapon -s
Filename Type Size Used Priority
/root/cp-swap file 1048572 107520 -2
Turn SWAP off so it can be recreated.
swapoff /root/cp-swap
Using example swap mount point: /root/cp-swap, recreate the disk image as a new size. Example 1G.
dd if=/dev/zero of=/root/cp-swap bs=1M count=1000
Then, set permissions on the disk image.
chmod 0600 /root/cp-swap
Now, verify the file exists and has the correct permissions.
ls -al /root/cp-swap
Then, format the disk image.
mkswap /root/cp-swap
Force the kernel to re-read the partition table so that it is not necessary to perform a reboot.
partprobe
After that, enable the system to use the swap space.
swapon /root/cp-swap
Finally, verify swap is enabled by running this command.
swapon -s
----
RedHat Enterprise Linux (LVM)
RedHat has multiple ways of enabling swap. Please refer to their documentation for instructions.
Resources
How to check available swap space on your server.