Connect USB devices to WSL2 on Windows 10
How to connect USB devices to WSL2 distribution running on Windows 10
Intro
Using WSL2 on Windows 10 is nice but it does not support USB out of the box.
To do so you will need to recompile the Linux Kernel used by your WSL distro, install usbipd
on your windows machine and grant your user admin rights.
Create a new distro with USB/IP enabled
To do so follow the excellent guide from the USB/IP repo here.
<install-path>
can be any path on your PC, I’ve set it to my user home.<user>
is the username used in your original SWL2 instance.
The new WSL2 distribution wsl2-usbip
will have the kernel module to work with USB\IP.
Note that this distribution does not share data with the original distribution.
Install USBIPd on windows 10
winget install usbipd
This should be enough. Check dorssel/usbipd-win for more info.
Grant your user admin rights
If you are like me and your user does not have admin rights but you have access to an admin user do as follow:
Open a powershell
with admin right
Add-LocalGroupMember -Group "Administrators" -Member "<GROUP>\<user.name>"
More info here.
Connect USB to WSL distribution
Discover which USB device you can share with WSL2.
In powershell
or cmd
C:\Program Files\usbipd-win> .\usbipd.exe wsl list
BUSID VID:PID DEVICE STATE
2-4 04d9:0296 USB Input Device Not attached
2-6 0c45:6a09 Integrated Webcam Not attached
2-8 0a5c:5842 Dell ControlVault w/o Fingerprint Sensor, Microsoft Usbcc... Not attached
2-10 8087:0026 Intel(R) Wireless Bluetooth(R) Not attached
4-2 0bda:8153 Realtek USB GbE Family Controller #2 Not attached
5-4 046d:0825 USB Video Device, USB Audio Device Not attached
8-1 046d:c246 USB Input Device Not attached
11-3 0b0e:0300 Jabra EVOLVE 20 SE MS, USB Input Device Not attached
11-4 0483:3748 STM32 STLink Not attached
connect i.e STM32 STLink
in powershell
or cmd
with admin rights (elevated)
.\usbipd.exe wsl attach --busid 11-4 --distribution wsl2-usbip
in the WSL2 shell (wsl2-usbip
) that you can ran with wsl --distribution wsl2-usbip --user <user>
❯ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 0483:3748 STMicroelectronics ST-LINK/V2
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Enjoy.