How to disable swap on Linux

Introduction

Swap is a space on a disk that is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space.

Swap space can take the form of either a dedicated swap partition or a swap file. In most cases, when running Linux on a virtual machine, a swap partition is not present, but in another situation, swap exist on machines.

Some software like Kubernetes requires that swap should be turned off. This article will show to you how to disable swap.

How to disable swap

The easiest way to disable swap is to:

  1. run swapoff -a: this will immediately disable swap
  2. remove any swap entry from /etc/fstab
  3. reboot the system. If the swap is gone, good. If for some reason, it is still here, you had to remove the swap partition. Repeat steps 1 and 2 and, after that, use fdisk or parted to remove the (now unused) swap partition.
  4. reboot

For CentOS it requires to regenerate initramfs with dracut command:

dracut --regenerate-all --force

You can read more linux guides by link https://linuxnotes.org/category/linux-how-to/

Viva La Linux!

Leave A Comment