It is now possible to connect USB devices in WSL and work with them directly. Thanks to Microsoft's contributions to open-source usbipd-win project, you can do a variety of tasks which weren't available in WSL, like flashing an Arduino or accessing a smartcard reader.
The feature requires you to have the second gen of WSL with a kernel version 5.10.60.1 or later.
Usbipd-win is a software for sharing locally connected USB devices to other machines, including Hyper-V guests and WSL 2. It supports silent driver installation thanks to use of Microsoft Hardware Compatibility Publisher drivers. It also supports Dev channel builds, so you can try it even if you run a pre-release Windows 11. Finally, in addition to the release page on GitHub, you can install and update the app with winget
.
Here's how to use it to connect USB devices under WSL.
Connect USB devices in WSL
- Head over this GitHub page, download and install the latest app version.
- Open your Ubuntu WSL 2 instance and type
sudo apt install linux-tools-5.4.0-77-generic hwdata
. - Now, modify the sudo options to allow the
root
user to run the usbip command. For that, typesudo visudo
and hit Enter. - Add /usr/lib/linux-tools/5.4.0-77-generic to the beginning of secure_path. You will get something like this:
Defaults secure_path="/usr/lib/linux-tools/5.4.0-77-generic:/usr/local/sbin:..."
. - Open a new command prompt as administrator.
- Type usbipd wsl list and hit Enter.Note the BUS ID value for the USB device you want to attach to WSL.
- Now, run this command:
usbipd wsl attach --busid <busid>
. Substitute the <busid> value with the one you noted. - Finally, open your WSL 2 instance and run the lsusb command to see available USB devices. It should list your attached device.
You are done!
You can now work with your USB device right from WSL.
When finished, detach the device using the usbipd wsl detach --busid <busid>
. Again, run it from a command prompt running as administrator.
You can learn more on how it works in the official announcement.
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
I just want to do the reverse! You might be amazed where did I find usb from wsl first. Calm down I just mount it from remote computer to my wsl machine. Then I want to mount to windows host. I have full reason to do that.