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.

jdphenix
  • 15,022
  • 3
  • 41
  • 74
user2650268
  • 377
  • 1
  • 3
  • 3
  • Related: [Auto-activate VG on removable HDD reconnection](https://unix.stackexchange.com/q/391798/143394) – Tom Hale Sep 12 '17 at 12:58

2 Answers2

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

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

dmsetup ls
dmsetup remove <name>
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
StianE
  • 3,055
  • 20
  • 20
  • `dmsetup ls` showed the dm device had already disappeared. Are there any edge cases which need this explicitly? – Tom Hale Sep 11 '17 at 07:14
  • @TomHale Based on the trouble I'm running into and the words this article (https://access.redhat.com/solutions/140273), I'm thinking it's a good idea to remove the device from dm before physically removing it. :) – vastlysuperiorman Sep 28 '17 at 17:02
12

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.

zonksoft
  • 2,400
  • 1
  • 24
  • 36