How can I shut down/"unmount" a Linux lvm2 physical volume?
I plugged an external had drive to my computer. On the drive is a LVM2 PV with one volume group which has some logical volumes. I now want to remove this drive again properly.
I unmounted the filesystems, deactivated all logical volumes and the volume group.
How can I deactivate the physical volume? Or make the PV and the VG unknown to Linux again? Like just the opposite of lvmdiskscan and vgchange -a y ?
I want to leave the PV/VG and LVs on the disk intact.
To remove unused physical volumes from a volume group, use the vgreduce command. The vgreduce command shrinks a volume group's capacity by removing one or more empty physical volumes. This frees those physical volumes to be used in different volume groups or to be removed from the system.
Use the vgreduce command to remove the physical volume /dev/sdb1 from the volume group.
To remove an inactive logical volume, use the lvremove command. You must close a logical volume with the umount command before it can be removed. In addition, in a clustered environment you must deactivate a logical volume before it can be removed.
lvchange -an <lvpath> vgchange -an <vgname>
If you also want to remove the device maps you can use
dmsetup ls dmsetup remove <name>
I do
vgchange -an <vgpath>
before I remove the disk and
vgchange -ay <vgpath>
after I connected it again. Otherwise, any LVM display command will produce input/output errors, and the partition will not be mountable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With