Linux usb 5. usbip (USB Over IP) 使用实例
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
0. 简介
USB Over IP 是一种应用很多的场景,目前已经有现成的解决方案 usbip
。linux 和 windows 环境下都有配套软件,本文不分析原理就验证一下 Linux 环境下 usbip 功能的使用。
1. Server 配置
运行环境为 ubuntu 20.04.2。操作命令如下:
// (1) 关闭防火墙
$ sudo ufw disable
// (2) 加载 server 端驱动
$ cd /lib/modules/`uname -r`/kernel/drivers/usb/usbip
$ sudo insmod usbip-core.ko
$ sudo insmod usbip-host.ko
// (3) 编译安装 usbip 用户态工具
$ cd /lib/modules/`uname -r`/build/tools/usb/usbip
$ ./autogen.sh && ./configure && make && sudo make install
$ sudo echo "/usr/local/lib/" >> /etc/ld.so.conf
$ sudo ldconfig
// (4) 启动 usbip server 守护进程
$ sudo usbipd -D
// (5) 查询 server 端可用的 device
$ usbip list -l
usbip: error: failed to open /usr/share/hwdata//usb.ids
- busid 2-1 (0e0f:0003)
unknown vendor : unknown product (0e0f:0003)
- busid 1-2 (0781:5567)
unknown vendor : unknown product (0781:5567)
$ lsusb
Bus 001 Device 007: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
// (6) 将其中的 u盘设备 export 出去
$ sudo usbip bind --busid 1-2
usbip: info: bind device on busid 1-1: complete
2. Client 配置
运行环境为 ubuntu 20.04.2。操作命令如下:
// (1) 关闭防火墙
$ sudo ufw disable
// (2) 加载 client 端驱动
$ cd /lib/modules/`uname -r`/kernel/drivers/usb/usbip
$ sudo insmod usbip-core.ko
$ sudo insmod vhci-hcd.ko
// (3) 编译安装 usbip 用户态工具
$ cd /lib/modules/`uname -r`/build/tools/usb/usbip
$ ./autogen.sh && ./configure && make && sudo make install
// (4) 查询 server export 出来的 device
$ sudo usbip list --remote 192.168.232.128
usbip: error: failed to open /usr/share/hwdata//usb.ids
Exportable USB devices
======================
- 192.168.232.128
1-2: unknown vendor : unknown product (0781:5567)
: /sys/devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2
: (Defined at Interface level) (00/00/00)
// (5) 挂载 server 设备到 client 本地
$ sudo usbip attach --remote 192.168.232.128 -b 1-2
usbip: debug: usbip.c:129:[run_command] running command: `attach'
usbip: debug: usbip_attach.c:100:[import_device] got free port 0
libusbip: debug: vhci_driver.c:367:[usbip_vhci_attach_device2] writing: 0 3 65543 3
libusbip: debug: vhci_driver.c:372:[usbip_vhci_attach_device2] attach attribute path: /sys/devices/platform/vhci_hcd.0/attach
libusbip: debug: vhci_driver.c:380:[usbip_vhci_attach_device2] attached port: 0
// (6) 查看本地 usb 设备,已经可用看到 u盘设备,功能可用正常使用
$ sudo usbip port
usbip: error: failed to open /usr/share/hwdata//usb.ids
Imported USB devices
====================
Port 00: <Port in Use> at High Speed(480Mbps)
unknown vendor : unknown product (0781:5567)
3-1 -> usbip://192.168.232.128:3240/1-2
-> remote bus/dev 001/007
$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 2a45:0004 Meizu Corp. PRO 6
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
参考资料
1.USB/IP PROJECT
2.usbip/README
3.myusbip
4.USBIP介绍
5.USB/IP - a Peripheral Bus Extension for Device Sharing over IP Network
6.USB/IP: A Transparent Device Sharing Technology over IP Network
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献18条内容
所有评论(0)