If the LVM volume (logical volume) is no longer required to be used by the LVM (Logical Volume Manager) on the system, you can remove/delete it with the ‘lvremove’ command following the steps below.
But make sure the LVM volume does not contain any data. If it does, make sure to back up that data before proceeding with the LVM removal.
To demonstrate this, in our use-case we will remove
“lv001” from the volume group
“vg01”. The LV is mounted on the mount point
Please go through the below articles (Part-1 to 4) if you need some background knowledge on LVM:
- Part-1: How to Create/Configure LVM (Logical Volume Management) in Linux
- Part-2: How to Extend/Increase LVM’s (Logical Volume Resize) in Linux
- Part-3: How to Reduce/Shrink LVM’s (Logical Volume Resize) in Linux
- Part-4: How to Remove Physical Volume from a Volume Group in LVM
Let’s begin our use-case:
Use the df command to check if your LV (Logical Volume) contains any data. If yes, then backup the data.
Backup can be done in many ways, but you can perform it based on your requirements and the resources available in your environment.
# df -h /lvmtest Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg01-lv001 15360M 34M 15326M 4% /lvmtest
Alternatively, you can verify this using the ‘lvs’ or ‘lvdisplay’ command as follows:
# lvs or # lvdisplay /dev/mapper/vg01-lv001
Firstly, delete the entry of the mount point from the /etc/fstab file:
# vi /etc/fstab … /dev/mapper/vg01-lv001 /lvmtest ext4 defaults 0 0 …
Unmount the mount point using the umount command:
# umount /lvmtest
Disable the “lv001” logical volume:
# lvchange -an /dev/vg01/lv001 or # lvchange -an /dev/mapper/vg01-lv001
Finally, delete the “lv001” logical volume:
# lvremove /dev/vg01/lv001 or # lvremove /dev/mapper/vg01-lv001 Do you really want to remove active logical volume "lv001"? [y/n]: y Logical volume "lv001" successfully removed
If there are no logical volumes associated with the volume group(VG) and if the VG is no longer required, then remove that as well.
Disable the “vg01” volume group as shown below:
# vgchange -an vg01
Delete the “vg01” volume group:
# vgremove vg01 Volume group "officevg" successfully removed
Delete physical volumes used for volume group “vg01”:
# pvremove /dev/sdb /dev/sdc Labels on physical volume "/dev/sdb" successfully wiped. Labels on physical volume "/dev/sdc" successfully wiped.
In this guide, we’ve shown you how to Delete/Remove LV (Logical Volume) in Linux and also to remove the VG’s (Volume Groups) if they are no longer required.
If you found this article helpful, please do share with your friends and spread the knowledge. Please feel free to comment below if you have any queries/concerns. We will get back to you as soon as we can. Happy learning!