quickemu-project / quickemu

Quickly create and run optimised Windows, macOS and Linux virtual machines
MIT License
10.44k stars 456 forks source link

How to pass through USB devices not present at startup #828

Closed dsseng closed 4 months ago

dsseng commented 10 months ago

Expected behaviour

I can list USB device IDs to be passed through automatically, even if devices are not present when the VM starts.

Actual behaviour

Only devices present at launch will be available. However, if I replug those, they reconnect to the VM.

Steps to reproduce the behaviour

Add usb_devices=("2500:0021", "0bda:0169") or equivalent to the config, have none or only one of the devices plugged in when launching the VM.

Quickemu output

Quickemu 4.8 using /usr/bin/qemu-system-x86_64 v7.2.6
 - Host:     "Fedora release 38 (Thirty Eight)" running Linux 6.5 (arcturus)
 - CPU:       AMD Ryzen 5 4500U with Radeon Graphics
 - CPU VM:   1 Socket(s), 4 Core(s), 1 Thread(s), 4G RAM
 - EFI:      WARNING! /usr/share/OVMF/OVMF_CODE.fd is a symlink.
             Resolving to... /usr/share/edk2/ovmf/OVMF_CODE.fd
 - BOOT:     EFI (Linux), OVMF (/usr/share/edk2/ovmf/OVMF_CODE.fd), SecureBoot (off).
 - Disk:     tw2/disk.qcow2 (16G)
 - Display:  SDL, virtio-vga-gl, GL (on), VirGL (on)
 - Sound:    intel-hda
 - ssh:      On host:  ssh user@localhost -p 22220
 - WebDAV:   On guest: dav://localhost:9843/
 - 9P:       On guest: sudo mount -t 9p -o trans=virtio,version=9p2000.L,msize=104857600 Public-sh7dm ~/Public
 - USB:      Host pass-through requested:
             o Ettus Research LLC USRP B200-mini on bus 003 device 011 is accessible.
             ! USB device 0bda:0169 not found. Check your configuration
 - TPM:      tw2/tw2.swtpm-sock (569124)
 - Network:  Bridged (virbr0)
 - Monitor:  On host:  nc -U "tw2/tw2-monitor.socket"
             or     :  socat -,echo=0,icanon=0 unix-connect:tw2/tw2-monitor.socket
 - Serial:   On host:  nc -U "tw2/tw2-serial.socket"
             or     :  socat -,echo=0,icanon=0 unix-connect:tw2/tw2-serial.socket
 - Process:  Starting tw2.conf as tw2 (569127)

Linux Distribution & Kernel

LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description:    Fedora release 38 (Thirty Eight)
Release:        38
Codename:       ThirtyEight
Linux arcturus 6.5.0-257.vanilla.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Aug 28 05:29:59 UTC 2023 x86_64 GNU/Linux

Notes

As seen on https://github.com/quickemu-project/quickemu/blob/master/quickemu#L167 it bails out when no device is found. QEMU however is able to bind devices by their USB IDs, so this can be used.

dsseng commented 10 months ago

Another benefit would be better support for devices like B200-mini, which re-appear on bus after firmware loading. As I currently have whole setup, including firmware, inside the VM, I have to boot it twice after the device has been plugged, because after firmware upload it reappears with same ID but on USB3 bus.

This device boots without FPGA firmware and establishes an HS link. Software uploads FPGA image which makes controller setup SuperSpeed link, which moves the device to a different bus. Quite annoying to handle. Haven't yet tried with plain QEMU.

flexiondotorg commented 4 months ago

This is already possible.

Start your virtual machine using --display spice and this will enable clipboard sharing and advanced USB redirection. See the section in the Wiki about USB Redirection

You might also be interested in the SPICE viewer feature to automatically redirect newly connected USB devices, available via: