Resumo

This blog post presents a way to enable the use of CAN network in WSL. To do this, it is essential to have WSL installed on your computer so that you can use a custom Kernel with CAN network modules enabled.

First of all, update your system.

sudo apt-get update -y

Then download the Kernel from the GitHub repository. Note that the linux-msft-wsl-X.X.y section should be replaced with the desired version, for example, linux-msft-wsl-5.15.y. To check which version of WSL you are using use uname -r

git clone https://github.com/microsoft/WSL2-Linux-Kernel.git --depth=1 -b linux-msft-wsl-X.X.y

Now copy the modules to a .config file

cd WSL2-Linux-Kernel
cat /proc/config.gz | gunzip > .config

Then install the required packages.

sudo apt update && sudo apt install build-essential flex bison libssl-dev libelf-dev bc python3 pahole

Now use the following commands to build the custom kernel.

make prepare modules_prepare
make menuconfig

A screen will now appear to select the modules that should be installed. In this screen, select Networking Support, then press M on the CAN bus subsystem support option. Then press Enter to access this option and mark with M the modules you want to install.

Finally, build the custom kernel.

make -j4
sudo make module_install

Finally, copy the BzImage file that will be located in arch/x86/boot/bzImage to the Windows folder C: and create a .wslconfig file with the text below in C:\<User>\>

[wsl2]
kernel=C:\\bzImage

Minha Opinião

Esta é a maneira mais simples de habilitar uma rede virtual CAN network no Windows. Infelizmente, esta função não é habilitada diretamente, mas pode ser usada com alguma facilidade usando o método indicado acima.