I'm struggling to connect a usb device, that gets detected correctly by the host, to a kvm vm.
I have a freshly installed Ubuntu Server 14.10 as KVM/QEMU host. I set up an Ubuntu vm using this command:
virt-install --connect qemu:///system \
-n test01 \
-r 1024 \
--vcpus=2 \
--disk path=/vmstorage/01/test01.img,size=5 \
--vnc \
--noautoconsole \
--os-variant=ubuntuutopic \
--hvm \
--cdrom /path/to/ubuntu-14.10-server-i386.iso
After the successful installation a virsh dumpxml test01
returns
<domain type='kvm' id='16'>
<name>test01</name>
<uuid>f58ca825-c999-4168-9f5a-616057d9955d</uuid>
<memory unit='KiB'>1048576</memory>
<currentMemory unit='KiB'>1048576</currentMemory>
<vcpu placement='static'>2</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch='x86_64' machine='pc-i440fx-utopic'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<cpu mode='custom' match='exact'>
<model fallback='allow'>SandyBridge</model>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/vmstorage/01/test01.img'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<backingStore/>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>
<alias name='usb0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<alias name='usb0'/>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<alias name='usb0'/>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<alias name='usb0'/>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'>
<alias name='pci.0'/>
</controller>
<controller type='ide' index='0'>
<alias name='ide0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='bridge'>
<mac address='52:54:00:11:b2:c1'/>
<source bridge='br0'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/0'/>
<target port='0'/>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/0'>
<source path='/dev/pts/0'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</memballoon>
</devices>
<seclabel type='dynamic' model='apparmor' relabel='yes'>
<label>libvirt-f58ca825-c999-4168-9f5a-616057d9955d</label>
<imagelabel>libvirt-f58ca825-c999-4168-9f5a-616057d9955d</imagelabel>
</seclabel>
</domain>
I now want to attach an USB stick. After some googleing I found some sources that basically all suggest the following approach:
- attach stick to host
get vendor- and product-id
root@host01:~# lsusb Bus 002 Device 004: ID 13fe:5100 Kingston Technology Company Inc. Flash Drive Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 004: ID 0624:0249 Avocent Corp. Bus 001 Device 003: ID 0624:0248 Avocent Corp. Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
add new config-snippet to vm via
virsh edit test01
<devices> <!- ... -> <hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x13fe'/> <product id='0x5100'/> </source> </hostdev> </devices/>
restart vm
After that the vm should see the stick via lsusb
, but nothing changes. If I try to attach the device to a second vm though, virsh start <othervm>
fails with error: Requested operation is not valid: USB device 002:003 is in use by driver QEMU, domain test01
BUT I can still mount and access the stick on the host. I tried different sticks and different vm-operating systems (ubuntu and windows), no success.
Some instructions suggest to turn off apparmor, but a /etc/init.d/apparmor stop
didn't change anything.
This is driving me nuts, since I don't get any error or log messages and I have no clue how to find out what's wrong. Any ideas on how to get the usb connected to the vm, or at least, how to analyse it further?