The WSL2-Linux-Kernel repo contains the kernel source code and configuration files for the WSL2 kernel.
If you discover an issue relating to WSL or the WSL2 kernel, please report it on the WSL GitHub project. It is not possible to report issues on the WSL2-Linux-Kernel project.
If you're able to determine that the bug is present in the upstream Linux kernel, you may want to work directly with the upstream developers. Please note that there are separate processes for reporting a normal bug and a security bug.
Is there a missing feature that you'd like to see? Please request it on the WSL GitHub project.
If you're able and interested in contributing kernel code for your feature request, we encourage you to submit the change upstream.
Instructions for building an x86_64 WSL2 kernel with an Ubuntu distribution using bash are as follows:
-
Install the build dependencies:
$ sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev cpio qemu-utils
-
Modify WSL2 kernel configs (optional):
$ make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl
-
Build the kernel using the WSL2 kernel configuration and put the modules in a
modules
folder under the current working directory:
$ make KCONFIG_CONFIG=Microsoft/config-wsl && make INSTALL_MOD_PATH="$PWD/modules" modules_install
You may wish to include
-j$(nproc)
on the firstmake
command to build in parallel.
Then, you can use a provided script to create a VHDX containing the modules:
$ sudo ./Microsoft/scripts/gen_modules_vhdx.sh "$PWD/modules" modules.vhdx
To save space, you can now delete the compilation artifacts:
$ make clean && rm -r "$PWD/modules"
If you prefer, you can also build the modules VHDX manually as follows:
-
Calculate the modules size (plus 1024 bytes for slack):
modules_size=$(du -s "$PWD/modules" | awk '{print $1;}'); modules_size=$((modules_size + 1024));
-
Create a blank image file for the modules:
dd if=/dev/zero of="$PWD/modules.img" bs=1 count=$modules_size
-
Setup filesystem and mount img file:
lo_dev=$(losetup --find --show "$PWD/modules.img") && mkfs -t ext4 "$lo_dev" && sudo mount "$lo_dev" "$PWD/modules_img"
-
Copy over the modules, unmount the img now that we're done with it:
cp -r "$PWD/modules" "$PWD/modules_img" && sudo umount "$PWD/modules_img"
-
Convert the img to VHDX:
qemu-img convert -O VHDX "$PWD/modules.img" "$PWD/modules.vhdx"
-
Clean up:
rm modules.img # optionally $PWD/modules dir too
Please see the documentation on the .wslconfig configuration file for information on using a custom built kernel.