Remove LVM Volume

How to remove a volume from lvm

check if lv is still mounted

$ df -hTP | grep test                                                                                          
/dev/mapper/datavg-testlv ext4      9.9G    4.5M  9.4G    1% /mnt/test

check with lsof if there are open files pointing on the volume. if yes close them

get id with lsblk

$ lsblk | grep test                                                                                                
└─datavg-testlv                               254:4    0    10G  0 lvm   /mnt/test

check with lsof (in this case we fount the id 254:4 with lsblk which will be 254,4 for lsof)

#if we get empty response, there are no open files
$ lsof | grep "254,4"                                                                                   

$ lsof /mnt/test                                                                                        

Remove all mount entries from /etc/fstab

# check for entries
$ grep test /etc/fstab                                                                                           
/dev/mapper/datavg-testlv /mnt/test ext4 defaults 0 0
#we get an entry so we open /etc/fstab and remove it
$ vim /etc/fstab

umount the volume

umount -f /mnt/test

now we can start the removal. if lvremove still sees open files, reboot the machine and everything will be closed

$ lvremove /dev/mapper/datavg-testlv                                                                               
Do you really want to remove active logical volume datavg/testlv? [y/n]: y
  Logical volume "testlv" successfully removed.

if needed we can now remove the volume group too. can only be done if there are no other logical volumes

$ vgremove datavg

and remove the physical volume

pvremove /dev/sdx

Leave a Reply

Your email address will not be published. Required fields are marked *