Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
recompile wsl2 kernel, add modules and CAN modules + can utils.
mines ubuntu 20.04 based, WSL2
in windows
wsl --list -v
* Ubuntu-20.04 Stopped 2
in wsl
# the old update routine
sudo apt-get update -y
# add tools to build kernel, apologies if i missed anything as i already have a bunch of dev stuff setup
sudo apt-get install -y autoconf bison build-essential flex libelf-dev libncurses-dev libssl-dev libtool libudev-dev
#get kernel version
uname -r
# get matching version, this is mine
#extract it (change to your kernel version)
tar -xf linux-msft-wsl-
# build linux/modules
# change to the folder tar extracted too, yours might be different, i usually set a link from WSL-Linux-Kernel to the current
cd WSL2-Linux-Kernel-linux-msft-wsl-
cat /proc/config.gz | gunzip > .config
make prepare modules_prepare -j $(expr $(nproc) - 1)
# select vcan and can subsystems here
make menuconfig -j $(expr $(nproc) - 1)
make modules -j $(expr $(nproc) - 1)
sudo make modules_install
make -j $(expr $(nproc) - 1)
sudo make install
# copy it to windows drive
cp vmlinux /mnt/c/Users/<yourwindowsloginname>/
#create this file, change /<yourwindowsloginname> to your windows users directory name
vi /mnt/c/Users/<yourwindowsloginname>/.wslconfig
#with these contents
# exit wsl
in windows
rem reboot wsl entirely
wsl --shutdown
rem restart wsl
in wsl
sudo modprobe vcan
#if it fails, check dmesg as kernel messages are limited back to modprobe and its terse
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
# add can-utils
sudo apt install can-utils
#add can_raw
sudo modprobe can_raw
#do something with it
candump -c -c -ta vcan0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment