本帖最后由 langke93 于 2017-3-9 17:39 编辑
下面供楼主参考,仅供参考:
The bus/device IDs can be obtained from virsh via the 'virsh nodedev-list --tree' and 'virsh nodedev-dumpxml' commands or using 'lsusb' to determine the bus and device.
我采用的是lsusb来查看usb设备的编号
[root@nail-SBCJ-5-3-3 home]# lsusb Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 004: ID 0930:6544 Toshiba Corp. Kingston DataTraveler 2.0 Stick (2GB) 修改xml文件,填好字段 vendor:product(0930:6544 ) [root@nail-SBCJ-5-3-3 home]# cat usb.xml <hostdev mode='subsystem' type='usb'> <source> <vendor id='0x0930'/> <product id='0x6544'/> </source> </hostdev> 或者修改xml文件,填好字段address [root@nail-SBCJ-5-3-3 home]# cat usb1.xml <hostdev mode='subsystem' type='usb'> <source> <address bus='002' device='004'/> </source> </hostdev> 2 挂载usb设备 [root@Nail-SBCJ-slot5 home]# virsh attach-device instance-0000005d usb.xml Device attached successfully 挂载成功后,虚拟机的xml里面会添加一段 <hostdev mode='subsystem' type='usb' managed='no'> <source> <vendor id='0x0781'/> <product id='0x5567'/> <address bus='2' device='4'/> </source> <alias name='hostdev0'/> </hostdev> 虚拟机里面也会看到相应的u盘设备,如下在控制台里面,看到虚拟机识别到u盘为sdb,mount u盘分区后,可以看到u盘的内容。
3 u盘已经挂载成功之后,再尝试把u盘挂载到新的虚拟机,挂载失败 [root@Nail-SBCJ-slot5 home]# [root@Nail-SBCJ-slot5 home]# virsh attach-device instance-00000061 usb.xml error: Failed to attach device from usb.xml error: Requested operation is not valid: USB device 002:004 is in use by domain instance-0000005d
You have new mail in /var/spool/mail/root [root@Nail-SBCJ-slot5 home]#
4 解挂载命令 [root@Nail-SBCJ-slot5 home]# virsh detach-device instance-0000005d usb.xml Device detached successfully
遇到的问题: 1 lsusb命令不识别 解决:安装 usbutils-007-4.el7.x86_64.rpm --nodeps 2 有多个usb的时候,怎么判断虚拟机要哪个usb设备 ? 3 attach的时候,提示 'usb-host' is not a valid device model name 解决:编译qemu的时候,带参数 --enable-libusb,并且编译好之后,要安装rbd包
From qemu-1.7 release version, the old usb-host(host-linux.c) had been removed, re-implemented by libusbx. So you should build qemu with --enable-libusb, then you can use usb pass-through capacity. 4 如果usb分区成两个分区,不清楚对挂载有没有影响,需要进行测试验证,没有影响。 5 u盘被一个虚拟机挂载之后,其他虚拟机不可以再挂载这个u盘
来自: csdn maureenxo
|