At the time of writing WSL 2 does not have official support for interfacing with USB type devices. To solve this, a fork of the usbip project is modified by Microsoft to allow virtual connectivity between USB devices on a host via the USB/IP protocol.
Though it is recommended to use the usbip from a Windows 11 host, there is a way to build a custom WSL2 Kernel in Windows 10 with usbip driver support enabled for USB Mass Storage devices.
This is a supplementary guide which allows for a more linear step by step instruction to eliminate the confusion introduced by the official documentation.
from the windows command prompt
alternatively you can just install the MSI
winget install usbipd-win
from within WSL2 terminal
sudo apt install linux-tools-virtual hwdata
sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/*/usbip 20
export your current distro to a tar file as a failsafe:
wsl --list --verbose`
wsl --export <current-distro> <temporary-path>\wsl2-usbip.tar`
in case the build fails we can restore from this backup using the following commands:
wsl --import wsl2-usbip <install-path> <temporary-path>\wsl2-usbip.tar`
wsl --distribution wsl2-usbip --user <user>`
update your packages
sudo apt update && sudo apt upgrade
install prerequisite tools
sudo apt install build-essential \
autoconf \
bison \
dwarves \
flex \
libelf-dev \
libncurses-dev \
libssl-dev \
libtool \
libudev-dev
clone the repo
git clone https://github.com/microsoft/WSL2-Linux-Kernel.git
cd WSL2-Linux-Kernel
git checkout linux-msft-wsl-5.10.y
copy current config.gz
cp /proc/config.gz config.gz
gunzip config.gz
mv config .config
use menuconfig to select kernel features
You may need to set CONFIG_USB=y in .config prior to running menuconfig
sudo make menuconfig
Ensure that the following features are enabled (move = up/down, select = (s)pace)
Device Drivers -> USB Support
Device Drivers -> USB Support -> USB announce new devices
Device Drivers -> USB Support -> USB Modem (CDC ACM) support
Device Drivers -> USB Support -> USB/IP
Device Drivers -> USB Support -> USB/IP -> VHCI HCD
Device Drivers -> USB Support -> USB/IP -> Debug messages for USB/IP
Device Drivers -> USB Support -> USB Mass Storage Support
Device Drivers -> USB Support -> USB Mass Storage Support > USB Mass Storage Debug
Device Drivers -> USB Serial Converter Support
Device Drivers -> USB Serial Converter Support -> USB FTDI Single port Serial Driver
build the kernel
run
getconf _NPROCESSORS_ONLN
ornproc
to find the number of cores.
sudo make -j 8
alternatively you can directly install the kernel
sudo make -j 8 && sudo make modules_install -j 8 && sudo make install -j 8
build usb/ip tools
cd tools/usb/usbip
sudo ./autogen.sh
sudo ./configure
sudo make install -j 8
copy usbip library to /lib
sudo cp libsrc/.libs/libusbip.so.0 /lib/libusbip.so.0
install usb.ids for named display of usb devices
sudo apt install linux-tools-virtual hwdata
sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/*/usbip 20
from the project root copy the kernel image
cp arch/x86_64/boot/bzImage /path/to/destination/kernel
configure reference to the kernel image from wsl
vim /mnt/c/Users/user/.wslconfig
[wsl2]
kernel=c:\\path\\to\\destination\\kernel
restart WSL 2 from the windows command prompt
wsl --shutdown
https://aka.ms/wsl-usbip
https://github.com/dorssel/usbipd-win/wiki/WSL-support#building-your-own-usbip-enabled-wsl-2-kernel
https://docs.microsoft.com/en-us/windows/wsl/build-custom-distro
https://docs.microsoft.com/en-us/windows/wsl/use-custom-distro
Recommend adding a small note about modifying the kernel "Local version" so that you can easily confirm the installation of the kernel with
uname -r
. For example, appending "-usb" so thatuname -r
returns 5.10.x.y-microsoft-standard-WSL2+-usbRegardless, thank you for the guide! Very helpful.