How to Permanently Disable Swap on a WHM/cPanel Server
User
How to turn your swap file off permanently on a WHM/cPanel Linux server.
Note this is also applicable for a normal server with WHM installed.
Assistant
Yes — on most WHM/cPanel Linux servers, swap is made permanent via `/etc/fstab`. To turn it off now and after reboot, comment out the swap line in `/etc/fstab`, then disable current swap.
Run as root.
> ### Command 1 — Check current swap
> swapon --show
> grep -nE 'swap|SWAP' /etc/fstab
> cp -a /etc/fstab "/etc/fstab.backup.$(date +%F-%H%M%S)"
> sed -i '/^[[:space:]]*[^#].*[[:space:]]swap[[:space:]]/ s/^/# disabled swap permanently /' /etc/fstab
> swapoff -a
> systemctl daemon-reload
> swapon --show
> free -h
> grep -nE 'swap|SWAP' /etc/fstab
> systemctl daemon-reload
> swapon --show
> free -h
> grep -nE 'swap|SWAP' /etc/fstab
### Command 2 — Backup /etc/fstab
cp -a /etc/fstab "/etc/fstab.backup.$(date +%F-%H%M%S)"
### Command 3 — Comment out active swap entries in /etc/fstab
sed -i '/^[[:space:]]*[^#].*[[:space:]]swap[[:space:]]/ s/^/# disabled swap permanently /' /etc/fstab
This safely comments out any active swap line, for example:
/swapfile none swap sw 0 0
becomes:
# disabled swap permanently /swapfile none swap sw 0 0
### Command 4 — Turn swap off immediately
swapoff -a
### Command 5 — Reload systemd and verify
systemctl daemon-reload
swapon --show
free -h
grep -nE 'swap|SWAP' /etc/fstab
If swapon --show returns nothing, swap is now off.
Optional — Reboot test
reboot
After reboot:
swapon --show
free -h
If swap is still empty after reboot, it is permanently disabled.
I would not delete the swap file yet. Leave /swapfile in place until you are sure the server is stable without swap.