Difference between revisions of "Linux/Virtualization/Usb"

From Iveze
Jump to: navigation, search
(Created page with "Usb Category:Linux Category:Hardware")
 
Line 1: Line 1:
Usb
+
If a USB device is plugged in a host machine, it needs to know what to do with it. Should the host itself use it, or should it be forwarded to a guest, and if so to which guest?
 +
 
 +
=== Forward USB ===
 +
A USB device can be forwarded to a guest by vendor id and product id. This works well if there is only one device of a certain model ever plugged into the host.
 +
 
 +
The vendor id and product id can be obtained with lsusb (if not available, [[Linux/Install/Software|install]] usbutils). There will be several lines like this:<blockquote>Bus 002 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply</blockquote>In this line the vendor id is 051d and the product id is 0002. From the description you can make out which line you are looking for.
 +
 
 +
Now a sub-definition of the guest's definition must be written in a file, containing the vendor and product id.
 +
<hostdev mode="subsystem" type="usb"><br>
 +
    <source startupPolicy="optional"><br>
 +
        <vendor id="0x051d"/><br>
 +
        <product id="0x0002"/><br>
 +
    </source><br>
 +
</hostdev>
 +
Assuming the file is called ups.xml This file can be used to attach or detach the usb device.
 +
virsh attach-device guestname ups.xml
 +
or
 +
virsh detach-device guestname ups.xml
 
[[Category:Linux]]
 
[[Category:Linux]]
 
[[Category:Hardware]]
 
[[Category:Hardware]]

Revision as of 15:53, 13 June 2015

If a USB device is plugged in a host machine, it needs to know what to do with it. Should the host itself use it, or should it be forwarded to a guest, and if so to which guest?

Forward USB

A USB device can be forwarded to a guest by vendor id and product id. This works well if there is only one device of a certain model ever plugged into the host.

The vendor id and product id can be obtained with lsusb (if not available, install usbutils). There will be several lines like this:
Bus 002 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
In this line the vendor id is 051d and the product id is 0002. From the description you can make out which line you are looking for.

Now a sub-definition of the guest's definition must be written in a file, containing the vendor and product id.

<hostdev mode="subsystem" type="usb">
<source startupPolicy="optional">
<vendor id="0x051d"/>
<product id="0x0002"/>
</source>
</hostdev>

Assuming the file is called ups.xml This file can be used to attach or detach the usb device.

virsh attach-device guestname ups.xml

or

virsh detach-device guestname ups.xml