USB is a device-host protocol. So the host, which is likely your operating system requires a host controller interface (which is a piece of hardware).
The host controllers require drivers to run.
There are 3 kinds of USB host controller drivers:
- ohci - Open Host Controller Interface - USB 1
- uhci - Universal Host Controller Interface - USB 1
- ehci - Enhanced Host Controller Interface - USB 2, 1
- xhci - eXtensible Host Controller Interface - USB 3, 2, 1
For more information see: https://gist.github.com/CMCDragonkai/810f78ee29c8fce916d072875f7e1751
When virtualizing USB (such as using QEMU), we need to first virtualize the host controller interface.
For QEMU, this means where is a various options to achieve this.
The
-usb
command line switch adds usb controllers matching the emulated hardware platform. So for the 'pc' machine type (emulating a 20+ year old i440FX chipset) this is a uhci host adapter (supporting usb1). For the 'q35' machine type (emulating a almost 10 year old Q35 chipset) it is ehci (for usb2 devices) with uhci companions (for usb1 devices). This is what you can use when running old guests which lack xhci support. https://www.kraxel.org/blog/2018/08/qemu-usb-tips/
QEMU has a list of virtualized devices for supporting these host controllers: https://en.wikibooks.org/wiki/QEMU/Devices/USB/Root
The most likely options you want is something like this:
-device qemu-xhci,id=xhci -device usb-...,bus=xhci.0
Note that .0
means the port of the interface. Interfaces have a limited number of ports, and it is possible to control them or add more than 1 virtual host controller interfaces.
The rest of the options are located here: https://qemu.weilnetz.de/doc/qemu-doc.html#usb_005fdevices
The only option that involves pass-through from the host to the guest system is usb-host
. The other options are virtualizing the USB device itself.
To passthrough you need the hostbus
and hostaddr
or hostbus
and hostport
or vendorid
and productid
. All of this information can be acquired by lsusb
.
The vendorid
and productid
are hex numbers, so always pass in 0x...
.
3 things though:
-accel kvm
sudo
In the guest machine, it should be possible to see the plugged in device with
lsusb
andlsblk
(if usb mass storage).