How to deactivate a LVM2 physical volume to remove the drive?
Asked Answered
S

2

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.

Spindly answered 4/8, 2013 at 11:1 Comment(1)
Related: Auto-activate VG on removable HDD reconnectionCeilidh
J
60
lvchange -an <lvpath>
vgchange -an <vgname>

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

dmsetup ls
dmsetup remove <name>
Jaenicke answered 4/8, 2013 at 12:25 Comment(2)
dmsetup ls showed the dm device had already disappeared. Are there any edge cases which need this explicitly?Ceilidh
@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. :)Inherent
J
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.

Jilolo answered 21/2, 2015 at 22:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.