Site icon NetworkHunt

How to Disable Swap on Linux

How to Disable Swap on Linux

What is Swap?

Swap is the extra virtual memory that a computer uses when it runs out of physical memory (RAM). The Swap partition is stored on the hard drive or secondary memory of your computer, but using swap partitions can slow down the system because hard drives are much slower than RAM. Thus, some users choose to disable swap if their computer has enough RAM and they don’t want the performance of their computer to drop.

Follow the steps below to Disable Swap on your Computer-

  1. Step-1: Check How much Swap is being used on your computer.
  2. Step-2: Find your Swap partition or file.
  3. Step-3: Disable the swap partition.
  4. Step-4 Reboot the System.
  5. Step-5: Verify Swap is Still Disabled
Step-1: Check How much Swap is being used on your computer.

This step is crucial because if you don’t know how much swap is being used on your computer then blindly disabling it may crash the device due to memory deficiency. So to check how much swap is being used, run the command below in a terminal window-

$> free -h

Look for “Swap” in the output,  if the value is 0 or very low then you may safely disable Swap on your computer.

Step-2: Find your Swap partition or file.

To find the swap partition on your system use the command below.

$> sudo swapon --show

If now output is provided by this command, it means that there is no active swap partition on the system.

Step-3: Disable the swap partition.

To temporarily disable a specific swap partition, use the command below.

$> sudo swapoff <partition file>

To disable all available swap partitions, use the command below.

$> sudo swapoff -a

To permanently disable swap on the system, edit the /etc/fstab file and add a hash ‘#’ symbol at the beginning of the swap line. Use command below to edit the file.

$> nano /etc/fstab

To learn more about nano text editor, click here->https://networkhunt.com/how-to-install-nano-text-editor-in-linux/

Step-4: Reboot the System.

After editing the fstab file, reboot your system to apply the changes. Use the command below to reboot.

$> sudo reboot
Step-5: Verify Swap is Still Disabled

After the system restarts, check again if the swap is disabled. Run the commands below to make sure.

$> free -h

$> sudo swapon --show
Exit mobile version