Cyberithub

How to Delete Volume Group(LVM) in Linux Using 5 Easy Steps

Advertisements

In this article, I will take you through the steps to delete Volume Group in Linux. Volume group is a logical aggregation of physical volumes in LVM(Logical Volume Manager) Technology. This acts as a storage reservoir in LVM where the storage can be added by adding multiple physical volumes and it can be assigned as well by creating multiple logical volumes. Volume Group provides an abstraction Layer in LVM which allows us to manage the free spaces of multiple storage disks in an effective manner.

How to Delete Volume Group(LVM) in Linux Using 5 Easy Steps 1

Delete Volume Group(LVM) in Linux

Also Read: How to List/Get/Display/Find MAC Address in Linux Using 11 Popular Methods

1. Check mounted Logical Volume using df command

First you need to check the mounted volume and the mount point name using df -h command. Here you can see that log_grp1 is currently mounted on /u01 mount point. To know more about LVM configuration you can check on How to configure LVM (pvcreate, vgcreate and lvcreate ) in Linux Using 6 Easy Steps.

[root@localhost ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     484M   0   484M   0%   /dev
tmpfs                        496M   0   496M   0%  /dev/shm
tmpfs                        496M  6.8M 489M   2%   /run
tmpfs                        496M   0   496M   0%  /sys/fs/cgroup
/dev/mapper/centos-root      37G   1.5G 36G    4%    /
/dev/sda1                    1014M 193M 822M   19%  /boot
tmpfs                        100M   0   100M   0%   /run/user/0
/dev/mapper/vol_grp-log_grp1 384M  2.3M 358M   1%   /u01

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to User.

2. Unmount the Volume using umount command

Once you identified the mount point, you need to remove it by using umount /u01 command as shown below.

[root@localhost ~]# umount /u01

After unmounting the logical volume you can further check if there are any other active logical volumes of volume group vol_grp1 is currently mounted.

[root@localhost ~]# df -h
Filesystem              Size  Used Avail Use% Mounted on
devtmpfs                484M   0   484M   0%   /dev
tmpfs                   496M   0   496M   0%  /dev/shm
tmpfs                   496M  6.8M 489M   2%  /run
tmpfs                   496M   0   496M   0%  /sys/fs/cgroup
/dev/mapper/centos-root 37G   1.5G 36G    4%    /
/dev/sda1               1014M 193M 822M  19%  /boot
tmpfs                   100M   0   100M   0%  /run/user/0

Once everything is verified, you can safely remove any entry from /etc/fstab if available. This will make sure that System will not try to mount something which is unavailable.

[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Apr 23 12:36:31 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=1e70f026-ce6f-4938-a74c-ec9c5f6ce74a /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
#/dev/sdb1 swap swap defaults 0 0
#/root/testswap swap swap defaults 0 0
#/dev/vol_grp/log_vol swap swap defaults 0 0

3. Disable Logical Volume using lvchange command

Now to we need to disable all the associated logical volume before moving ahead and delete volume group from the System. You can disable the logical volume log_grp1 by using lvchange -an /dev/vol_grp/log_grp1 command as shown below.

[root@localhost ~]# lvchange -an /dev/vol_grp/log_grp1

Check Logical Volume status using lvscan command. You can check from below output log_grp1 is now showing in inactive state. Similarly you need to disable all the logical volume associated with Volume Group vol_grp using lvchange command as shown above.

[root@localhost ~]# lvscan
ACTIVE '/dev/vol_grp/log_vol1' [12.00 MiB] inherit
ACTIVE '/dev/vol_grp/log_grp' [2.00 GiB] inherit
inactive '/dev/vol_grp/log_grp1' [400.00 MiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [36.99 GiB] inherit

4. Delete Logical Volume using lvremove command

Now delete the logical volume log_grp1 using lvremove /dev/vol_grp/log_grp1 command as shown below. Similarly delete all the logical volume that is associated with Volume group vol_grp using lvremove command.

[root@localhost ~]# lvremove /dev/vol_grp/log_grp1
Logical volume "log_grp1" successfully removed

Check Logical Volume Status again by running lvscan command. You can see from below output log_grp1 does not exists now and hence it is removed.

[root@localhost ~]# lvscan
ACTIVE '/dev/vol_grp/log_vol1' [12.00 MiB] inherit
ACTIVE '/dev/vol_grp/log_grp' [2.00 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [36.99 GiB] inherit

5. Delete Volume Group using vgremove command

Once all the Logical Volume are deleted you can now delete volume Group vol_grp using vgremove vol_grp command as shown below.

[root@localhost ~]# vgremove vol_grp
  Volume group "vol_grp" successfully removed

To verify you can run vgscan and get confirmed if vol_grp is removed or not. As you can see from below output vol_grp does not exists now.

[root@localhost ~]# vgscan
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2

 

 

Popular Recommendations:-

Create KVM Virtual machine using Cockpit UI RHEL CentOS 7/8

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)

9 useful w command in Linux with Examples

12 Most Popular rm command in Linux with Examples

8 Useful Linux watch command examples (RedHat/CentOS 7/8)

25 Useful Linux SS Command Examples to Monitor Network Connections

Leave a Comment