Build a custom Microsoft WSL2 kernel from source, then generate a matching Windows .wslconfig file. The project is intended for Debian or Ubuntu environments running inside WSL2.
- The build script now uses strict bash settings, safer temp directory handling, and a local
.wslconfiggenerator instead of executing a remote script. - Kernel version discovery now uses
git ls-remoteagainst the upstream Microsoft repository, not brittle HTML parsing and not the GitHub API. - The
.wslconfiggenerator now validates inputs, detects Windows hardware from PowerShell, and writes current settings into the correct[wsl2]and[experimental]sections. - A
config-wslfile with full CAN bus support is bundled in the repo and is used automatically bybuild-kernel.sh(override with--config <path>). - CI, linting, smoke tests, and basic repo hygiene files have been added.
- WSL2 on Windows with a Debian or Ubuntu distro
sudoaccess inside the distro- Internet access to download the upstream kernel source
The build script installs missing packages automatically with apt-get.
Clone the repository and run the build:
git clone https://github.com/slyfox1186/wsl2-kernel-build-script.git
cd wsl2-kernel-build-script
sudo bash build-kernel.shBuild a specific version:
sudo bash build-kernel.sh --version 6.6.87.2 --output-directory "$HOME/WSL2"Build the latest kernel from a major series:
sudo bash build-kernel.sh --series 6 --skip-wslconfigList upstream versions:
bash build-kernel.sh --list-versionsGenerate only .wslconfig:
bash wslconfig-generator.sh --kernel /mnt/c/Users/you/WSL2/vmlinuxThe repo ships a config-wsl file with full Linux CAN bus support enabled (raw, BCM, GW, J1939, ISO-TP, vcan, vxcan, plus the common controller and USB drivers). When build-kernel.sh runs, it picks the kernel .config in this order:
--config <path>if you pass one explicitly.- The repo's
config-wslif it exists alongsidebuild-kernel.sh. - Upstream
Microsoft/config-wslfrom the kernel source tarball.
make olddefconfig is then run inside the kernel tree, so any options new to the kernel version you build will be initialized to their defaults without prompting.
To use your own config, point at it:
sudo bash build-kernel.sh --config /path/to/my-config-wslTo force the upstream Microsoft default instead of the bundled config, rename or delete config-wsl in the repo before running the script.
The kernel build produces vmlinux in your selected output directory. Store that file somewhere stable on Windows, for example:
C:\Users\<your-user>\WSL2\vmlinux
Create C:\Users\<your-user>\.wslconfig and point kernel= at that file. A sample config lives at .wslconfig.example.
After updating the Windows config, apply the change from PowerShell or Command Prompt:
wsl --shutdownRun the local checks before pushing changes:
make lint
make smoke- Microsoft WSL2 kernel source: https://github.com/microsoft/WSL2-Linux-Kernel/
- Microsoft WSL configuration docs: https://learn.microsoft.com/windows/wsl/wsl-config