Serial Support WSL2

This is a guide on how I get my Sonoff Zigbee 3.0 Dongle (CP210x) working through WSL2 using a custom kernel.

Guide

  1. In a WSL2 instance install the dependencies for building the custom kernel.
    sudo apt install build-essential flex bison libssl-dev libelf-dev dwarves libncurses-dev

  2. Clone the WSL2 Linux Kernel (–depth 1 gets only the latest commit)
    git clone https://github.com/microsoft/WSL2-Linux-Kernel.git --depth 1

  3. Navigate to the WSL2-Linux-Kernel folder
    cd WSL2-Linux-Kernel

  4. Edit the kernel build configuration
    make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl

  5. Go to Device Drivers -> USB Support -> USB Serial Converter support and enable the drivers you need. (For the Sonoff Dongle, CP210x is required. Other drivers may be used for different devices).

  6. To make this baked into the kernel, press space twice so that <*> is displayed instead of <M>

  7. Save and Exit (Press S once and then ESC until exit menu is shown)

  8. Build the kernel (-4j or -8j to speed this process up)
    make KCONFIG_CONFIG=Microsoft/config-wsl -4j

  9. Copy kernel to Windows
    cp arch/x86/boot/bzImage /mnt/c/Users/<your-user-name-here>/wsl_kernel

  10. Create a file in your Windows user directory called .wslconfig and add this:

[wsl2]
kernel = C:\\Users\\<your-user-name-here>\\wsl_kernel

You can now restart your WSL2 instance and connect the device by USB like normal, using this method

Thanks to Leo Bound for all of this information

3 Likes

Just wanted to verify that now on kernel “5.10.102.1-microsoft-standard-WSL2” the cpx210x driver seems included, right?

I am having problems getting my Sonoff Zigbee 3.0 Dongle (CP210x) to work using WSL2 (Ubuntu 22.04) and Home Assistant in Docker but running “lsusb -t” I get;
Port 1: Dev 2, If 0, Class=Vendor Specific Class, Driver=cp210x, 12M
so guessing I don’t need to compile a custom kernel for it?