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.

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.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Unlock the Right Solutions with Confidence

At CloudSpinx, we don’t just offer services - we deliver clarity, direction, and results. Whether you're navigating cloud adoption, scaling infrastructure, or solving DevOps challenges, our seasoned experts help you make smart, strategic decisions with total confidence. Let us turn complexity into opportunity and bring your vision to life.

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

Node.js is an open-source platform built on Chrome’s JavaScript runtime environment to help developers build fast and scalable network applications. […]

You’ll learn how to install Python 3.13 on a CentOS Stream 10 Linux system in today’s tutorial. Python is a […]

Scala programming language is a high-level programming language that is statically typed and supports a fusion of object-oriented programming (OOP) […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.