# 在 WSL 2 中访问 USB 设备(以大疆 4G 模块为例)
Linux 支持 USB/IP 协议,可以通过网络访问其它设备上的 USB 设备。usbipd-win 是一个让 Windows 支持 USB/IP 协议的工具。所以,如果在作为宿主机的 Windows 上安装 usbipd-win,就可以把 Windows 的 USB 设备通过 USB/IP 协议映射到 WSL 2 中。
## 测试环境和对象
以下测试环境的宿主机为 Windows 10 22H2;WSL 2 中的系统为 Ubuntu 26.04 LTS;所用 USB 设备为大疆 4G 模块。
## 操作步骤
在 Windows 上安装 usbipd-win:
```cmd
winget install usbipd
```
把大疆 4G 模块接入系统,等待 Windows 完成设备安装。Windows 没有该设备的驱动,这是正常的。
此时在 Windows 上执行 `usbipd list` 可以看到对应的设备信息:
```cmd
> usbipd list
Connected:
BUSID VID:PID DEVICE STATE
2-11 2ca3:4006 EG25G-QDC507 Not shared
```
然后把设备映射到 WSL 2 中,注意需要以管理员身份执行:
```cmd
> usbipd bind --busid 2-11
> usbipd attach --wsl --busid 2-11
usbipd: info: Using WSL distribution 'Ubuntu' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Loading vhci_hcd module.
usbipd: info: Detected networking mode 'nat'.
usbipd: info: Using IP address 172.24.80.1 to reach the host.
```
设备映射到 WSL 2 中后,在 Windows 的设备管理器中就消失了。此时在 WSL 2 中运行 `lsusb` 可看见:
```bash
Bus 001 Device 002: ID 2ca3:4006 DJI Technology Co., Ltd. EG25G-QDC507
```
如果要解除设备映射可执行:
```cmd
> usbipd detach --busid 2-11
```