Table of Contents
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.
Delete Volume Group(LVM) in Linux
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
rootuser to run all the below commands.You can use any user with
sudoaccess to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide
sudoaccess 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
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
lvremove /dev/vol_grp/log_grp1 command as shown below. Similarly delete all the logical volume that is associated with Volume group
[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
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