How to make devices (i.e. USBs and peripherals) hotpluggable in Virt-Manager & putting an entire USB hub in the VM?

EDIT: I found startupPolicy="optional", but after boot, the devices don’t “plug in” to the VM unless I restart. Also, this answer from StackExchange didn’t work for me.

By default, Virt-Manger doesn’t seem to let you boot a VM if a USB device isn’t shown in the system. Any way I can make those devices removable so that it’ll auto-plug if detected, and booting will proceed even if they aren’t plugged in?

Partially related: how can I make a USB hub dedicate itself to the virtual machine?

When I ran this script from ArchWiki, here’s what I got:

$ for usb_ctrl in /sys/bus/pci/devices/*/usb*; do pci_path=${usb_ctrl%/*}; iommu_group=$(readlink $pci_path/iommu_group); echo "Bus $(cat $usb_ctrl/busnum) --> ${pci_path##*/} (IOMMU group ${iommu_group##*/})"; lsusb -s ${usb_ctrl#*/usb}:; echo; done
Bus 1 --> 0000:04:00.0 (IOMMU group 23)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 2 --> 0000:04:00.0 (IOMMU group 23)
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 3 --> 0000:07:00.1 (IOMMU group 19)
Bus 003 Device 003: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 003 Device 002: ID 048d:5702 Integrated Technology Express, Inc. ITE Device
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 4 --> 0000:07:00.1 (IOMMU group 19)
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 5 --> 0000:07:00.3 (IOMMU group 19)
Bus 005 Device 006: ID 2516:0067 Cooler Master Co., Ltd. MK750
Bus 005 Device 005: ID 046d:c08b Logitech, Inc. G502 SE HERO Gaming Mouse
Bus 005 Device 004: ID 1532:0208 Razer USA, Ltd Tartarus Chroma
Bus 005 Device 003: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 005 Device 002: ID 8087:0032 Intel Corp. 
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 6 --> 0000:07:00.3 (IOMMU group 19)
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

cat: '/sys/bus/pci/devices/0000:0c:00.0/usbc_pd_fw/busnum': Not a directory
Bus  --> 0000:0c:00.0 (IOMMU group 28)

Bus 7 --> 0000:0f:00.3 (IOMMU group 34)
Bus 007 Device 008: ID 28da:3101 G.SKILL Corporation G.SKILL RIPJAWS MX780 GAMING MOUSE
Bus 007 Device 003: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub
Bus 007 Device 005: ID 045e:02d1 Microsoft Corp. Xbox One Controller
Bus 007 Device 002: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub
Bus 007 Device 007: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub             
Bus 007 Device 006: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub             
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 8 --> 0000:0f:00.3 (IOMMU group 34)
Bus 008 Device 006: ID 0781:5591 SanDisk Corp. Ultra Flair
Bus 008 Device 003: ID 2109:0817 VIA Labs, Inc. USB3.0 Hub             
Bus 008 Device 002: ID 2109:0817 VIA Labs, Inc. USB3.0 Hub             
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
  • IOMMU 34 - Bus 7 & 8 are 2 separate hubs that are plugged to the back of the motherboard.
  • IOMMU 19
    • Bus 6 is front panel IO (both top and bottom portion of the O11 Dynamic).
    • USB devices in Bus 5 are plugged at the back

So this is a question with not-perfect solutions.

I’ve found that the best solution is to pass an entire USB controller through.

If you have a USB controller on your GPU, that’s best. Pass it through, an use a USB C hub to split out your ports. It’s what I do on my workstation and allows me to do Passthrough on an ITX machine.

Regarding auto-plug of USB devices, I really don’t have a good solution for this, unfortunately.

Aah darn. My mobo only has 1 PCIe 4.0 x4 left, and I’m saving that for storage.

VIRT-manager isn’t capable of manually passing through a USB device, like Virtual Box?

you can pass devices through with USB redirection, but if it’s not booting when the device isn’t connected, I don’t think it’ll be smooth.

Also, you don’t need to use a PCIE x4 slot. You might be able to pass one of the motherboard or CPU onboard controllers through.

You’ll have to look at the PCI block diagram of your motherboard to determine that though.

$ for usb_ctrl in /sys/bus/pci/devices/*/usb*; do pci_path=${usb_ctrl%/*}; iommu_group=$(readlink $pci_path/iommu_group); echo "Bus $(cat $usb_ctrl/busnum) --> ${pci_path##*/} (IOMMU group ${iommu_group##*/})"; lsusb -s ${usb_ctrl#*/usb}:; echo; done
Bus 1 --> 0000:04:00.0 (IOMMU group 23)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 2 --> 0000:04:00.0 (IOMMU group 23)
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 3 --> 0000:07:00.1 (IOMMU group 19)
Bus 003 Device 005: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 003 Device 016: ID 28da:3101 G.SKILL Corporation G.SKILL RIPJAWS MX780 GAMING MOUSE
Bus 003 Device 008: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub
Bus 003 Device 007: ID 045e:02d1 Microsoft Corp. Xbox One Controller
Bus 003 Device 013: ID 12d1:4321 Huawei Technologies Co., Ltd. UVC Camera
Bus 003 Device 004: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub
Bus 003 Device 017: ID 046d:c541 Logitech, Inc. USB Receiver
Bus 003 Device 006: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub             
Bus 003 Device 003: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub             
Bus 003 Device 002: ID 048d:5702 Integrated Technology Express, Inc. ITE Device
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 4 --> 0000:07:00.1 (IOMMU group 19)
Bus 004 Device 005: ID 0bda:0411 Realtek Semiconductor Corp. Hub
Bus 004 Device 003: ID 0bda:0411 Realtek Semiconductor Corp. Hub
Bus 004 Device 008: ID 2109:0817 VIA Labs, Inc. USB3.0 Hub             
Bus 004 Device 002: ID 2109:0817 VIA Labs, Inc. USB3.0 Hub             
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 5 --> 0000:07:00.3 (IOMMU group 19)
Bus 005 Device 005: ID 1532:0208 Razer USA, Ltd Tartarus Chroma
Bus 005 Device 006: ID 2516:0067 Cooler Master Co., Ltd. MK750
Bus 005 Device 004: ID 046d:c08b Logitech, Inc. G502 SE HERO Gaming Mouse
Bus 005 Device 003: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 005 Device 002: ID 8087:0032 Intel Corp. 
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 6 --> 0000:07:00.3 (IOMMU group 19)
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

cat: '/sys/bus/pci/devices/0000:0c:00.0/usbc_pd_fw/busnum': Not a directory
Bus  --> 0000:0c:00.0 (IOMMU group 28)

Bus 7 --> 0000:0f:00.3 (IOMMU group 34)
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 8 --> 0000:0f:00.3 (IOMMU group 34)
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Does this help?

I assume that the “VIA Labs” one is the hub I want to use to passthrough after unplugging and replugging it. These 2 devices, plugged to different hubs, are showing up in the same bus:

  • Bus 003 Device 017: ID 046d:c541 Logitech, Inc. USB Receiver
  • Bus 003 Device 016: ID 28da:3101 G.SKILL Corporation G.SKILL RIPJAWS MX780 GAMING MOUSE

Already worked around that with <source startupPolicy="optional">

Found the block diagram from the manual:

This block diagram made me realize that, I think, I should’ve put my NVME SSD on the M2A_CPU slot (connected to the CPU), instead of M2B_SB (connected to the chipset).

And if I were to put a USB PCIe card, not sure if that there’ll be enough space under the 2nd GPU (especially when I replace that 1060 with a 3060 (Ti)).

So I figured out how to make USB redirection work, but it only worked on my Linux VMs, not Windows. I installed SPICE Guest Tools a while back before I had it GPU-accelerated.

Is there another driver I need to install?

Edit: turns out I have to have QXL video enabled to make it work. Doesn’t work when I have it set to none.

Well, I decided to just install my USB card. So far, it works.

I just hope that when I replace the GTX 1060 with a 3060 Ti or a 3060, it’ll still fit. So far, the one I want (MSI Gaming X) won’t. My options are probably the Zotac Twin Edge or the MSI Ventus (where the fans don’t bulge).