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
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> [...]Use the
virsh detach-devicecommand with the the--hostdevoption 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
--liveargument to the previous command.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
Display the XML configuration of the VM again, and check that the
<hostdev>section of the device no longer appears.# virsh dumpxml <VM-name>