1. Home
  2. Linux
  3. Disable swap on linux

How to disable SWAP on Linux

The Linux platform uses SWAP as extra memory for system operations. Essentially, if you run out of physical memory, the system will use virtual RAM (AKA SWAP) to ensure that your operating system doesn’t crash and freeze. Without getting too complicated, it’s safe to say SWAP space on Linux is hugely important. So, why would you want to disable it?

The most compelling to reason to disable SWAP is that many don’t need it. The argument is that with larger and larger amounts of RAM in modern systems, users don’t ever use overflow memory.

Another argument against using SWAP is that most computers these days are running on Solid State Drives. Given that SWAP is a partition (or a file in some cases) is accessed a lot, it could potentially wear out SSDs faster.

Suffice it to say, the SWAP debate is a divisive subject in the Linux community, and both sides of the debate have good points. Regardless, if for some reason you find yourself in a position where you do not want SWAP, you’ll need to know how to disable it, and modern Linux OSes don’t make it intuitive or easy.

Due to how complex dealing with SWAP is, we’ve decided to make this guide. In it, we’ll walk you through how to disable the SWAP feature on Linux. Also, we’ll go over how you can permanently delete the SWAP file or partition.

Viewing active SWAP on Linux

Turning of SWAP starts by checking if you have it active on the system. The best way to do this is to check the /proc/swap file. It lists out active devices currently set up as SWAP.

To view the /proc/swaps file, run the cat command. Please note that depending on your system’s setup, you may need to run this command with the sudo command.

cat /proc/swaps

Or, if you need to run it with sudo, do:

sudo cat /proc/swaps

In the readout, you’ll notice the SWAP devices in the file. Depending on your setup, you may have an active partition working, or a Swap file in the root directory.

Need to keep your SWAP readout for quick access later on? Save it to a file by executing:

cat /proc/swaps/ >> ~/swap-info.txt


sudo cat /proc/swaps/ >> /home/username/swap-info.txt

Removing SWAP permanently

Now that you’ve got information about the SWAP devices on your system, you’ll be able to disable it more easily. To start, gain a root shell in the terminal. Having root is critical in this process. You can gain root by executing the su command.

su -

Note: can’t get su? You may be able to work with the sudo -s command instead.

sudo -s

Once you’ve gained root access in the shell, write the swapoff command along with the name of the swap file or partition at the end of the command. For example, to disable your Linux PC’s swap file, you’d write out the following command.

Note: in this example, the SWAP file’s name is “swapfile”. Yours may differ!

swapoff /swapfile

Alternatively, if your Linux PC has a SWAP partition, you’d turn it off with swapoff followed by the name of the partition.

Note: be sure to replace /dev/sdXY with your SWAP partitions label, as shown in /proc/swaps.

swapoff /dev/sdXY

Once you run the swapoff command on your Linux system, you’ll have effectively shut it off. However, SWAP can still turn itself back on upon reboot, unless you delete it from your computer.

To delete SWAP permanently off of your Linux system, follow one of the instructions below.

Deleting the SWAP file

A lot of modern Linux systems have transitioned to using SWAP files. Having a SWAP file is excellent, as it’s much simpler to get rid of, as there is no partition to mess with or re-format.

To disable and delete your SWAP file permanently on Linux, do the following commands.

Note: like mentioned before, the SWAP file in our example is named “swapfile”. Be sure to change the name of the file in the command below if your systems SWAP file’s name differs.

su -

cd /

rm swapfile

Next, open up /etc/fstab and delete the line that specifies your SWAP partition.

nano /etc/fstab

When you’ve completely removed the SWAP file line in /etc/fstab, close the editor with Ctrl + O and Ctrl + X.

Deleting the SWAP partition

Deleting a SWAP partition is a little harder than a SWAP file, as there’s a partition to work with, rather than a single file that can be erased.

To start the partition deletion process, install the Gparted, partition editor. Unsure about how to get it? Head over to this Pkgs.org page. It has a listing of how to get Gparted on nearly every distribution.

Note: if you use Fedora or another Linux distribution that has LVM,  you must delete your SWAP partition with the KDE Partition manager, rather than Gparted, as it allows users to manipulate LVM partitions on the fly.

Once Gparted is installed, launch it. Then, locate your SWAP partition and delete it by right-clicking on the partition, then select the “delete” button in the menu.

With the SWAP partition deleted, click the “Apply” button in Gparted to write the changes. You should then be left with a blank set of free space on your hard drive.

Close Gparted when the changes are applied and launch a terminal. In the terminal, open your /etc/fstab file in Nano.

sudo nano /etc/fstab

Using the Nano editor, delete the line that refers to your SWAP partition. Then, save it with Ctrl + O and exit the editor with Ctrl + X.

Regenerate Linux boot image files

Now that SWAP is gone, it’s critical that you regenerate your Linux boot image. Keep in mind that this is going to change depending on the distribution you use.

  • Ubuntu: sudo update-initramfs -u
  • Debian: sudo update-initramfs -u
  • Arch Linux: sudo mkinitcpio -p linux
  • Fedora: sudo dracut --regenerate-all --force
  • OpenSUSE: sudo mkinitrd

When the initramfs update is complete, reboot your PC, and your SWAP partition will be gone!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.