The WSL2 Linux kernel is source code is publicly available at https://github.com/microsoft/WSL2-Linux-Kernel
In the past, WSL2 lacked features to run an OS-level Wireguard client or firewall. Rebuilding was necessary to add those features.
But currently, Debian 13 on WSL2 has all of these features. Customizing the kernel will rarely be needed.
Open a Terminal and connect to WSL2.
Install the necessary packages for software development:
sudo apt update
sudo apt install build-essential flex bison libssl-dev libelf-dev libncurses-dev bc git dwarves
Clone the source code, saving space by not downloading the history:
git clone --depth 1 https://github.com/microsoft/WSL2-Linux-Kernel.git
Edit the configuration options:
cd WSL2-Linux-Kernel
vi Microsoft/config-wsl
Modify the options you need to. In fact, most of these are enabled, so this page will be updated later 8-)
Compile the kernel:
make KCONFIG_CONFIG=Microsoft/config-wsl -j$(nproc)
Copy it to Windows profile (replace or assign $USERPROFILE)
cp arch/x86/boot/vmlinux /mnt/c/Users/$USERPROFILE/vmlinux-custom
Create or edit a custom .wslconfig:
vi /mnt/c/Users/$USERPROFILE/.wslconfig
[wsl2]
kernel=C:\\Users\\$USERPROFILE\\vmlinux-custom
Exit WSL2 and restart it:
exit
wsl --terminate Debian
wsl -d Debian