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.

Your IT Journey Starts Here!

Ready to level up your IT skills? Our new eLearning platform is coming soon to help you master the latest technologies.

Be the first to know when we launch! Join our waitlist now.

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

Recent Post

Leave a Comment

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

Related Post

For most system admins, their day-to-day life activities revolve around having access to remote systems.VNC an acronym for Virtual Network […]

PostgreSQL is an open-source object-relational database management system (ORDBMS) based on POSTGRES, Version 4.2. Postgresql was developed at the University […]

Today’s tutorial will show you how to install WordPress with Apache and Let’s Encrypt on an Ubuntu 24.04|22.04 Linux system […]

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.