attaching usb dongle to KVM VM

To grant permanent access to the raw USB device nodes to the user the hypervisor runs as, you need to create an udev rule; the chown-based answer will only work until the next reboot.

In /lib/udev/rules.d, create a file like 51-usb_passthrough.rules :

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{busnum}=="2" ATTRS{devpath}=="1" GROUP="kvm"

Here I used physical bus and port numbers to target the device (as I prefer passing through the physical port no matter what device is plugged in rather than reconfiguring my VM each time I connect a new device), but of course you can use whatever attributes you want; the GROUP argument determines the group that will own the device node, this should be whatever user runs the virtual machines.

Run udevadm control --reload-rules to make the new rule effective immediately (you still need to disconnect/reconnect the USB devices) or simply reboot the host.


It's probably a problem with access rights. Your QEMU deamon is not allowed to access the USB devices. Try:

chown libvirt-qemu /dev/bus/usb/ -R

or whichever user your KVM is running as. This should do the trick.


Easy solution: connect with

nc -U socket-file

to your QEMU monitor, where socket-file is the path to monitor. How to find: ps -FA | grep qemu. You will find there at the command line.

And run the command at the monitor:

device_add usb-host,id=<ANY string>,hostbus=<BUS>,hostport=<PORT>

this is pass-through by port number. You can pass through any device with any VID/PID. You can also pass-through particular devices using

device_add usb-host,id=<ANY string>,vendorid=0x0461,productid= 0x0010

and they can be plugged in to any port of your host.

Helpful commands also:

info usbhost
info usb