大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 part…

问题原文

原帖链接 · asciiphil · CC BY-SA 3.0

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.

已采纳解答

原帖链接 · asciiphil · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-10-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。