xen中USB设备的使用方法--资料收集

上一篇 / 下一篇  2011-08-02 21:20:23 / 个人分类:xen

xen使用之USB pass-through(HVM)
        by Wang Xiantong,xiantong@gmail.com
date:2009.7.17
最近在迁移人事系统到虚拟平台的时候,发现XenServer5.5,Vmware ESXi3.5都不支持pass-through功能。我们的人事考勤系统需要安装USB加密狗,所以决定在Debian 5.0(lenny)下布署xen。这里主要说一下usb pass-through的实现。
1、把USB插入主机
2、在console下输入命令
        lenny#lsusb
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 096e:0001 Feitian Technologies, Inc.
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
3、确定插入的USB设备ID号为096e:0001,“:”号前的是该产品的厂商代号,后面是产品代号
4、编缉HVM客户机的配置文件,这里是win2003,添加下面两行
        usb=1
        usbdevice="host:096e:0001"
5、启动HVM虚拟机
        lenny# xm create win2003.cfg

===============================================================

驱动问题:
方案二: 
USB的支持关键在于驱动,没有驱动设备时mount执行是肯定不成的。我在Red Hat里使用U盘的通用方法如下,屡试不爽 


1. 先别插U盘,/sbin/lsmod看是否有usb-storage。如果没有的话: 


cd /lib/modules/2.4.20-8/kernel/drivers/usb 

