Skip to content

Instantly share code, notes, and snippets.

@charlie-x
Created July 28, 2021 20:55
Show Gist options
  • 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

@warpoons
Copy link

warpoons commented Jun 4, 2024

For error bc: not found when executing make prepare modules_prepare -j $(expr $(nproc) - 1), please refer to here by sudo apt-get install bc.

And for selecting vcan and can after executing make menuconfig -j $(expr $(nproc) - 1), please refer to here.

@warpoons
Copy link

warpoons commented Jun 4, 2024

Hi @charlie-x @yves-chevallier @david-yyongning. Thanks for your great suggestion!

I am currently encountering the exception that all these commands are executed successfully without errors but running the last line candump -c -c -ta vcan0 has no responses, no logs and no exceptions and can only exit by ctrl+c.

and running sudo tc qdisc add dev eth0 root handle 1: tbf rate 300mbit burst 256kb latency 800ms reports Error: Specified qdisc not found.

Could you tell me how can I fixed it? Thanks!

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