Image: IDG
There are many open source programs (aka code that’s accessible to the public) out there for both Linux and Windows. For programs and tools where that’s not the case, WSL (Windows Subsystem for Linux) is the ideal solution for using Linux programs on Windows computers. This means that you don’t have to start Linux first and can use the Linux program in the currently active Windows.
Programs in WSL run slower than under native Linux, but it’s not always noticeable. Microsoft is also continuing to work on improvements that will be incorporated into the Linux kernel. A newer kernel can therefore speed up WSL.
WSL kernel and virtualization
In WSL 2, the Linux kernel runs on a hypervisor (Hyper-V), similar to its Linux counterpart KVM/Qemu. The kernel offers functions to ensure communication between the guest and host systems. This concerns, for example, the shared use of the main memory and CPU management. The program code for this comes primarily from Microsoft.
For Linux users, newer kernels offer support for newer hardware and performance optimizations. Microsoft also regularly optimizes the Hyper-V code in the kernel, but the hardware drivers hardly play a role in WSL because the virtual hardware always remains the same. However, there are drivers that are required for certain applications such as network block devices (nbd), which can be used to mount virtual hard disks in VHD format, for example.
Install WSL and check the version
Powershell, Command Prompt, and WSL can be used conveniently in the Windows terminal. It’s available by default in Windows 11, but Windows 10 users need to install it via the Microsoft Store.
In Powershell, install WSL with the following code:
wsl --install -d Ubuntu-24.04
To call up the available distributions, enter the code below and then restart Windows:
wsl --list --online
After logging in, a Linux terminal will open and notify you when the installation is complete. You will then be asked to enter a user name and password for the Linux account. Update the Ubuntu system with:
sudo apt update && sudo apt upgrade
In the Windows terminal, start Linux via the menu that appears after clicking on the arrow button next to the tabs. In Powershell, determine the WSL version with:
wsl -l -v
If a 1 appears in the Version column for an older installation, update the version with these two lines:
wsl --set-default-version 2
wsl --set-default [Distribution]
Replace the placeholder [Distribution] with the name of the distribution.
Creating a new kernel for WSL 2
Step 1: Start Linux in WSL and install some developer packages with:
sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev libncurses-dev git
Step 2: Create a working directory and download the source code (four lines):
mkdir kernel
cd kernel
git clone https://github.com/microsoft/WSL2-Linux-Kernel.git --depth=1 -b linux-msft-wsl-6.6.y
cd WSL2-Linux-Kernel
Adjust the kernel version if necessary.
Step 3: With the following line of code, you can give the kernel its own name:
scripts/config --file Microsoft/config-wsl --set-str LOCALVERSION "-custom-microsoft-standard-WSL2"
If you wish, you can use this line of code to call up the configuration editor and make your own customizations:
make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl
IDG
Step 4: Create the kernel with:
echo 'yes' | make -j $(nproc) KCONFIG_CONFIG=Microsoft/config-wsl
Install the modules with:
sudo make KCONFIG_CONFIG=Microsoft/config-wsl modules_install
Step 5: In Windows Explorer, call up the Linux environment via the entry below Linux in the navigation area. Copy the vmlinux file from your home directory to the Windows user profile in the WSL folder (C:Users[username]WSL).
Step 6: Under Windows, create the .wslconfig file in your profile folder. Enter these two lines into it:
[wsl2]
kernel=C:Users[username]WSLvmlinux
Replace the placeholder [username] with your user name.
In Powershell, terminate all running WSL instances with:
wsl --shutdown
If you start Linux in the Windows subsystem for Linux, the following command shows the version of the new kernel:
uname -a
This article originally appeared on our sister publication PC-WELT and was translated and localized from German.
Author: Thorsten Eggeling
Thorsten Eggeling schreibt seit gut 20 Jahren Artikel für die PC-WELT.