Hi, Moved away from Clang to GCC. Sounds more standard anyway. *smile* Now you can use all Ubuntu versions to compile the kernel. Building a Linux kernel for WSL2 using GCC Last updated: 18:28 02.11.2020 Or just get it and updated versions of this documentation from here: https://www.dropbox.com/sh/nhcbxnv5zllxuof/AABbHdkf3Yd4RuEPnkBf5MMLa?dl=0 Note: Changed from Clang back to GCC because this seems to be a more standard way of doing it. Sources https://www.xyb.name/2020/03/14/build-your-kernel-for-wsl2/ https://nathanchance.dev/posts/wsl2-kernel-clang/ Howto 1. Download and install the needed tools. Use Ubuntu. $ sudo apt update $ sudo apt upgrade $ sudo apt install g++ make flex bison libssl-dev libelf-dev bc wget 2. Download the kernel source code The latest is 5.9.3 at the moment of writing. Find the latest info on https://www.kernel.org/ $ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.9.3.tar.xz $ tar xf linux-5.9.3.tar.xz $ cd linux-5.9.3 $ wget https://raw.githubusercontent.com/microsoft/WSL2-Linux-Kernel/master/Microso... You can also use linux-next (bleeding edge code) if you want: $ wget https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/snapshot... for the kernel of 30 October 2020. Modify the dates. See the kernel website for the latest. 3. Build the kernel. An out directory (out.x86_64) can be handy to have a clean environment. $ make -j$(nproc) -s KCONFIG_CONFIG=config-wsl O=out.x86_64 distclean olddefconfig all Move the kernel to the Windows file system. I have my kernels sitting at e:\wsl\kernel. $ cp out.x86_64/arch/x86/boot/bzImage /mnt/e/wsl/kernel/linux-5.9.3 Tell WSL2 to use that kernel when booting up. Create a .wslconfig file in your user directory for example at c:\users\username. This file should contain the following: [wsl2] kernel = e:\\wsl\\kernel\\linux-5.9.3 Note that you need to use double backslashes. Then do on a cmd window. $ wsl --shutdown Then load a linux distro and type $ cat /proc/version Now you should see something like that Linux version 5.9.3-microsoft-standard (root@SimonPC) (gcc (Ubuntu 10.2.0-13ubuntu1) 10.2.0, GNU ld (GNU Binutils for Ubuntu) 2.35.1) #1 SMP Mon Nov 2 17:42:10 CET 2020 Some have noticed that the VM gets stuck starting with a custom kernel at times; if that happens, run wsl --shutdown and try reopening one of the distributions again, it will usually work after a couple of times. Enjoy.
participants (1)
-
Simon Eigeldinger