for v in *.o storage/*.o ; do /sbin/insmod $v ; done 

2. 这里再/sbin/lsmod,应该有usbcore、usb-ohci(或usb-uhci,根据主板芯片组而不同)、usb-storage、scsi_mod等。其中usb-storage的状态应该为 

(unused)。 


3. 插入U盘,不停的/sbin/lsmod,这期间usb-storage的状态应为Initializing,持续时间大约半分钟,其实就相当于Windows在右下角不停的弹汽球:) 


4. 初始化结束后, /sbin/fdisk -l,应该能看到/dev/sda1设备。这时,执行 

mount /dev/sda1 /mnt/udisk 才能成功。如果是MSDOS格式,又想看到中文,可以 

mount -t vfat /dev/sda1 /mnt/udisk -o iocharset=gb2312。 


(为方便可以/etc/fstab加一行,以后就可以 mount /mnt/udisk就行了)。 

5. 奇怪的是有时候fdisk是看不到sda1,但是也能mount上 


使用以上步骤挂U盘基本上可说是“万全”了。台式机、笔记本、VMware都一样。 

mkdir /mnt/usb 

mount /dev/sda1 /mnt/usb 

笔记本上安装linux用法和台式机一样 

ps: 

首先要检查lsmod|grep usb-storage 这是支持USB的模块。如果没有的话,是无法操作USB接口的设备的。 

如没有的话,可以手功modprobe usb-storage,一般查看U盘可以用fdisk -l可以很清楚的看到这个硬件的设备名 

,比猜测硬件名要准确多了.


TAG:

werm520的个人空间 引用 删除 werm520   /   2011-08-22 14:00:42
(原始网页: http://www.drivers-download.com/cn/downloadlist.php?id=180)
werm520的个人空间 引用 删除 werm520   /   2011-08-18 14:18:29
On Do, Feb 21, 2008 at 03:15:57 +0200, Andris wrote:
> Hello all!
>
> I have Centos 5.1 64bit xen Dom0 and ABIT mobo with no serial ports.
> The task is:
>
> - connect an external fax modem to Dom0 via USB -> to serial converter cable
> - export that serial port to paravirtualized Gentoo DomU for use with
> Hylafax
>
> I found the solution:
> http://www.olivetalks.com/2008/01/24/usb-forwarding-on-xen by exporting
> mobo usb PCI device to domU.
> But unfortunately it seems not to be stable setup as noted by author.
> Although I successfully use a similar approach for PCI printer port card
> (Dom0) and HASP device (DomU) in production environment with no problems
> at all.
> Are there differences for USB?
>
> I connected USB to serial converter cable to my Dom0 machine. Everything
> is detected and ok. I see /dev/ttyUSB0 as my serial port.
> How to export /dev/ttyUSB0 to my DomU?
> I suppose the irq and ioports options in domU config file are not
> applicable to port created by USB converter cable.
>
> If this setup is impossible for paravirtualized domU, then I can create
> a HVM gentoo DomU.
> What about usb=1 option or serial='/dev/ttyUSB0' option?

You can export it e.g. via network:



Server:

socat TCP4-LISTEN:54321,reuseaddr /dev/ttyUSB0,b115200,nonblock,raw,echo=0


Client:

socat PTY,link=/dev/vmodem0,b115200,raw,echo=0,waitslave TCP4:127.0.0.1:54321


==================================

If you're using Linux on the other computer to view and log the serial console:
In linux you can get a list of the serial ports by running "dmesg | grep ttyS". USB serial adapters are usually named "ttyUSB*", so you can check for them with "dmesg | grep ttyUSB".

You can use for example "minicom", "kermit" or many other tools to view the serial console. You can start minicom with "minicom -s" to enter the setup mode to configure the serial settings. Another option is to press "Ctrl-A p" when minicom is running to enter the settings dialog. After configuring the settings remember to save them, and then restart minicom. "Ctrl-A x" can be used to quit minicom. Read the minicom man-page for more information about the usage.

You can also use simple "screen" command to view the serial console: "screen /dev/ttyUSB0 115200".

==================================================
werm520的个人空间 引用 删除 werm520   /   2011-08-04 14:15:23
添加usb文件:
1、在将usb插入宿主机前,通过lsusb查看设备;
2、插入后,在通过lsusb查看,新加的设备即为usb设备;

3、将usb设备假如xm管理
   创建一个用来管理usb的通用账户:
xm  usb-hc-create Domain-0 2 8
//This creates a virtual USB 2.0 host controller on the guest that has 8 ports.
通过命令获取usb信息:
xm usb-list-assignable-devices

将usb接入管理
xm  usb-attach Domain-0 0 1 8-1

通过xm usb-list Domain-0可以查看
4、确认VM支持接入usb设备:
   查看VMconfig.xen文件,确认是否有参数usb = 1,当存在这个参数时VM可以在线接入usb设备。
   如果想VM启动时,就载入USB设备,可以增加参数
usbdevice='host 0644:1008'  //其中 0644:1008 为上图查出的ID后的参数后

5、将USB设备接入VM,命令格式如下:
xm usb-add <domain> <[host:bus.addr] [host:vendor_id:product_id]>
例:xm usb-add 52 host:0644:1008  (52为VMID,host:为设备ID,既上图查出的ID)
接入后 windows就可以正常看到设备了,linux如需使用该设备则需要安装相关驱动,且设备支持linux。

通过 xm usb-del 52 host:0644:1008 可去除usb


备注:
linux发现USB设备需要载入以下模块(不同版本linux可能文件夹位置有所不同,find后载入):
/lib/modules/`uname -r`/kernel/drivers/ide/ide-core.ko
/lib/modules/`uname -r`/kernel/drivers/scsi/scsi_mod.ko
/lib/modules/`uname -r`/kernel/drivers/scsi/sd_mod.ko
/lib/modules/`uname -r`/kernel/drivers/usb/core/usbcore.ko   //redhat没有该模块
/lib/modules/`uname -r`/kernel/drivers/usb/host/ehci-hcd.ko
/lib/modules/`uname -r`/kernel/drivers/usb/host/ohci-hcd.ko
/lib/modules/`uname -r`/kernel/drivers/usb/host/uhci-hcd.ko
/lib/modules/`uname -r`/kernel/drivers/usb/storage/usb-storage.ko
/lib/modules/`uname -r`/kernel/drivers/usb/input/usbhid.ko #加载这个模块是为了支持USB键盘,如果在启动过程中,如果出现无法找到root的时候,会进入一个临时的shell,因此可能需要一些简单的调试,如 果是USB键盘的话,就必须要加载这个模块了
/lib/modules/`uname -r`/kernel/fs/ext2/ext2.ko
/lib/modules/`uname -r`/kernel/fs/ext3/ext3.ko
/lib/modules/`uname -r`/kernel/fs/jbd/jbd.ko
/lib/modules/`uname -r`/kernel/fs/mbcache.ko
 

评分:0

我来说两句

Open Toolbar