USB redirection

前言

物理上插在某A机器上,需要在某B系统中使用,而这个B系统,运行在某台服务器C的虚拟化环境中。

A:192.168.131.102 (USB在此物理机)
B:192.168.131.101上起的虚拟机 centos
C:192.168.131.101

A配置

使用kvm管理工具 virt-manager 的过程中,通过USB passthrough,映射本地usb设备。意外发现有usb重定向选项。

usb重定向的类型选择中,除了Spice通道,还有TCP的方式,可以填写host和port。

yum install dnf

dnf install usbredir-server -y

yum install usbutils

查看usb

yum install usbutils

Bus 002 Device 006: ID 0930:6545 Toshiba Corp. Kingston DataTraveler 102/2.0 / HEMA Flash Drive 2 GB / PNY Attache 4GB Stick
Bus 002 Device 002: ID 8087:8002 Intel Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 046b:ff10 American Megatrends, Inc. Virtual Keyboard and Mouse
Bus 001 Device 003: ID 046b:ff01 American Megatrends, Inc.
Bus 001 Device 002: ID 8087:800a Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


选择usb的ip号
usbredirserver -p 8686 -v 3 0930:6545
端口可以自定义。

verbosity level(-v)级别从0-5,0:Silent 1:Errors 2:Warnings 3:Info 4:Debug 5:Debug++。

这将把对应的usb设备映射到网上。可以通过 netstat 命令检查,新开一个终端

yum install net-tools

usbredirserver -p 8686 -v 3 0930:6545

通过netstat -altunp检查

netstat -altunp | grep usbredirserve
tcp6       0      0 :::8686                 :::*                    LISTEN      48338/usbredirserve

B配置

先创建虚拟机,编写xml文件:

<domain type='kvm'>
  <name>centostest</name>
  <uuid>be26b846-42a1-455c-9c96-2ce7ad2a220f</uuid>
  <memory unit='KiB'>208896</memory>
  <currentMemory unit='KiB'>208896</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
    <bootmenu enable='yes'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='localtime'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/centostest.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/root/CentOS-7.6-x86_64-DVD-1810.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0' model='piix3-uhci'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:9d:ca:db'/>
      <source bridge='br0'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='850c7add-a5b3-4b42-888e-4593569b0690'/>
      </virtualport>
      <target dev='tap0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='5910' autoport='no' listen='0.0.0.0' keymap='en-us'>
      <listen type='address' address='0.0.0.0'/>



创建

virsh define centostest.xml
Domain centostest defined from centostest.xml

virsh start centOS
Domain centOS started

修改xml文件,加入

<redirdev bus='usb' type='tcp'>
  <source mode='connect' host='192.168.131.102' service='8686'/>
  <protocol type='raw'/>
  <address type='usb' bus='0' port='1'/>
</redirdev>

重启动虚拟机即可

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不会长胖的斜杠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值