0

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'>
  <source>
    <vendor id='0x046d'/>
    <product id='0xc308'/>
  </source>
</hostdev>

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 – williamvds Feb 3 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'. – Darhuuk Feb 3 at 18:32
0

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
./configure
make

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.