I'm running libvirt with QEMU/KVM and I have disk images for the VMs in LVM logical volumes. Naturally, many of the guest VMs use LVM for their disks, too.
I ran partprobe
on my hypervisor and it detected all of the VM guest partitions, so now the LVM tools (pvs
, vgs
, lvs
, etc.) list all of the guest's LVM entities along with the host's.
Is there a way to remove all of these LVM physical volumes from the host's knowledge (without affecting the guests, of course)? Rebooting the host isn't an option; several of these VMs need to stay running.
In case it helps, here's what the LVM layers look like, more or less:
/dev/sdb1 - host PV
|
vg_hostname_vms - host VG
|
+-lv_vm1 - host LV, used as a disk image for vm1
| +-part1 - vm1 boot partition
| +-part2 - vm1 PV
| |
| vg_vm1 - vm1 VG
| +-lv_root - vm1 LV - /
| +-lv_swap - vm1 LV - swap
|
+-lv_vm2 - host LV, used as a disk image for vm2
+-part1 - vm1 boot partition
+-part2 - vm2 PV
|
vg_vm2
+-lv_root - vm2 LV - /
+-lv_swap - vm2 LV - swap
+-lv_home - vm2 LV - /home
Now, when I run vgs
, here's what I see:
VG #PV #LV #SN Attr VSize VFree
vg_hostname_vms 1 2 0 wz--n- 10.91t 9.53t
vg_vm1 1 2 0 wz--n- 9.76g 0
vg_vm2 1 3 0 wz--n- 97.16g 0
I only want to see the host's volume groups (and only its physical and logical volumes).
I'm running all of this on a Scientific Linux 6.5 host. The guest OSes vary.
You should set up an LVM filter on the host, to filter out the unwanted LVM devices detected. Here's a link to the official documentation:
http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/lvm_filters.html
something like
filter = [ "r|/dev/VM_related_VG/*|" ]
should workYou can get rid of the guest PVs with the low-level
dmsetup
command.To remove the device associated with partition 2 on vm1's disk image, run:
This will cause vm1's PV, VG, and LVs to disappear from the host's LVM tools.
I had a similar issue and solved it with an LVM filter defined in the
devices
section of the LVM configuration file/etc/lvm/lvm.conf
:In my case I want to allow PVs whose device pathname starts with
/dev/sd
or with/dev/nvme
and finally reject all the rest.I have used
global_filter
instead offilter
in order to make sure the filter applies always.