14.2. Attaching and Updating a Device with virsh

download PDF
For information on attaching storage devices refer to Section 13.3.1, “Adding File-based Storage to a Guest”

Procedure 14.1. Hot plugging USB devices for use by the guest virtual machine

The following procedure demonstrates how to attach USB devices to the guest virtual machine. This can be done while the guest virtual machine is running as a hotplug procedure or it can be done while the guest is shutoff. The device you want to emulate needs to be attached to the host physical machine.
  1. Locate the USB device you want to attach with the following command:
    # lsusb -v
    idVendor           0x17ef Lenovo
    idProduct          0x480f Integrated Webcam [R5U877]
  2. 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'>
            <vendor id='0x17ef'/>
            <product id='0x480f'/>

    Figure 14.1. USB Devices XML Snippet

  3. Attach the device with the following command:
    # virsh attach-device rhel6 --file usb_device.xml --config
    In 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 --config option. If you want this change to be persistent, use the --persistent option. If you want the change to take effect on the current domain, use the --current option. See the Virsh man page for additional information.
  4. If you want to detach the device (hot unplug), perform the following command:
    # virsh detach-device rhel6 --file usb_device.xml
    In this example [rhel6] is the name of your guest virtual machine and [usb_device.xml] is the file you attached in the previous step
Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.