Skip to content

Instantly share code, notes, and snippets.

@charlie-x
Created July 28, 2021 20:55
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save charlie-x/96a92aaaa04346bdf1fb4c3621f3e392 to your computer and use it in GitHub Desktop.
Save charlie-x/96a92aaaa04346bdf1fb4c3621f3e392 to your computer and use it in GitHub Desktop.
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
5.10.16.3-microsoft-standard-WSL2
# get matching version, this is mine
wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-5.10.16.3.tar.gz
#extract it (change to your kernel version)
tar -xf linux-msft-wsl-5.10.16.3.tar.gz
# 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-5.10.16.3/
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
[wsl2]
kernel=C:\\Users\\<yourwindowsloginname>\\vmlinux
# exit wsl
exit
in windows
rem reboot wsl entirely
wsl --shutdown
rem restart wsl
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
@yves-chevallier
Copy link

Missing : sudo apt install dwarves

@david-yyongning
Copy link

david-yyongning commented Feb 24, 2024

Missing : sudo apt install dwarves

same here. Just install dwarves.
Thanks @charlie-x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment