15.7. Removing PCI devices from virtual machines by using the command line


To remove a PCI device from a virtual machine (VM), remove the device information from the XML configuration of the VM.

Procedure

  1. In the XML configuration of the VM to which the PCI device is attached, locate the <address domain> line in the <hostdev> section with the device’s setting.

    # virsh dumpxml <VM-name>
    
    [...]
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x65' slot='0x00' function='0x0'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
    </hostdev>
    [...]
  2. Use the virsh detach-device command with the the --hostdev option and the device address.

    For example, the following command persistently removes the device located in the previous step.

    # virt detach-device <VM-name> --hostdev 0000:65:00.0 --config
    Domain 'VM-name' defined successfully.
    注意

    To remove a PCI device from a running VM, add the --live argument to the previous command.

  3. Optional: Re-attach the PCI device to the host. For example the following command re-attaches the device removed from the VM in the previous step:

    # virsh nodedev-reattach pci_0000_65_00_0
    Device pci_0000_65_00_0 re-attached

Verification

  1. Display the XML configuration of the VM again, and check that the <hostdev> section of the device no longer appears.

    # virsh dumpxml <VM-name>
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部