Issue: You can use FTDI based USB devices such as microcontroller boards and embedded products in Ubuntu Linux on physical devices and on full flegded VMs but under WSL2 the device does not work. You can successfully map the USB device in usbipd and you see it show up in lsusb, dmesg, journal. But no new serial device shows up under /dev/tty* and you cannot use the device.
Background: Ubuntu under Windows 11 WSL2 as of 2024/04 does not include the ftdi-sio driver in its default kernel builds. You cannot easily install that driver from the package manager either. Under WSL, similar to container environments and solaris zones, all linux guests use the same kernel.
Solution: Build and install a custom linux kernel with builtin FTDI drivers. At the time of writing, the default WSL kernel is 5.15 and the latest WSL branch is 6.1
Enter the Ubuntu WSL environment:
# If ubuntu is your only WSL or your default WSL, simply type "wsl"
# Double check with wsl -l if your ubuntu has another name like Ubuntu-22.04
# Mine is just called "Ubuntu"
wsl -d Ubuntu
Now download Microsoft’s modified kernel distribution and build it
git clone https://github.com/microsoft/WSL2-Linux-Kernel.git --depth=1 -b linux-msft-wsl-6.1.y
sudo apt update
sudo apt -y install build-essential flex bison libssl-dev libelf-dev bc
sudo apt -y install python3 pahole
cd WSL2-Linux-Kernel
## This line turns the FTDI driver from disabled or module to builtin
./scripts/config --file Microsoft/config-wsl --set-val CONFIG_USB_SERIAL_FTDI_SIO y
make -j$(nproc) KCONFIG_CONFIG=Microsoft/config-wsl
sudo make modules_install headers_install
## Use another target directory if you don't want the kernel in the root of C:\
cp arch/x86/boot/bzImage /mnt/c/bzImage-6.1
Leave the VM.
Back in Windows Terminal, run
wsl --shutdown
cd ~
notepad .wslconfig
Add or edit in the file:
[wsl2]
kernel=C:\\Users\\yourusernamehere\\bzImage-6.1
memory=4GB
Save the file.
Then run “wsl” or “wsl -d yourdistribution” to restart into the new kernel
To verify inside wsl, run
uname -a
## Expect output similar to
## Linux W-PF384K2W 6.1.21.2-microsoft-standard-WSL2+ #1 SMP Tue Apr 2 22:11:36 CEST 2024 x86_64 x86_64 x86_64 GNU/Linux
Note: In some cases, Windows will not actually terminate WSL and you need a full reboot of the host windows computer.