Microsoft introduced Windows Subsystem for Linux (WSL), enabling users to run Linux apps directly from their Windows installation without needing a virtual machine. Initially, WSL had its limitations, primarily due to the lack of a full-fledged Linux kernel, causing compatibility issues with several applications. WSL version 2 addressed many of these issues, but one crucial feature was still missing: the ability to connect physical USB devices.
For those who actively use WSL and want to access USB devices from within the Linux instance running under WSL, there’s good news. Thanks to Microsoft’s contributions to the open-source usbipd-win project, USB pass-through access is now possible in WSL. This allows users to perform tasks like flashing Android devices under WSL, which were previously unsupported by the Linux subsystem.
What is usbipd-win?
The usbipd-win project aims to provide a solution for sharing locally connected USB devices with other machines, including Hyper-V guests and WSL2. Initially, the official WSL2 Linux kernel lacked support for the USB/IP protocol, requiring users to build the kernel themselves.
Since WSL kernel version 5.10.60.1, the necessary parameters are pre-configured, eliminating the need for manual recompilation. Microsoft also contributed a command-line interface to the project, enabling USB device sharing on Windows and seamless attachment from within WSL.
Connecting USB Devices under WSL
Before starting, ensure you are running Windows 11 and have installed all WSL updates. You need a WSL 2 Linux distro for this to work. Run the following command from within WSL:
uname -a
If it shows a kernel version of 5.10.60.1 or later, you’re good to go. If the installed kernel version is older, update it using the following commands:
wsl --shutdown
wsl --update
Next, visit the usbipd-win project’s GitHub repo, download, and install the latest release. The latest version supports silent driver installation and Dev channel builds of Windows 11. You can also install and update the app using Windows Package Manager CLI:
winget install --interactive --exact dorssel.usbipd-win
Install the user space tools for USB/IP and a database of USB hardware identifiers. For Ubuntu on WSL, run:
sudo apt install linux-tools-virtual hwdata
sudo update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20
You may need to adjust the path variable for other distros based on the version number of the meta package.
If the symbolic link created using the update-alternatives command doesn’t work, manually modify the sudo options to allow the root user to find the usbip command. Edit the /etc/sudoers file using sudo visudo
and add /usr/lib/linux-tools/<version-number>-generic
to the beginning of secure_path.
Open a new Terminal instance as Administrator and list all the USB devices connected to Windows:
usbipd wsl list
Note the BUSID value of the USB device you want to attach to WSL and run the following command to initiate the attachment process:
usbipd wsl attach --busid <busid>
For example, to attach an Android device’s Fastboot interface:
usbipd wsl attach --busid <busid>
Open a new WSL 2 instance and run lsusb
to see the available USB devices. You can now work with your USB device from WSL.
When you’re done, detach the device using:
usbipd wsl detach --busid <busid>
GUI Alternative
If the command-line interface isn’t your preference, try wsl-usb-gui
, an unofficial GUI wrapper around the usbipd-win binary. It simplifies USB device listing and interoperability between the host OS and WSL instance. Ensure the latest version of usbipd-win is installed and the WSL kernel is up-to-date. Download the latest wsl-usb-gui
installer from the project’s GitLab releases page and run the MSI file. Upon successful installation, find the WSL USB shortcut in the Start menu, run the app, and use the Attach and Detach buttons to manage USB pass-through.
From here, you’re ready to tinker with all your USB devices in WSL. For more information, refer to Microsoft’s official documentation and usbipd-win’s GitHub Wiki section.