1

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??

downtheroad
  • 409
  • 4
  • 11

1 Answers1

2

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 bellow in qemu monitor:

(qemu) device_del idofyourdevice

Changbin Du
  • 501
  • 5
  • 11
  • 2
    thanks for answering, but I couldn't make it work, where did you get `1.2.2`? from `lsusb -t` ? – downtheroad Mar 24 '20 at 22:30
  • With Windows 7 guest didn't work but with Windows 10 did, thanks! – downtheroad Mar 30 '20 at 13:19
  • lsusb -t so the 1.2.2 is probably two hubs in the path of the device. For devices behind hubs we use the dot notation to represent the tree. – Drakes Jan 10 '21 at 02:16
  • 1
    This answer does not provide any specific example or context information about where to use the command. – Jonathan Ben-Avraham Nov 17 '22 at 08:15
  • @JonathanBen-Avraham the monitor can be accessed via a unix socket or telnet (maybe some more ways too. To bring up a telnet server you might start qemu with `-monitor telnet:192.168.1.128:5555,server,nowait` or similar. Then when the VM is running you can connect with `telnet 192.168.1.128 5555` and you'll get the qemu monitor prompt. – Johnny Haddock Jun 14 '23 at 09:02