Libvirt and USB devices

I’ve been beating my head against a wall on this. Seems straight forward, but gets bogged down in the details. Attaching a usb device to a guest “automatically”. Plug a camera or printer into the vhost, how to get it to a guest. Yes I know virsh attach-device, or the gui. So I worked on a udev->bash_script->virsh tool, that works, it’s a bit specific to my 3d-printer usb_id, but I can boot my vhost, auto-boot my guest, and systemd and/or udev will find the device and virsh attach-device, until rebooting the vhost. USB id are dynamic and end-up stale in the guest config and boom! no boot!. Kind of defeats the purpose of USB when I have to manually keep adding/removing devices from my guests. Is there not some kind of usb_proxy/bridge to make vhost usb devices recognizable by the guests? Is there a way to configure the vhost to “broadcast” or expose it’s usb to all the guests. yes there are reasons why this could be bad, but manually touching guests all the time to get access to a printer or a camera seems too brute force. I’m certain someone else has bumped into this issue. In particular the failure of a guest to boot, simply because it printer or camera is powered off at reboot. Thx in advance.

I haven’t done it, but maybe this is what you are looking for?

1 Like