I've entered the following

swapoff -a

This only works until reboot. I'm not sure the best way to permanently disable swaps on Centos. Can anyone advise? thanks


This configuration is stored in /etc/fstab by default in CentOS. You can check and remove your current swap device from that configuration file.


I cribbed this from https://www.refmanual.com/2016/01/08/completely-remove-swap-on-ce7/ with a bit of additional clarification and testing.

First disable swap temporarily:

# swapoff -a

Then remove the LVM volume for the swap:

# lvremove -Ay /dev/centos/swap

You can recover the space used by extending the root volume:

# lvextend -l +100%FREE centos/root

You then need to remove the LVM swap partition from the kernel boot command line by editing the GRUB configuration file in /etc/default/grub to remove the rd.lvm.lv=centos/swap device:

# vi /etc/default/grub
##GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root crashkernel=auto rhgb quiet"

The GRUB configuration needs to be regenerated. On a BIOS boot system:

# grub2-mkconfig -o /etc/grub2.cfg

On a UEFI system:

# grub2-mkconfig -o /etc/grub2-efi.cfg

Edit /etc/fstab to remove or comment out the swap device:

# vi /etc/fstab
/dev/mapper/centos-root  /        xfs    defaults 0 0
#/dev/mapper/centos-swap swap     swap   defaults 0 0

Reboot and your system should come up without any swap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.