For the past 2 years I've been running a Windows VM to which I passed through USB devices. The devices were attached while the VM was running, using virsh attach-device vm_name config_file.xml, where config_file.xml was e.g.:

<!-- Logitech Internet Navigator -->
<hostdev mode='subsystem' type='usb' managed='yes'>
    <vendor id='0x046d'/>
    <product id='0xc308'/>

This all worked great, until I decided yesterday that it was time to upgrade my Ubuntu 16.04 to 18.04. Now attaching USB devices to the VM doesn't work anymore.

Here's the output I'm seeing:

$ virsh attach-device windows-gaming-uefi config/keyboard-white.xml 
error: Failed to attach device from config/keyboard-white.xml
error: internal error: unable to execute QEMU command 'device_add': failed to open host usb device 1:3

The device definitely exists, here's some lsusb output:

Bus 001 Device 003: ID 046d:c308 Logitech, Inc. Internet Navigator Keyboard

I took a look in kern.log to see if AppArmor had something to do with it, but that doesn't seem to be the case. Just to make sure it's not interfering with anything, I've disabled AppArmor completely for now.

Does anyone have any clue as to how to fix this?

Edit: Doing a chmod -R go+rw /dev/bus/usb before attempting to attach the USB devices doesn't help either.

  • This issue suggests it could be a USB 2 / USB 3 problem. What USB controller(s) do you create? Try adding other types. For reference, I run QEMU with -device ich9-usb-uhci3,id=uhci -device usb-ehci,id=ehci -device nec-usb-xhci,id=xhci
    – user311098
    Commented Feb 3, 2019 at 16:52
  • I've got one usb controller of type 'ehci' and another 3 "regular" ones (no type specified). virt-manager shows them as 1 'ehci' and 3 'piix3-uhci'.
    – AVH
    Commented Feb 3, 2019 at 18:32

2 Answers 2


Thanks to Darhuuk's answer I was able to get this working myself, and then modify it to not run qemu as root. This is what I did:

In /etc/libvirt/qemu.conf, set:

user = "qemu"
group = "qemu"

Create /lib/udev/rules.d/51-qemu-usb-passthrough.rules containing

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="XXXX" ATTRS{idProduct}=="YYYY" GROUP="qemu"

where XXXX and YYYY are the vendor and product IDs of the device I wanted to forward. (It can also be set by other sysfs attributes, e.g. bus and port, if you want to forward a specific physical USB port regardless of what's plugged in)

Run udevadm control --reload-rules and sudo systemctl restart libvirtd.service.


I managed to solve my problem by first reinstalling QEMU from source (see https://askubuntu.com/questions/1067722/how-do-i-install-qemu-3-0-on-ubuntu-18-04):

sudo apt-get purge "qemu*"
sudo apt-get autoremove
sudo apt-get build-dep qemu

wget https://download.qemu.org/qemu-3.1.0.tar.xz
tar -xf qemu-3.1.0.tar.xz
rm qemu-3.1.0.tar.xz
cd qemu-3.1.0

sudo apt-get install checkinstall
sudo checkinstall make install

Then making sure QEMU ran as root, by adding the following to /etc/libvirt/qemu.conf:

user = "root"
group = "root"

And finally reloading the KVM modules:

sudo rmmod kvm_intel
sudo rmmod kvm
sudo modprobe kvm
sudo modprobe kvm_intel
sudo systemctl restart libvirtd.service

It seems to me that running QEMU as root shouldn't be strictly necessary, but I just wanted to get this working.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .