Removing mount point and detaching LVM 📁 🔌

To remove a mount point and detach the logical volume and physical volume we need to follow these steps. First we have to unmount the mounted directory, then make the logical volume status to unavailble, then detach the logical volume. After that you have reduce the volume group if you want to remove the physical volume also but other physical volumes will be attached to that VG. And, if you want to remove all the PVs then you also have remove the VG. So, first unmount, then remove LV, then either reduce VG or remove VG, then finally remove the PV.

1. Unmounting

umount /mnt/data

2. Making LV status unavailble

lvchange -an /dev/VG-NAME/LV-NAME
  • here in -an flag a is for availability state and n is for not available

3. Detaching the LV

lvremove /dev/vg_data/lv_data

4. To reduce the VG

vgreduce VG-NAME /PV/NAME

ex: /dev/sda1

5. TO remove VG completly

vgremove VG-NAME

6. Finally removing the PV

pvremove /PV/NAME

ex: /dev/sda1

Conclusion

These steps are crucial to follow before removing any Physical Volume, as without this data may be corrupted or a constant error will show while listing LVM components with vgs , pvs commands ⚠️ 🚨.