Introduction
This article outlines how you can resize the SWAP on your server. The below examples assume you are using CentOS or another RedHat RHEL-based operating system.
cPanel support can not assist or support enabling SWAP on your server. The procedure below is intended to serve as a guide and involves editing sensitive files that are part of your file system configuration. If you are uncomfortable making the changes, we recommend contacting a qualified System Administrator for detailed assistance.
Procedure
For CentOS, AlmaLinux, and RockyLinux:
- Determine if SWAP is enabled on the server already. The output from the following command can tell you. The output below contains an example SWAP disk image path that will differ on your server. If SWAP is not enabled, the following command will produce no output:
root@server [~] # swapon -s
Filename Type Size Used Priority
/root/cp-swap file 2047996 0 -3 - If SWAP is not yet enabled, follow the instructions in this companion article to create and mount a SWAP disk instead:
How to enable SWAP on your server -
Turn SWAP off so it can be recreated by referring to your server's SWAP disk path:
swapoff /root/cp-swap
-
recreate the disk image as a new size. This example creates an image 1G in size:
dd if=/dev/zero of=/root/cp-swap bs=1M count=1000
- Set permissions on the disk image:
chmod 0600 /root/cp-swap
- Verify that the image was recreated with the proper size and has the proper permissions:
root@server [~] # ls -al /root/cp-swap
-rw------- 1 root root 1048576000 Jan 1 00:55 /root/cp-swap - Before we can use it, we must format the disk image to be useable as SWAP:
mkswap /root/cp-swap
-
We can force the kernel to re-read the partition table so that it is not necessary to perform a reboot:
partprobe
- Now we can enable SWAP using the disk image we recreated:
swapon /root/cp-swap
- We can use the command from Step 1 to verify SWAP is enabled again:
root@server [~] # swapon -s
Filename Type Size Used Priority
/root/cp-swap file 1048572 586304 -2
Resources
How to check available swap space on your server.
Comments
0 comments
Article is closed for comments.