This repository provides automated builds of Microsoft's official WSL2 kernel sources, compiling and releasing only the bzImage kernel files.
- Automates building official Microsoft kernel sources exactly as released
- Provides access to historical kernel versions
- Only distributes the compiled bzImage (kernel binary)
- Does NOT provide or modify any vhdx files
https://github.com/lenML/lets-build-wsl2-kernels/releases
- Go to "Actions" tab
- Select "Build WSL2 Kernel"
- Click "Run workflow"
- Specify kernel version (e.g.
5.15.90.1
) - Click "Run workflow"
- Download the bzImage artifact after build completes
- Place it in your preferred location (e.g.
C:\Windows\System32\lxss\tools
) - Create/modify
%USERPROFILE%\.wslconfig
:
[wsl2]
kernel=C:\\path\\to\\bzImage
- Restart WSL:
wsl --shutdown
To build locally from official sources:
./scripts/build.sh [version]
Example:
./scripts/build.sh 5.15.90.1
Microsoft maintains the WSL2-Linux-Kernel but:
- Doesn't provide pre-built historical kernel versions
- Only distributes kernels through Windows Update
- Makes it difficult to test different kernel versions
I encountered issues while fine-tuning models using Unsloth, and I suspect they are related to the WSL2 kernel. To experiment with different WSL kernels, I created this repository.
The specific Unsloth issue can be found here: unslothai/unsloth#1744
Problems I discovered include:
- Some WSL kernel versions have serious memory management issues:
- Memory is requested but cannot be released, even when
pageReporting=true
is enabled. memlock
limits vary—some WSL instances have a higher or even unlimited locked memory cap, but typically the limit is around 2GB. In my tests, it sometimes allows only 2GB, which is entirely dependent on the WSL kernel.memlock
has a hard limit that seems unchangeable within WSL.memlock
appears to overestimate current locked memory; repeated locking of the same memory can be counted multiple times (as documented in WSL's infiniband/user_verbs.rst).
- Memory is requested but cannot be released, even when
- Some WSL kernels are incompatible with Docker Desktop.
The WSL2 kernel has specific behaviors around memory allocation and locking:
-
Performance Monitoring Memory:
- The
perf_event_mlock_kb
setting governs memory available for performance monitoring - This extends the
RLIMIT_MEMLOCK
limit but only for perf_event mmap buffers - Processes with
CAP_IPC_LOCK
capability bypass these limits - See documentation
- The
-
Memory Pinning:
- Direct I/O requires memory regions to stay at fixed physical addresses
- The kernel accounts pinned memory in
pinned_vm
- Pages pinned multiple times are counted each time (may overestimate actual usage)
- Documentation reference
These behaviors explain some of the memory management challenges encountered when running memory-intensive workloads in WSL2.
Kernel code is under Microsoft's original licenses. Build scripts are MIT licensed.