Skip to content

Instantly share code, notes, and snippets.

@jlcarruda
Last active December 26, 2023 21:55
Show Gist options
  • Save jlcarruda/7ee5a94b01bd921e70e6bfeb6a60a973 to your computer and use it in GitHub Desktop.
Save jlcarruda/7ee5a94b01bd921e70e6bfeb6a60a973 to your computer and use it in GitHub Desktop.
Build a custom Kernel for WSL2 for module load
[wsl2]
kernel=C:\\Users\\WIN10_USER\\bzimage

On WSL2

sudo apt install build-essential flex bison libssl-dev libelf-dev dwarves
git clone https://github.com/microsoft/WSL2-Linux-Kernel.git
cd WSL2-Linux-Kernel
cp Microsoft/config-wsl .config
make -j $(expr $(nproc) - 1)

On Windows

  • Copy \\wsl$\<DISTRO>\home\<USER>\WSL2-Linux-Kernel\arch\x86\boot\bzimage to %userprofile%
  • Put on %userprofile% the .wslconfig file (or add the kernel config on an existing one)
  • Shutdown WSL with wsl --shutdown
  • Reopen WSL2 Flavor

Back on WSL2

  • Copy the Makefile on home folder
  • run make on home
obj-m:=lkm_example.o
all:
make -C $(shell pwd)/WSL2-Linux-Kernel M=$(shell pwd) modules
clean:
make -C $(shell pwd)/WSL2-Linux-Kernel M=$(shell pwd) clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment