> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# WSL 上的 USB 转发

> 使用 usbipd 将物理 USB 设备从 Windows 挂载到 WSL 环境中。

## 概述

在 Windows + WSL 上，USB 设备不会自动在 Linux 子系统内可见。`usbipd-win` 工具通过回环 IP 隧道将 USB 总线从 Windows 主机转发到 WSL，从而弥补这一差距。

<Note>
  `usbipd-win` 必须已经安装。如果尚未安装，请在 Windows 管理员终端中运行 `winget install usbipd-win`。
</Note>

## 分步操作

<Steps>
  <Step title="终止 Windows 上正在运行的 ADB 服务器">
    打开 **PowerShell（管理员模式）** 并运行：

    ```batch theme={null}
    adb kill-server
    ```

    <Info>
      如果 ADB 未在运行，此命令可能会报告错误 — 可以安全地忽略。
    </Info>
  </Step>

  <Step title="列出可用的 USB 设备">
    ```batch theme={null}
    usbipd list
    ```

    记下您的 Qualcomm 设备的 `BUSID`。
  </Step>

  <Step title="绑定设备（持久性，一次性操作）">
    ```batch theme={null}
    usbipd bind --busid=<BUSID>
    ```

    <Note>
      绑定在**重启后仍然保持**。如果您的设备暴露多个 USB 模式（例如 ADB + EDL），请对每个 `BUSID` 各绑定一次。
    </Note>

    <Warning>
      在某些企业机器上，`usbipd bind` 或后续的挂载步骤可能会因防火墙策略而失败。如果您看到明确的防火墙错误，请按照下面的**企业防火墙解决方法**操作。
    </Warning>
  </Step>

  <Step title="将设备挂载到 WSL 并启用自动重新挂载">
    ```batch theme={null}
    usbipd attach --wsl --busid=<BUSID> --auto-attach
    ```

    <Warning>
      * 保持此 PowerShell 窗口**打开** — 关闭它会停止自动挂载循环。
      * 每次重启 WSL 后，您都必须重新运行此命令。
      * 如果更换了物理 USB 端口，请从头重新运行所有 usbipd 命令。
    </Warning>

    下图展示了完整的绑定和挂载流程：

    <img src="https://mintcdn.com/qualcomm-prod/ajmq44Q1W0vLtUT4/Tools/QVSCE/images/usbipd-commands-attach.gif?s=c0963be0dfabd76a514ce1e474cf8cf3" alt="usbipd — 绑定和挂载命令" width="1112" height="618" data-path="Tools/QVSCE/images/usbipd-commands-attach.gif" />
  </Step>

  <Step title="在 WSL 内验证设备">
    在您的 WSL 终端中：

    ```bash theme={null}
    lsusb
    ```

    您应该能看到列出的 Qualcomm 设备。
  </Step>
</Steps>

## 企业防火墙解决方法

<AccordionGroup>
  <Accordion title="WSL 镜像网络 — 解决防火墙问题">
    1. 关闭所有打开的 WSL 终端。

    2. 在 PowerShell 中关闭 WSL：

    ```batch theme={null}
    wsl --shutdown
    ```

    3. 编辑 `%UserProfile%\.wslconfig` 并添加：

    ```ini theme={null}
    [wsl2]
    networkingMode=mirrored
    ```

    4. 重启 WSL：

    ```batch theme={null}
    wsl -d ubuntu-22.04
    ```

    5. 重试 `usbipd bind` 和 `usbipd attach` 步骤。
  </Accordion>
</AccordionGroup>

## 完成后分离 / 解绑

<CodeGroup>
  ```batch Detach theme={null}
  usbipd detach --busid=<BUSID>
  ```

  ```batch Unbind theme={null}
  usbipd unbind --busid=<BUSID>
  ```
</CodeGroup>
