Linux Administrator

How to Safely Delete Swap on Linux System

Swap is used when the amount of Random Access Memory (RAM) is full. Swap space is a portion of a hard disk drive (HDD) that is used for virtual memory. Virtual memory is the use of space on a HDD to simulate additional main memory. Memory is used to hold portions of the operating system, programs and data that are currently in use or that are frequently used.

In this article I will show you how to safely delete Swap on Linux system.

Some time you need to delete your swap partition most of cases when your swap partition configured on LVM and you are unable to increase swap size because there is no space left on volume group.

Recently I faced on issue where my swap partition was configured on LVM. There are two volume group was create on system as shown below.

# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  vg0    1   2   0 wz--n- 10.1g 1.1g
  vg1    2   4   0 wz--n- 20.2g 10.1g

Now lets see the logical volume details.

# lvs
  LV                   VG   Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  opt_bak              vg0  -wi-ao----  9.00g
  swap                 vg0  -wi-ao----  4.00g

As above you can see 4GB swap lv created on vg0 and I want to increase swap size to 4GB to 6GB but unable to increase swap lv becasue there is no sufficient space available in vg0 that’s why I decide to delete swap lv and recreate it using vg1 because there are 10GB space is available in vg1.

Safely Delete Swap

1. Open your terminal and access your server with root privileges.

2. Edit /etc/fstab and delete or comment out the line that has swap mounted automatically at boot.

# vim /etc/fstab
#/dev/mapper/swap swap                    swap    defaults        0 0 

3. Turn off the already-mounted swap for this session so that the next step doesn’t result in an error.

# swapoff -a

4. Now lets delete the swap volume permanently.

# lvremove /dev/mapper/swap

Congratulation! swap LV has been remove safely.

Follow the below link to create Logical Volume for Swap.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment