KVM – Passing USB to guest with virsh/XML fails but works from virt-manager

kvm-virtualizationlibvirtusb

Running kvm on debian 8.8 jessie. I cannot redirect usb from a host to a guest (tried debian jessie and windows 2012 as guests, same problem)

libvirt 1.2.9-9+deb8u4

If I redirect the USB drive from virt-manager GUI, the guest sees the usb.

If I attempt the redirection using "virsh attach-device guest-dom" hostdev.xml. The guest sees the device (lsusb, and windows dev manager) but there is no block device detected (lsblk does not see the device)

# cat hostdev.xml
<hostdev mode='subsystem' type='usb'>
  <source>
    <vendor id='0x1976'/>
    <product id='0x6025'/>
  </source>
</hostdev>

Following are the logs from guest when it works (vir-manager method)

May 28 17:18:21 deb2 kernel: [  949.120071] usb 4-1: new full-speed USB device number 17 using uhci_hcd
May 28 17:18:21 deb2 kernel: [  949.312416] usb 4-1: New USB device found, idVendor=1976, idProduct=6025
May 28 17:18:21 deb2 kernel: [  949.312421] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
May 28 17:18:21 deb2 kernel: [  949.312423] usb 4-1: Product: USB
May 28 17:18:21 deb2 kernel: [  949.312426] usb 4-1: Manufacturer: ChipsBnk
May 28 17:18:21 deb2 kernel: [  949.312428] usb 4-1: SerialNumber: 088615381351
May 28 17:18:21 deb2 kernel: [  949.315619] usb-storage 4-1:1.0: USB Mass Storage device detected
May 28 17:18:21 deb2 kernel: [  949.315761] scsi16 : usb-storage 4-1:1.0
May 28 17:18:21 deb2 mtp-probe: checking bus 4, device 17: "/sys/devices/pci0000:00/0000:00:05.2/usb4/4-1"
May 28 17:18:21 deb2 mtp-probe: bus: 4, device: 17 was not an MTP device
May 28 17:18:22 deb2 kernel: [  950.320265] scsi 16:0:0:0: Direct-Access     ChipsBnk USB              4.00 PQ: 0 ANSI: 2
May 28 17:18:22 deb2 kernel: [  950.321321] sd 16:0:0:0: Attached scsi generic sg1 type 0
May 28 17:18:22 deb2 kernel: [  950.331807] sd 16:0:0:0: [sda] 258047 512-byte logical blocks: (132 MB/125 MiB)
May 28 17:18:22 deb2 kernel: [  950.338099] sd 16:0:0:0: [sda] Write Protect is off
May 28 17:18:22 deb2 kernel: [  950.338112] sd 16:0:0:0: [sda] Mode Sense: 00 00 00 00
May 28 17:18:22 deb2 kernel: [  950.344426] sd 16:0:0:0: [sda] Asking for cache data failed
May 28 17:18:22 deb2 kernel: [  950.344885] sd 16:0:0:0: [sda] Assuming drive cache: write through
May 28 17:18:22 deb2 kernel: [  950.429158]  sda: sda1
May 28 17:18:22 deb2 kernel: [  950.481252] sd 16:0:0:0: [sda] Attached SCSI removable disk

root@deb2:~# lsusb
Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 0409:55aa NEC Corp. Hub
Bus 004 Device 017: ID 1976:6025 Chipsbrand Microelectronics (HK) Co., Ltd. Flash Drive 512 MB
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

root@deb2:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    1  126M  0 disk
└─sda1   8:1    1  126M  0 part
sr0     11:0    1 1024M  0 rom
vda    254:0    0   40G  0 disk
├─vda1 254:1    0 38.3G  0 part /
├─vda2 254:2    0    1K  0 part
└─vda5 254:5    0  1.7G  0 part [SWAP]

Following are the logs from guest when it fails (virsh … xml method)

May 28 17:21:01 deb2 kernel: [ 1109.816098] usb 4-2.5: new full-speed USB device number 18 using uhci_hcd
May 28 17:21:02 deb2 kernel: [ 1110.093544] usb 4-2.5: New USB device found, idVendor=1976, idProduct=6025
May 28 17:21:02 deb2 kernel: [ 1110.093548] usb 4-2.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
May 28 17:21:02 deb2 kernel: [ 1110.093551] usb 4-2.5: Product: USB
May 28 17:21:02 deb2 kernel: [ 1110.093553] usb 4-2.5: Manufacturer: ChipsBnk
May 28 17:21:02 deb2 kernel: [ 1110.093555] usb 4-2.5: SerialNumber: 088615381351
May 28 17:21:02 deb2 kernel: [ 1110.095995] usb-storage 4-2.5:1.0: USB Mass Storage device detected
May 28 17:21:02 deb2 mtp-probe: checking bus 4, device 18: "/sys/devices/pci0000:00/0000:00:05.2/usb4/4-2/4-2.5"
May 28 17:21:02 deb2 kernel: [ 1110.097109] scsi17 : usb-storage 4-2.5:1.0
May 28 17:21:02 deb2 mtp-probe: bus: 4, device: 18 was not an MTP device

^C
root@deb2:~# lsusb
Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 018: ID 1976:6025 Chipsbrand Microelectronics (HK) Co., Ltd. Flash Drive 512 MB
Bus 004 Device 002: ID 0409:55aa NEC Corp. Hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
root@deb2:~#
root@deb2:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom
vda    254:0    0   40G  0 disk
├─vda1 254:1    0 38.3G  0 part /
├─vda2 254:2    0    1K  0 part
└─vda5 254:5    0  1.7G  0 part [SWAP]

May 28 17:22:47 deb2 kernel: [ 1215.915327] usb 4-2.5: USB disconnect, device number 22

The syslog message looks same up to "mtp-probe". But failed case stops with mtp-probe and OK case follows with detecting USB stick blocking device.

Under windows 2012 the OS sees the new "Mass storage…" entry in dev manager in USB section but there is no disk visible in "disk managment" nor in WIndows Explorer.

How can I make "virsh attach-device ..XML" work ?

I have no apparmor installed.

Best Answer

virsh attach-device --live guest-dom hostdev.xml