WSL Using USB Device
Brief
About how to enable USB device under wsl.
Update WSL
Run Powershell
with administrator privilege, and input the following instructions:
List installed WSL distro:
wsl -l -v
The result may look like:
NAME STATE VERSION
* Ubuntu-20.04 Running 2
docker-desktop-data Stopped 2
Ubuntu Stopped 2
The asterisk indicates the default WSL distro. If it is docker-desktop-data
, it may not run, so change it to Ubuntu-20.04
or Ubuntu
:
wsl --set-default Ubuntu-20.04
Then shutdown WSL, update WSL and then restart it.
wsl --shutdown
wsl --update
Install Linux-Tools
Install linux tools:
sudo apt install linux-tools-5.8.0-63-generic hwdata
Add it to sudoers:
sudo vim /etc/sudoers
Modify the line of Defaults secure_path=… to include linux-tools:
Defaults secure_path="/usr/lib/linux-tools/5.8.0-63-generic:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
Force to save the /etc/soduers
file.
Install usbipd
The usbipd can be download from here.
Now run Powershell
as administrator.
Run the following command to list all USB devices:
usbipd wsl list
The result looks like:
BUSID DEVICE STATE
1-10 H100i v2 Not attached
1-13 Intel(R) Wireless Bluetooth(R) Not attached
10-2 USB Input Device Not attached
10-4 Logitech USB Input Device, USB Input Device Not attached
10-5 USB Input Device Not attached
16-1 USB Mass Storage Device Not attached
16-3 USB Audio Device, USB Input Device, USB Mass Storage Devi... Not attached
17-3 STMicroelectronics STLink Virtual COM Port, STMicroelectr... Not attached
18-1 J-Link driver Not attached
18-2 J-Link driver Not attached
18-3 USB-SERIAL CH340 Not attached
19-1 Generic Bluetooth Radio Not attached
19-4 150Mbps Wireless 802.11bgn Nano USB Adapter Not attached
To attach the second J-Link device to WSL:
usbipd wsl attach -b 18-2
To check if the USB device has been attached to WSL, in WSL, run:
lsusb
The result shows:
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 1366:0101 SEGGER J-Link PLUS
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Reference
The original reference.
Good luck.