14.2. Attaching and Updating a Device with virsh
Procedure 14.1. Hot plugging USB devices for use by the guest virtual machine
- Locate the USB device you want to attach with the following command:
# lsusb -v idVendor 0x17ef Lenovo idProduct 0x480f Integrated Webcam [R5U877]
- Create an XML file and give it a logical name (
usb_device.xml, for example). Make sure you copy the vendor and product IDs exactly as was displayed in your search.
<hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x17ef'/> <product id='0x480f'/> </source> </hostdev> ...
Figure 14.1. USB Devices XML Snippet
- Attach the device with the following command:
# virsh attach-device rhel6
--configIn this example [rhel6] is the name of your guest virtual machine and [usb_device.xml] is the file you created in the previous step. If you want to have the change take effect in the next reboot, use the
--configoption. If you want this change to be persistent, use the
--persistentoption. If you want the change to take effect on the current domain, use the
--currentoption. See the Virsh man page for additional information.
- If you want to detach the device (hot unplug), perform the following command:
# virsh detach-device rhel6
--file usb_device.xmlIn this example [rhel6] is the name of your guest virtual machine and [usb_device.xml] is the file you attached in the previous step