1,需求如下:短信机的使用的传统型的串口,想连接到业务,并能够根据业务设置发送短信。业务服务为kvm上运行的虚拟机,但kvm上没有添加usb1.0的接口,所以只能通过自己编写xml的方式,在挂载usb串口。
2,登录服务器使用如下命令查看usb的型号和类型:
[server1]#lsusb
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 002: ID 8087:800a Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 3689:8762
Bus 003 Device 005: ID 096e:0006 Feitian Technologies, Inc.
Bus 003 Device 009: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
根据ID 0403:6001 Future Technology Devices International, Ltd 查找x相对应的Vendor和product。
[server1]#lsusb -v |grep 0403
idVendor 0x0403 Future Technology Devices International, Ltd
[server1]#lsusb -v |grep 6001
Bus 003 Device 009: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
idProduct 0x6001 FT232 Serial (UART) IC
编写xm文件样例如下
[server1]#vim usb.xml
<hostdev mode='subsystem' type='usb' managed='yes'>
<source>
<vendor id='0x0403'/>
<product id='0x6001'/>
<!--address bus='3' device='3'/-->
</source>
<alias name='hostdev10'/>
</hostdev>
使用virsh list查看虚拟机的uuid
[root@ceph-4 ~]# virsh list
Id Name State
----------------------------------------------------
1 327066ab27f4463daaceb29d062ea486 running
2 358b22f708f64253ba845f7c81faa703 running
3 6e89ca538b19453e8a2858c5b429a8b9 running
4 fcf3f0c092524488a58a4086b4f82a10 running
挂载usb设备给虚拟机
挂载usb设备:virsh attach-device fcf3f0c092524488a58a4086b4f82a10 usb.10.xml
卸载usb设备:virsh detach-device fcf3f0c092524488a58a4086b4f82a10 usb.10.xml