36

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.

1

2 Answers 2

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

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

dmsetup ls
dmsetup remove <name>
2
  • 1
    dmsetup ls showed the dm device had already disappeared. Are there any edge cases which need this explicitly?
    – Tom Hale
    Commented Sep 11, 2017 at 7:14
  • @TomHale Based on the trouble I'm running into and the words this article (access.redhat.com/solutions/140273), I'm thinking it's a good idea to remove the device from dm before physically removing it. :) Commented Sep 28, 2017 at 17:02
13

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.