微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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运行的用户.这应该可以解决问题.

原文地址:https://www.jb51.cc/ubuntu/348586.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