Linux Tutorials

Disable Swap Partition Permanently on Linux System

On a Linux system with Swap partition or swap file, it is used a temporary storage when physical memory (RAM) space is depleted. When RAM is not available in your system, the inactive memory pages are often dumped into the swap free space. In this article we demonstrate how you can completely disable swap space in your Linux system.

Original content from computingforgeeks.com - post 11172

Running the free command in Linux will show whether swap is enabled in the system.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.5Gi       4.4Gi       2.2Gi        16Mi       856Mi       2.9Gi
Swap:         5.0Gi          0B       5.0Gi

If the swap backend is a block device you can check its path using the command below.

# blkid | grep swap
/dev/mapper/rl-swap: UUID="97f7f3ae-6cac-4fb5-967f-b49ba94c1d53" TYPE="swap"

To immediately disable swap in realtime run:

sudo swapoff -a

Confirm that it’s not active.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.5Gi       3.3Gi       3.4Gi        16Mi       856Mi       4.0Gi
Swap:            0B          0B          0B

To disable swap permanently, remove any entries in /etc/fstab file.

$ sudo vim /etc/fstab
#/dev/mapper/rl-swap     none                    swap    defaults        0 0

You can achieve the same using sed command.

sudo sed -i.bak -r 's/(.+ swap .+)/#\1/' /etc/fstab

Another hack involves using cron job.

$ sudo crontab -e
@reboot sudo swapoff -a  

CloudSpinx Services

CloudSpinx exists to offer you support services on Email solutions of any kind. Contact us now if you need help with installation and configurations, post-install integrations, and continuous support services for your email server services.

Keep reading

Claude Code Cheat Sheet – Commands, Shortcuts, Tips AI Claude Code Cheat Sheet – Commands, Shortcuts, Tips Upgrade Ubuntu 24.04 to Ubuntu 26.04 LTS (Step by Step) Ubuntu Upgrade Ubuntu 24.04 to Ubuntu 26.04 LTS (Step by Step) Open Source LLM Comparison Table (2026) AI Open Source LLM Comparison Table (2026) Install and Use Unsloth Studio for No-Code LLM Fine-Tuning AI Install and Use Unsloth Studio for No-Code LLM Fine-Tuning Fine-Tune an LLM with Unsloth: QLoRA on a Single GPU AI Fine-Tune an LLM with Unsloth: QLoRA on a Single GPU Install Crater Invoicing Solution on Debian 12/11/10 Debian Install Crater Invoicing Solution on Debian 12/11/10

Leave a Comment

Press ESC to close