Windows Subsystem for Linux and Hyper-V Get USB Passthrough Support
Windows Subsystem for Linux (WSL) is a feature in Windows that lets developers test and run Linux binaries directly from their desktop. The beauty of WSL is that there’s no need to switch between your Windows desktop and a virtual machine (VM) to develop Linux code.
For instance, you can open a Linux shell in Windows Terminal or use Visual Studio Code to build, debug, and run Linux apps without installing Linux in a VM. WSL brings developers the convenience of Windows with the power of Linux for app development.
If you are new to WSL, learn here how to install Windows Subsystem for Linux 2 and Ubuntu.
WSL has been generally welcomed by developers. And for most, it has proven more than adequate for their development needs on Windows. But developers working on IoT devices, where apps are developed for embedded Linux distributions, were left out in the cold because these devices connect to PCs via USB, which until now, wasn’t supported by WSL.
For more information on how to run Linux GUI apps using WSL, check out How to Install Linux GUI Apps in Windows 10 and Windows 11 with WSL on Petri.
Microsoft announced earlier this month that there’s now WSL support for USB device passthrough, albeit not natively. The functionality has been enabled by an open-source project called usbipd-win-project that lets developers use WSL in common scenarios that require USB connectivity, like flashing an Arduino or using a smartcard reader.
The project was originally started by Frans van Dorsselaer, a system architect based in Holland. Then it was picked up by a summer intern at Microsoft, Nelson Daniel Troncoso, a researcher and PhD student at Penn State University, who is responsible for the project in its current form.
How does USB device passthrough support work for WSL 2 and Hyper-V?
USBIPD works by using the USB/IP protocol to send USB traffic over the virtual network interface between Windows and WSL 2 or Hyper-V. Microsoft says that support for USB/IP has been in the Linux kernel since 2009 but that recent updates to Linux have made USB/IP easier to use in WSL.
Linux includes a USB/IP client, but Windows doesn’t natively have a USB/IP server. USBIPD fills that gap. Microsoft contributed the USBIPD command line tool to the project for enabling USB device sharing in Windows and for attaching devices in WSL.
How to use USB devices in Hyper-V and WSL 2
According to the project’s GitHub page, USBIPD works on Windows 8 and Windows Server 2012 or newer. The binaries install a service called USBIPD Device Host, a command line tool, and a Windows Firewall rule.
Installing the binaries is as easy as running the winget package manager command below:
winget install --interactive --exact dorssel.usbipd-win
You might be required to reboot your PC.
USB devices are not shared with USBIPD by default. To share a USB device, you should run the usbipd command line tool from a prompt with administrator privileges.
usbipd --help usbipd list usbipd bind --busid=<BUSID>
Share and connect a USB device to WSL 2
The above command works for Hyper-V guest VMs. But if you want to share and connect a USB device to WSL 2, it’s a bit more complicated. Microsoft provides detailed instructions for Windows 11 on its website for setting up USB device passthrough support in WSL 2.
For a complete walkthrough of how to connect USB devices to WSL 2, check out the video below from Microsoft.
More in Windows Client OS
Microsoft's September 2022 Patch Tuesday Updates Fix 64 Windows Vulnerabilities
Sep 14, 2022 | Laurent Giret
Windows Autopatch Gets Application-Based Authentication Support and More
Sep 8, 2022 | Rabia Noureen
How to Configure Windows Autopatch: A Step-by-Step Guide
Aug 24, 2022 | Dean Ellerby
How to Recover Your PC Using System Restore on Windows 10
Aug 23, 2022 | Michael Reinders
August Patch Tuesday Updates Fix 121 Vulnerabilities and Improve Focus Assist
Aug 10, 2022 | Laurent Giret
How to Set Up Amazon FSx for Windows File Server
Aug 5, 2022 | Arian Modiramani
Most popular on petri