Disable and remove swap

Updated: 2022-04-02

There are two types of swap in Linux: swap partitions and swap files.

The OS I chose to disable swap on is Ubuntu, but I think this will work under any Linux distribution (at least under Debian derived distributions).

  1. List the active swaps
swapon --show

This will show you which type of swap you have in your system that will be used in the next step.

An example output:

NAME      TYPE       SIZE USED PRIO
/dev/sdb1 partition 14,9G 3,7M   -2
  1. Disable swap for current session

If the swap is found on a partition, run:

sudo swapoff /dev/sdb1

Or if the swap is found within a file, run:

sudo swapoff /swapfile

Then

sudo rm /swapfile

Note: After you run the command above you must run the 3rd step or your system might fail to boot!

  1. Remove swap at boot

The swap info is found in /etc/fstab file.

sudo nano /etc/fstab

Search for the line that has swap text in it and comment it out.

Example:

UUID=606c8e0e-f961-495b-98a4-1034ad079341 none swap    defaults        0 0

becomes

# UUID=606c8e0e-f961-495b-98a4-1034ad079341 none swap    defaults        0 0

Resources: