How can I tell Linux to ignore disk partitions it's already discovered?

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 work


You 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:

dmsetup remove /dev/mapper/vg_hostname_vms-lv_vm1p2

This will cause vm1's PV, VG, and LVs to disappear from the host's LVM tools.