Skip to content

Instantly share code, notes, and snippets.

@HauptJ
Created January 21, 2026 20:48
Show Gist options
  • Select an option

  • Save HauptJ/0fd8a88fd67c2d6fce2c3d54f67939b0 to your computer and use it in GitHub Desktop.

Select an option

Save HauptJ/0fd8a88fd67c2d6fce2c3d54f67939b0 to your computer and use it in GitHub Desktop.
WSL Ubuntu Compile and Install Kernel with Kernel Headers
#!/usr/bin/env bash
set -e
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
user=josh
version=$(uname -r)
sudo apt install -y build-essential flex bc libelf-dev pahole bison;
git clone 'https://github.com/microsoft/WSL2-Linux-Kernel.git' --single-branch --depth 1 --recurse-submodules;
cd WSL2-Linux-Kernel;
make KCONFIG_CONFIG=Microsoft/config-wsl -j$(nproc);
sudo make modules_install;
sudo make install;
sudo cp -f /boot/vmlinuz-${version}+ /mnt/c/Users/${user}/vmlinuz-${version}+;
printf '[wsl2]\nkernel=C:\\\\Users\\\\${user}\\\\vmlinuz-${version}+\n' | sudo tee --append /mnt/c/Users/${user}/.wslconfig
sudo reboot now;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment