ubuntu – 将usb加密狗连接到KVM VM

我正在努力将主机正确检测到的USB设备连接到kvm vm.

我有一个新安装的Ubuntu Server 14.10作为KVM / QEMU主机.我使用这个命令设置了一个Ubuntu vm:

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

成功安装后,virsh dumpxml test01返回

<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>

我现在想要连接USB记忆棒.在一些googleing I found some sources之后,基本上所有建议采用以下方法

>坚持主持人
>获取供应商和产品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

>通过virsh编辑test01将新的config-snippet添加到vm

<devices>
  <!- ... ->
  <hostdev mode='subsystem' type='usb' managed='yes'>
    <source>
      <vendor id='0x13fe'/>
      <product id='0x5100'/>
    </source>
  </hostdev>
</devices/>

>重启vm

之后,vm应该通过lsusb看到棒,但没有任何变化.如果我尝试将设备连接到第二个vm,virsh start< othervm>失败并显示错误:请求的操作无效:驱动程序QEMU,域test01正在使用USB设备002:003但是我仍然可以在主机上安装和访问操纵杆.我尝试了不同的操作系统和不同的操作系统(ubuntu和windows),但没有成功.

一些说明建议关闭apparmor,但/etc/init.d/apparmor stop没有改变任何东西.

这让我疯了,因为我没有收到任何错误或记录消息,我不知道如何找出问题所在.有关如何将USB连接到虚拟机的任何想法,或者至少如何进一步分析它?

这可能是访问权限的问题.您的QEMU守护程序不允许访问USB设备.尝试:
chown libvirt-qemu /dev/bus/usb/ -R

或者您的KVM运行的用户.这应该可以解决问题.

相关文章

1.安装过程出现0x00000000指令引用的0x00000000内存该内存不能为written 如果你安装的是inux系统 需要在...
写在全面:如果根据以下教程涉及到只读文件需要更改文件权限才能需修改文件内容,参考我的另一篇博客:...
写在前面:以下步骤中需要在终端输入命令,电脑端查看博客的朋友可以直接复制粘贴到终端,手机端查看的...
ubuntu16.04和18.04更换国内源 写在前面:安装好ubuntu双系统后,默认的软件更新源是国外的,在国内使用...
ubuntu双系统启动时卡死解决办法(在ubuntu16.04和18.04测试无误) 问题描述: 在安装完ubuntu双系统后...
又来造轮子了。。。。。。。。。。。。。。。。 今天使用w3af向文件中写入的时候,发现没有write权限,...