Skip to main content

Complete Guide to Install, Share, and Maintain a USB Device in WSL2 with usbipd

note

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

  1. Open PowerShell with administrator privileges.
  2. Run the following command to install usbipdin windows:
winget install usbipd
  1. Confirm the installation by checking the version:
usbipd --version

Step 2: Share USB Device with WSL2

  1. Connect the USB device to Windows and list all available USB devices using:
usbipd list
  1. 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.

  1. 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.

  1. 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

  1. Open Device Manager by pressing Win + X and selecting it from the menu.
  2. Expand Universal Serial Bus controllers.
  3. Find the related USB Root Hub.
  4. Right-click the USB Root Hub and select Properties.
  5. Under the Power Management tab, uncheck Allow the computer to turn off this device to save power.