注:—— 写在前面:
其实USBIP最开始的时候只是用在Linux端的, 具体是如下:
- Windows端只可以作为客户端, 不可以做为服务端
- Linux端既可以作为客户端, 也可以作为服务端
- USBIP其实已经很老了, 03和11年都有更新, 之后就没有更新, 所以对于现代的版本不一定支持, 但是Windows10目前还是主流os, 所以有必要写个对于Windows的USBIP, 但是Linux内核集成的USBIP无法用到Windows, 所以这里的服务端我参考了Github大佬的代码, 也就是说, 原生的Linux内核的USBIP无法完成Windows测试, 如下的exe均是使用了Github大佬的源代码才完成了Windows10作为服务端的测试
注:
去release下载全部的可执行文件, 包括.sys, .cer等等
进入BIOS -> Security, 将security boot设置为disabled, 这样我们的电脑就可以进入测试模式, 方便接下来的进入测试模式command执行
以管理员的权限启动cmd, 接下来的操作默认都是管理员权限, 记得关闭Windows防火墙
注:
虽然有些操作不需要管理员权限, 但是为了防止记混, 我们全部使用管理员权限操作cmd
cmd输入:
bcdedit.exe /set TESTSIGNING ON
这句话执行完成后需要重启电脑应用 —— 成功后如下显示:
注1:
最后一步2个存储位置都需要存放certificate
- 受信任的根证书颁发机构
- 受信任的发布者
注2:
私钥键入的密码就是usbip
usbip.exe list -l
- busid 1-181 (8087:800a)
Intel Corp. : unknown product (8087:800a)
- busid 1-201 (046b:ff01)
American Megatrends, Inc. : unknown product (046b:ff01)
- busid 1-198 (8087:8002)
Intel Corp. : unknown product (8087:8002)
- busid 1-50 (ffff:5678)
unknown vendor : unknown product (ffff:5678)
- busid 1-213 (0424:2422)
Standard Microsystems Corp. : unknown product (0424:2422)
- busid 1-59 (046b:ff10)
American Megatrends, Inc. : Virtual Keyboard and Mouse (046b:ff10)
usbip.exe bind -b 1-50
usbip: info: bind_device: bind device on busid 1-50: complete
usbipd.exe -d -4
usbipd: info: starting usbipd (usbip 1.0.0)
usbip: debug: C:\work\usbip-win\userspace\src\usbipd\usbipd_sock.c:38:[build_sockfd] opening 0.0.0.0:3240
usbip: info: listening on 0.0.0.0:3240
[root@localhost usb]# modprobe vhci-hcd
[root@localhost usb]# lsmod | grep usbip
usbip_host 23823 0
usbip_core 27289 2 usbip_host,vhci_hcd
[root@localhost usb]# usbip list --remote=172.20.156.105
Exportable USB devices
======================
- 172.20.156.105
1-50: unknown vendor : unknown product (ffff:5678)
: \\?\usb#vid_ffff&pid_5678#2584371134226106772#{fb265267-c609-41e6-8eca-a20d92a833e6}
: (Defined at Interface level) (00/00/00)
[root@localhost usb]# usbip attach -r 172.20.156.105 -b 1-50
mkdir usb
mount /dev/sdc1 usb
[root@localhost usb]# docker run -it --name=usbiptest --privileged=true --device=/dev/sdc1 centos
[root@7ecc2247138b /]# fdisk -l
Disk /dev/sda: 447.1 GiB, 480103981056 bytes, 937703088 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x000df1cc
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 6143 4096 2M 83 Linux
/dev/sda2 * 6144 2103295 2097152 1G 83 Linux
/dev/sda3 2103296 937701375 935598080 446.1G 8e Linux LVM
Disk /dev/dm-0: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/dm-1: 64 GiB, 68719476736 bytes, 134217728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/dm-2: 302.1 GiB, 324404248576 bytes, 633602048 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sdd: 29.3 GiB, 31457280000 bytes, 61440000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xea860f1a
Device Boot Start End Sectors Size Id Type
/dev/sdd1 * 2048 61439999 61437952 29.3G c W95 FAT32 (LBA)
[root@7ecc2247138b /]# mkdir usb
[root@7ecc2247138b /]# mount /dev/sdd1 usb
[root@7ecc2247138b /]# df -h
Filesystem Size Used Avail Use% Mounted on
overlay 302G 108G 195G 36% /
tmpfs 64M 0 64M 0% /dev
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-var 302G 108G 195G 36% /etc/hosts
shm 64M 0 64M 0% /dev/shm
/dev/sdd1 30G 1.5M 30G 1% /usb
[root@7ecc2247138b /]# cd usb
[root@7ecc2247138b usb]# ls
'System Volume Information' images
success!
说明:
装有usb设备的装载usbip-host, 客户端装载vhci-hcd, 2台Windows作为host分别插一个usb
[root@localhost usb]# usbip list --remote=172.20.156.105
Exportable USB devices
======================
- 172.20.156.105
1-50: unknown vendor : unknown product (ffff:5678)
: \\?\usb#vid_ffff&pid_5678#2584371134226106772#{fb265267-c609-41e6-8eca-a20d92a833e6}
: (Defined at Interface level) (00/00/00)
[root@localhost usb]# usbip attach -r 172.20.156.105 -b 1-50
[root@localhost ~]# usbip list --remote=172.20.156.116
Exportable USB devices
======================
- 172.20.156.116
1-176: Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) : Flash Drive (090c:1000)
: \\?\usb#vid_090c&pid_1000#7&6af1be0&0&2#{fb265267-c609-41e6-8eca-a20d92a833e6}
: (Defined at Interface level) (00/00/00)
[root@localhost ~]# usbip attach -r 172.20.156.116 -b 1-176
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 91M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 80G 3.9G 77G 5% /
/dev/sda2 1014M 193M 822M 19% /boot
/dev/mapper/centos-var 302G 108G 195G 36% /var
tmpfs 13G 0 13G 0% /run/user/0
/dev/sdb1 30G 20G 9.8G 67% /mnt/usb
/dev/sdd1 30G 1.5M 30G 1% /root/usb
/dev/sde1 7.7G 1.3G 6.4G 17% /root/usb2
[root@localhost ~]# docker run -it --name=usb2 --privileged=true --device=/dev/sde1 centos
[root@885d01f7a932 /]# fdisk -l
Disk /dev/sda: 447.1 GiB, 480103981056 bytes, 937703088 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x000df1cc
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 6143 4096 2M 83 Linux
/dev/sda2 * 6144 2103295 2097152 1G 83 Linux
/dev/sda3 2103296 937701375 935598080 446.1G 8e Linux LVM
Disk /dev/dm-0: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/dm-1: 64 GiB, 68719476736 bytes, 134217728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/dm-2: 302.1 GiB, 324404248576 bytes, 633602048 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sdd: 29.3 GiB, 31457280000 bytes, 61440000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xea860f1a
Device Boot Start End Sectors Size Id Type
/dev/sdd1 * 2048 61439999 61437952 29.3G c W95 FAT32 (LBA)
Disk /dev/sde: 7.6 GiB, 8178892800 bytes, 15974400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc3072e18
Device Boot Start End Sectors Size Id Type
/dev/sde1 * 56 15974399 15974344 7.6G c W95 FAT32 (LBA)
[root@885d01f7a932 /]# mkdir usb
[root@885d01f7a932 /]# mount /dev/sde1 usb
[root@885d01f7a932 /]# df -h
Filesystem Size Used Avail Use% Mounted on
overlay 302G 108G 195G 36% /
tmpfs 64M 0 64M 0% /dev
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-var 302G 108G 195G 36% /etc/hosts
shm 64M 0 64M 0% /dev/shm
/dev/sde1 7.7G 1.3G 6.4G 17% /usb
[root@885d01f7a932 /]# cd usb
[root@885d01f7a932 usb]# ls
'2015060103007 ???.docx' '??' '????2019??' '???????????.docx'
'2015060103007 ???.pdf' '??' '????2019??.zip' '??PPT 149?'
'201922081221 ???' '???' '?????+??' 'System Volume Information'
'201922081221-???.docx' '???' '??????.pptx' 'fs????'
'??' '????' '????????' '~$??????.pptx'
[root@00d8d0036b78 /]# mkdir usb
[root@00d8d0036b78 /]# mount /dev/sdd1 usb
[root@00d8d0036b78 /]# cd usb
[root@00d8d0036b78 usb]# ls
'System Volume Information' images
并行性测试成功!