spice remote-viewer 连接会话时自动重定向usb设备(记录)
方法
1,直接使用以下命令即可自动重定向usb设备(除HID设备)
remote-viewer --spice-usbredir-redirect-on-connect="0x03,-1,-1,-1,0|-1,-1,-1,-1,1" console.vv
2,如果使用以下命令,则仅在插拔usb接口才会重定向usb设备:
remote-viewer --spice-usbredir-auto-redirect-filter="0x03,-1,-1,-1,0|-1,-1,-1,-1,1"
解释:
0x03,-1,-1,-1,0 代表过滤此HID(human interface device)设备,即鼠标、键盘、游戏手柄等。
-1,-1,-1,-1,1 代表允许所有设备连接。
| 多个规则组合,排前面的优先匹配规则(个人理解,不知道有没有错)
规则格式:
<class>,<vendor>,<product>,<version>,<allow>
<class>,<vendor>,<product>,<version>使用 -1 代表任何值
spice usb拓展
以下内容全部来源于:https://www.spice-space.org/usbredir.html
Using libvirt
The following libvirt XML will configure a guest with USB2 support and the ability to redirect 3 devices simultaneously:
<controller type='usb' index='0' model='ich9-ehci1'/>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<master startport='2'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<master startport='4'/>
</controller>
<redirdev bus='usb' type='spicevmc'/>
<redirdev bus='usb' type='spicevmc'/>
<redirdev bus='usb' type='spicevmc'/>
For USB3 support, the configuration can be simplified to:
<controller type='usb' index='0' model='nec-xhci'/>
<redirdev bus='usb' type='spicevmc'/>
<redirdev bus='usb' type='spicevmc'/>
<redirdev bus='usb' type='spicevmc'/>
Using QEMU
The following qemu options will configure a guest with USB2 support and the ability to redirect 3 devices simultaneously
-device ich9-usb-ehci1,id=usb \
-device ich9-usb-uhci1,masterbus=usb.0,firstport=0,multifunction=on \
-device ich9-usb-uhci2,masterbus=usb.0,firstport=2 \
-device ich9-usb-uhci3,masterbus=usb.0,firstport=4 \
-chardev spicevmc,name=usbredir,id=usbredirchardev1 \
-device usb-redir,chardev=usbredirchardev1,id=usbredirdev1 \
-chardev spicevmc,name=usbredir,id=usbredirchardev2 \
-device usb-redir,chardev=usbredirchardev2,id=usbredirdev2 \
-chardev spicevmc,name=usbredir,id=usbredirchardev3 \
-device usb-redir,chardev=usbredirchardev3,id=usbredirdev3
For USB3 support, the configuration can be simplified to:
-device nec-usb-xhci,id=usb \
-chardev spicevmc,name=usbredir,id=usbredirchardev1 \
-device usb-redir,chardev=usbredirchardev1,id=usbredirdev1 \
-chardev spicevmc,name=usbredir,id=usbredirchardev2 \
-device usb-redir,chardev=usbredirchardev2,id=usbredirdev2 \
-chardev spicevmc,name=usbredir,id=usbredirchardev3 \
-device usb-redir,chardev=usbredirchardev3,id=usbredirdev3
Host Filtering
Set a string specifying a filter to determine which USB devices are allowed/blocked to redirect USB traffic to the guest.
Using QEMU
-device usb-redir,filter='0x03:-1:-1:-1:0|-1:-1:-1:-1:1',chardev=usbredirchardev1,id=usbredirdev1
Note that in a QEMU command, the filter string should use a ':' character as a separator within the rule.
Using libvirt
...
<devices>
...
<redirfilter>
<usbdev class='0x08' vendor='0x1234' product='0xbeef' version='2.56' allow='yes'/>
<usbdev allow='no'/>
</redirfilter>
</devices>
...