How do I get the kernel headers for WSL2 Ubuntu24.04?
Running Windows 10 with WSL2 running Ubuntu24.04, and when I try to build a DKMS linux kernel module, I get the error
$ sudo dkms build eatmydata/0.1
Error! Your kernel headers for kernel 5.15.133.1-microsoft-standard-WSL2 cannot be found at /lib/modules/5.15.133.1-microsoft-standard-WSL2/build or /lib/modules/5.15.133.1-microsoft-standard-WSL2/source.
Please install the linux-headers-5.15.133.1-microsoft-standard-WSL2 package or use the --kernelsourcedir option to tell DKMS where it's located.
Normally this would be solved with a sudo apt install linux-headers-$(uname -r)
, but linux-headers-5.15.133.1-microsoft-standard-WSL2
is not available in apt, my options are:
$ uname -r
5.15.133.1-microsoft-standard-WSL2
$ sudo apt install linux-headers-
Display all 203 possibilities? (y or n)
linux-headers-6.11.0-1002-nvidia linux-headers-6.8.0-1009-oem linux-headers-6.8.0-1014-nvidia-lowlatency linux-headers-6.8.0-1020-nvidia linux-headers-6.8.0-50-lowlatency
linux-headers-6.11.0-1007-oem linux-headers-6.8.0-1010-aws linux-headers-6.8.0-1014-oem linux-headers-6.8.0-1020-nvidia-lowlatency linux-headers-6.8.0-51
linux-headers-6.11.0-1008-oem linux-headers-6.8.0-1010-azure linux-headers-6.8.0-1014-oracle linux-headers-6.8.0-1021-aws linux-headers-6.8.0-51-generic
linux-headers-6.11.0-1009-oem linux-headers-6.8.0-1010-gcp linux-headers-6.8.0-1015-aws linux-headers-6.8.0-31 linux-headers-aws
linux-headers-6.11.0-1010-oem linux-headers-6.8.0-1010-gke linux-headers-6.8.0-1015-azure linux-headers-6.8.0-31-generic linux-headers-azure
linux-headers-6.8.0-1001-gkeop linux-headers-6.8.0-1010-ibm linux-headers-6.8.0-1015-gcp linux-headers-6.8.0-31-lowlatency linux-headers-gcp
linux-headers-6.8.0-1002-gkeop linux-headers-6.8.0-1010-nvidia linux-headers-6.8.0-1015-gke linux-headers-6.8.0-35 linux-headers-generic
linux-headers-6.8.0-1003-gke linux-headers-6.8.0-1010-oem linux-headers-6.8.0-1015-ibm linux-headers-6.8.0-35-generic linux-headers-generic-hwe-24.04
linux-headers-6.8.0-1003-gkeop linux-headers-6.8.0-1010-oracle linux-headers-6.8.0-1015-nvidia linux-headers-6.8.0-35-lowlatency linux-headers-generic-hwe-24.04-edge
linux-headers-6.8.0-1004-gke linux-headers-6.8.0-1011-aws linux-headers-6.8.0-1015-nvidia-lowlatency linux-headers-6.8.0-36 linux-headers-gke
linux-headers-6.8.0-1005-gke linux-headers-6.8.0-1011-gcp linux-headers-6.8.0-1015-oracle linux-headers-6.8.0-36-generic linux-headers-gkeop
linux-headers-6.8.0-1005-ibm linux-headers-6.8.0-1011-gke linux-headers-6.8.0-1016-aws linux-headers-6.8.0-36-lowlatency linux-headers-gkeop-6.8
linux-headers-6.8.0-1005-intel linux-headers-6.8.0-1011-ibm linux-headers-6.8.0-1016-azure linux-headers-6.8.0-38 linux-headers-ibm
linux-headers-6.8.0-1005-oem linux-headers-6.8.0-1011-nvidia linux-headers-6.8.0-1016-gcp linux-headers-6.8.0-38-generic linux-headers-ibm-classic
linux-headers-6.8.0-1005-oracle linux-headers-6.8.0-1011-nvidia-lowlatency linux-headers-6.8.0-1016-gke linux-headers-6.8.0-38-lowlatency linux-headers-ibm-lts-24.04
linux-headers-6.8.0-1006-gke linux-headers-6.8.0-1011-oem linux-headers-6.8.0-1016-ibm linux-headers-6.8.0-39 linux-headers-kvm
linux-headers-6.8.0-1006-ibm linux-headers-6.8.0-1011-oracle linux-headers-6.8.0-1016-oem linux-headers-6.8.0-39-generic linux-headers-lowlatency
linux-headers-6.8.0-1006-intel linux-headers-6.8.0-1012-aws linux-headers-6.8.0-1016-oracle linux-headers-6.8.0-39-lowlatency linux-headers-lowlatency-hwe-20.04
linux-headers-6.8.0-1006-oem linux-headers-6.8.0-1012-azure linux-headers-6.8.0-1017-aws linux-headers-6.8.0-40 linux-headers-lowlatency-hwe-20.04-edge
linux-headers-6.8.0-1006-oracle linux-headers-6.8.0-1012-gcp linux-headers-6.8.0-1017-azure linux-headers-6.8.0-40-generic linux-headers-lowlatency-hwe-22.04
linux-headers-6.8.0-1007-azure linux-headers-6.8.0-1012-gke linux-headers-6.8.0-1017-gcp linux-headers-6.8.0-40-lowlatency linux-headers-lowlatency-hwe-22.04-edge
linux-headers-6.8.0-1007-gcp linux-headers-6.8.0-1012-ibm linux-headers-6.8.0-1017-ibm linux-headers-6.8.0-41 linux-headers-lowlatency-hwe-24.04
linux-headers-6.8.0-1007-gke linux-headers-6.8.0-1012-nvidia linux-headers-6.8.0-1017-nvidia linux-headers-6.8.0-41-generic linux-headers-lowlatency-hwe-24.04-edge
linux-headers-6.8.0-1007-ibm linux-headers-6.8.0-1012-nvidia-lowlatency linux-headers-6.8.0-1017-nvidia-lowlatency linux-headers-6.8.0-41-lowlatency linux-headers-nvidia
linux-headers-6.8.0-1007-nvidia linux-headers-6.8.0-1012-oem linux-headers-6.8.0-1017-oem linux-headers-6.8.0-44 linux-headers-nvidia-6.11
linux-headers-6.8.0-1007-oem linux-headers-6.8.0-1012-oracle linux-headers-6.8.0-1017-oracle linux-headers-6.8.0-44-generic linux-headers-nvidia-hwe-24.04-edge
linux-headers-6.8.0-1008-aws linux-headers-6.8.0-1013-aws linux-headers-6.8.0-1018-aws linux-headers-6.8.0-44-lowlatency linux-headers-nvidia-lowlatency
linux-headers-6.8.0-1008-azure linux-headers-6.8.0-1013-azure linux-headers-6.8.0-1018-azure linux-headers-6.8.0-45 linux-headers-oem-20.04
linux-headers-6.8.0-1008-gcp linux-headers-6.8.0-1013-gcp linux-headers-6.8.0-1018-gcp linux-headers-6.8.0-45-generic linux-headers-oem-20.04b
linux-headers-6.8.0-1008-gke linux-headers-6.8.0-1013-gke linux-headers-6.8.0-1018-ibm linux-headers-6.8.0-45-lowlatency linux-headers-oem-20.04c
linux-headers-6.8.0-1008-ibm linux-headers-6.8.0-1013-ibm linux-headers-6.8.0-1018-nvidia linux-headers-6.8.0-47 linux-headers-oem-20.04d
linux-headers-6.8.0-1008-nvidia linux-headers-6.8.0-1013-nvidia linux-headers-6.8.0-1018-nvidia-lowlatency linux-headers-6.8.0-47-generic linux-headers-oem-22.04
linux-headers-6.8.0-1008-oem linux-headers-6.8.0-1013-nvidia-lowlatency linux-headers-6.8.0-1018-oem linux-headers-6.8.0-47-lowlatency linux-headers-oem-24.04
linux-headers-6.8.0-1008-oracle linux-headers-6.8.0-1013-oem linux-headers-6.8.0-1018-oracle linux-headers-6.8.0-48 linux-headers-oem-24.04a
linux-headers-6.8.0-1009-aws linux-headers-6.8.0-1013-oracle linux-headers-6.8.0-1019-aws linux-headers-6.8.0-48-generic linux-headers-oem-24.04b
linux-headers-6.8.0-1009-azure linux-headers-6.8.0-1014-aws linux-headers-6.8.0-1019-gcp linux-headers-6.8.0-48-lowlatency linux-headers-oracle
linux-headers-6.8.0-1009-gcp linux-headers-6.8.0-1014-azure linux-headers-6.8.0-1019-nvidia linux-headers-6.8.0-49 linux-headers-virtual
linux-headers-6.8.0-1009-gke linux-headers-6.8.0-1014-gcp linux-headers-6.8.0-1019-nvidia-lowlatency linux-headers-6.8.0-49-generic linux-headers-virtual-hwe-24.04
linux-headers-6.8.0-1009-ibm linux-headers-6.8.0-1014-gke linux-headers-6.8.0-1019-oem linux-headers-6.8.0-49-lowlatency linux-headers-virtual-hwe-24.04-edge
linux-headers-6.8.0-1009-nvidia linux-headers-6.8.0-1014-ibm linux-headers-6.8.0-1020-aws linux-headers-6.8.0-50
linux-headers-6.8.0-1009-nvidia-lowlatency linux-headers-6.8.0-1014-nvidia linux-headers-6.8.0-1020-gcp linux-headers-6.8.0-50-generic
Thus I am stuck. How do I get the kernel headers?
Seems to me that the WSL kernel headers are not distributed anywhere, which means you need to compile it yourself:
sudo apt install build-essential flex bc libelf-dev pahole;
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 /boot/vmlinuz-6.6.36.6-microsoft-standard-WSL2+ /mnt/c/Users/<YourUsername>/vmlinuz-6.6.36.6-microsoft-standard-WSL2+;
printf '[wsl2]\nkernel=C:\\\\Users\\\\<YourUsername>\\\\vmlinuz-6.6.36.6-microsoft-standard-WSL2+\n' | sudo tee --append /mnt/c/Users/<YourUsername>/.wslconfig
sudo reboot now;
ofc 6.6.36.6
and <YourUsername>
needs adjusting.