usbqemuhotplugging

How to hotplug an USB device on Qemu 4.2.0?


I have Qemu 4.2.0 with Debian Testing Bullseye and Kernel 5.4.0 and I need to hotplug and unplug an USB device.

Currently I attach my USB device with

qemu... -usb -device usb-host,hostbus=x,hostaddr=y

but when I physically remove the device I can't longer detect it from within the VM (Win7).

So, what should I do to send a plug/unplug usb signal to the virtual machine??


Solution

  • You can do plug/unplug via qemu monitor. see https://en.wikibooks.org/wiki/QEMU/Monitor.

    To hot plug a usb device, type bellow in qemu monitor:

    (qemu) device_add usb-host,hostbus=2,hostport=1.2.2,id=idofyourdevice

    To remove a usb device, type below in qemu monitor:

    (qemu) device_del idofyourdevice