Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deactivate a LVM2 physical volume to remove the drive?

Tags:

linux

lvm

volume

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.

like image 290
user2650268 Avatar asked Aug 04 '13 11:08

user2650268


People also ask

How do you remove a physical volume from a volume group?

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.

How can you remove physical volume Dev sde1?

Use the vgreduce command to remove the physical volume /dev/sdb1 from the volume group.

How do you deactivate LV?

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.


2 Answers

lvchange -an <lvpath> vgchange -an <vgname> 

If you also want to remove the device maps you can use

dmsetup ls dmsetup remove <name> 
like image 112
StianE Avatar answered Sep 19 '22 16:09

StianE


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.

like image 30
zonksoft Avatar answered Sep 20 '22 16:09

zonksoft