原创作品,转载请标明出处 http://blog.youkuaiyun.com/zhangzxing/article/details/8994655
更新(2013.07.09):实现windows下usb重定向的方法不止有一种,我说的只是其中一个方法,不要因此影响了大家的思路,还有一种方法,参考这位同学的博文
http://blog.youkuaiyun.com/terence427/article/details/9144567
最近也在捣鼓usbclerk,建议使用最新的spice-gtk和virt-viewer有问题大家一起探讨,有更好的方法欢迎分享!
1.环境
fedora 17;
mingw64;
spice-gtk0.14,virt viewer 0.5.3,usbredir 0.5.2
2.编译
安装mingw64,
最简单的方法 yum install mingw64-* --skip-broken 跳过冲突
2.1编译 usbredir-0.5.2
这个源码是我从mingw-usbredir-0.5.2-2.fc19.src.rpm这个rpm包里解出来的,因为直接下usbredir的源码包编译的时候有问题,本人太菜搞不定就拿现成的来用了。
mingw64-configure
mingw64-make
mingw64-make install
2.2编译 spice-gtk-0.14
mingw64-configure --without-sasl --with-gtk=2.0 --with-audio=gstreamer --without-python --enable-usbredir=yes --enable-smartcard=no
可能会在检查usbredirect模块式报错,解决方法用spice-gtk-0.19版本的configure文件来替换0.14版本的configure文件,然后再执行一遍上边的指令,应该能成功生成Makefile文件,(那为啥不直接用0.19版本的呢,我用0.19的编出来花屏,可能最新的不太稳定) 然后
mingw64-make
mingw64-make install
还有几个需要注意的问题:1.spice-gtk-0.14/spice-common/spice_codegen.py 添加可执行权限。2.在spice-gtk-0.14/spice-common/spice-protocol下需单独执行mingw64-make install,因为有可能这个文件夹下的编译结果没安装导致在编译virt viewer是找不到包 spice-protocol。
2.3.编译 virt viewer
mingw64-configure --with-gtk=2.0 --with-spice-gtk
mingw64-make
mingw64-make install
3. 运行virt viewer
我的操作系统是 windows 7 64 位
3.1 链接
3.2 链接成功
3.3 插入U盘,应该会报错
3.4 借助一个工具转换驱动程序 zadig
选中你的U盘把他的驱动转成 WinUSB类型的,然后再到虚拟机的选择这个设备
这个地方有点蛋疼,名字都一样,我这第一个是我的U盘,下变那俩是鼠标键盘,选中第一个然后close稍等一会,这个虚拟机就会发现一个存储设备了,原因是这样,没有对windows下usb设备处理的相应代码,现在是这样的:
#if __linux__
*manufacturer = spice_usbutil_get_sysfs_attribute(bus, address, "manufacturer");
*product = spice_usbutil_get_sysfs_attribute(bus, address, "product");
#endif
if ((!*manufacturer || !*product) &&
spice_usbutil_load_usbids()) {
for (i = 0; i < usbids_vendor_count; i++) {
if ((int)usbids_vendor_info[i].vendor_id != vendor_id)
continue;
if (!*manufacturer && usbids_vendor_info[i].name[0])
*manufacturer = g_strdup(usbids_vendor_info[i].name);
product_info = usbids_vendor_info[i].product_info;
for (j = 0; j < usbids_vendor_info[i].product_count; j++) {
if ((int)product_info[j].product_id != product_id)
continue;
if (!*product && product_info[j].name[0])
*product = g_strdup(product_info[j].name);
break;
}
break;
}
}
if (!*manufacturer)
*manufacturer = g_strdup(_("USB"));
if (!*product)
*product = g_strdup(_("Device"));
所以,要改代码喽