Complete Guide to Install, Share, and Maintain a USB Device in WSL2 with usbipd
This guide applies to WSL2, which has NAT (Network Address Translation) networking capabilities. USB forwarding with usbipd does not work with WSL1.
Step 1: Install usbipd-win on Windows
- Open PowerShell with administrator privileges.
- Run the following command to install
usbipdin windows:
winget install usbipd
- Confirm the installation by checking the version:
usbipd --version
Step 2: Share USB Device with WSL2
- Connect the USB device to Windows and list all available USB devices using:
usbipd list
- By default devices are not shared with USBIP clients. To share devices, run the following commands with administrator privileges:
usbipd bind --busid=<BUSID>
For example, if the busid is 3-2:
usbipd bind --busid=3-2
[!TIP] Sharing a device is persistent; it survives reboots.
- Attach the desired device to WSL2 by specifying its
busid.
usbipd attach --wsl --busid=<BUSID>
For example, if the busid is 3-2:
usbipd attach --wsl --busid=3-2
[!TIP] Attaching devices to a client is non-persistent. You will have to re-attach after a reboot, or when the device resets or is physically unplugged/replugged.
- In WSL2, verify the connection using:
lsusb
Step 3: Prevent USB Disconnection in WSL2
The USB device may get automatically detached after a few minutes of idling, on system resets, or if WSL2 exits. Here’s how to mitigate these issues:
1. Reattach Device on WSL2 Launch
Each time WSL2 restarts, you’ll need to reattach the device using:
usbipd attach --wsl --busid=<busid>
You could create a PowerShell or Bash script that runs this command each time WSL2 starts to automate the process.
2. Disable USB Power Management to Prevent Timeout
- Open Device Manager by pressing Win + X and selecting it from the menu.
- Expand Universal Serial Bus controllers.
- Find the related USB Root Hub.
- Right-click the USB Root Hub and select Properties.
- Under the Power Management tab, uncheck Allow the computer to turn off this device to save power.