How to build and use a kernel in WSL2

  1. sudo git clone
  2. sudo apt install build-essential flex bison libssl-dev libelf-dev
  3. cd WSL2-Linux-Kernel
  4. cp Microsoft/config-wsl .config (if you’ve compiled previously, this may require sudo)
  5. sudo make -j $(expr $(nproc) - 1))
  6. From Windows, copy \wsl$\DISTRO\home\WSL_USERNAME\WSL2-Linux-Kernel\arch\x86\boot\bzimage to C:\Users\WIN10_USERNAME
  7. Create a file called .wslconfig in C:\Users\WIN10_USERNAME:
  8. From PowerShell, run wsl –shutdown
  9. Reopen your flavor of WSL2