How to set up WSL2 with a custom Linux kernel and network

Last update: 30/06/2025
Author Isaac
  • WSL2 allows you to run Linux en Windows with a full kernel and high performance.
  • Configuring a custom kernel and networking requires enabling specific Windows and WSL features.
  • It is possible to access the file system between Windows and Linux with ease and mount services such as Docker.
  • Visual and productivity improvements can be applied to the terminal to develop more efficiently.

Configure WSL2 with custom kernel and network

The Windows Subsystem for Linux (WSL2) has revolutionized the way developers and power users use Linux within a Windows environment. This tool allows you to integrate both OS almost natively, eliminating the need for Virtual machines heavy or complicated dual boot configurations.

The really interesting thing is that WSL2 allows the use of a complete, custom Linux kernel, in addition to a more robust and flexible network configuration. This is a huge advantage for those who need a more production-like development environment or want to take full advantage of the technical capabilities of their tools.

What is WSL2 and why is it better than WSL1?

WSL2 represents the second generation of the Windows Subsystem for Linux and brings with it significant improvements over its predecessor. The radical difference is that WSL2 uses a lightweight virtual machine based on Hyper-V containing a complete Linux kernel, allowing for greater compatibility with applications that rely on system calls and much better performance, especially in the file system.

Thanks to these improvements, we can:

  • Run tools like Docker without third-party dependencies.
  • Compile native software for Linux within Windows.
  • Using Linux File Systems as ext4 from Windows.

WSL2 with custom Linux kernel on Windows

Prerequisites and supported systems

Before you jump into setting up WSL2, you'll want to make sure your operating system is ready:

  • Windows 10 with version 1903 and build 18362 or higher.
  • Windows 11 is fully compatible.
  • The functionality also depends on activating the virtualization in the BIOS.

You can check your version by typing winver from the run dialog (Win + R).

  How to fix “Out of Virtual Memory” error in Windows 11

How to enable WSL and WSL2 on Windows

There are several ways to enable WSL, from commands en PowerShell to graphic options through the Control Panel. Here's the most comprehensive way to ensure everything runs smoothly:

Option 1: Using PowerShell (recommended)

Run PowerShell as administrator and type the following commands:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

wsl --set-default-version 2

This will enable the WSL feature and set all new distros to use WSL2 by default.

Option 2: From the Control Panel

Go to “Turn Windows features on or off” and select the following:

  • Windows subsystem for Linux
  • Virtual Machine Platform
  • Hyper-V (optional but recommended)

Then, restart your computer to apply the changes.

Installing a Linux distribution

From the Microsoft Store you can install distributions such as:

  • Ubuntu (16.04, 18.04, 20.04, 22.04)
  • Debian
  • Kali Linux
  • openSUSE

When you first open the installed distro, it will ask you to create a Linux user and passwordThis will be your default user within the environment.

Configuring a custom Linux kernel

A very powerful feature of WSL2 is that you can use your own Linux kernel. To do this:

1. Compile or download a custom kernel

It is possible to use a kernel compiled by you or one from a third party. Make sure it is compatible with the WSL2 environment.

2. Edit the .wslconfig file

In your Windows user folder (C:\Users\ ), creates a file called .wslconfig if it doesn't already exist. Inside it, add:

[wsl2]
kernel=C:\Ruta\al\kernel\vmlinuz

Save the changes and restart WSL with:

wsl --shutdown

Upon restart, WSL2 will load the provided custom kernel.

Enable networking in WSL2 and access via localhost

In recent versions of WSL2, Microsoft enabled traffic redirection between Linux and Windows by localhost, which makes it much easier to use and configure.

This means that you can start a server inside WSL2 (for example, python3 -m http.server 8000) and access from the browser in Windows to http://localhost:8000. If you need to expose ports to the network, you will need to configure rules with netsh or specific tools to redirect IPs and ports correctly.

  Adobe Reader does not recognize my printer. Here are three solutions

Accessing the file system between Windows and Linux

With WSL2 you can interact with the file system of both platforms fluidly:

  • From Linux you can access Windows drives in /mnt/c, /mnt/d, etc.
  • From Windows you can access Linux through \\wsl$\<distro>\

Also, you can use the command wslpath to easily convert routes from one system to another.

Backups, export and import distributions

WSL2 offers commands to make full backups of your distributions, which is very useful if you want to migrate or save them before making major changes. Example for export:

wsl --export Debian C:\backups\debian_backup.tar

And to import into another system:

wsl --import Debian C:\WSL\Debian C:\backups\debian_backup.tar --version 2

This will clone the entire distro keeping paths and settings intact.

Using Docker in WSL2 without Docker Desktop

One of the great advantages of WSL2 is that you can run Docker directly, without the need for Docker Desktop or additional tools. Steps to install it:

  1. Add the official Docker repository to your distro.
  2. Install the packages: docker-ce, docker-ce-cli, containerd.io.
  3. Add your user to the docker group: sudo usermod -aG docker $USER.
  4. Edit /etc/wsl.conf to start Docker automatically.

Then you can run docker run hello-world and check that everything is working correctly.

Customized terminal to improve your productivity

Since you'll be spending a lot of time working in the terminal, it's a good idea to make it more user-friendly and useful:

Install ZSH + Oh-My-ZSH

ZSH is a replacement for bash with more features and together with the framework Oh-My-ZSH You have access to hundreds of plugins and visual themes.

Configure Powerlevel10k

This ZSH theme enhances the command bar by displaying Git branches, errors, environments, and more. It's also highly customizable.

Additional plugins for ZSH

  • zsh-autosuggestions
  • fzf (command history and search)
  • nvm (Node.js version manager)
  • batcat (replacing cat with colors)

Advantages over a virtual machine or dual boot

Compared to a traditional VM, WSL2:

  • Consume less memory by dynamically managing RAM.
  • Starts in less than a second.
  • Facilitates access to files between systems.
  • It integrates with VSCode through the “Remote – WSL” extension.
  Troubleshoot synchronization issues in shared Office documents

And in front of Boot dual is even more convenient, as it avoids reboots and allows you to work with graphical and CLI tools without interruptions.

Common mistakes when installing or using WSL2

  • 0x80070003: Indicates that the distro is not on the C: drive
  • 0x80370102: Virtualization is disabled in the BIOS.
  • WSL2 requires kernel update: Visit https://aka.ms/wsl2kernel to download the add-on package.

With all this setup, you'll have a complete Linux environment running on Windows, with a fully functional kernel, active networking, Docker running, and a friendly and productive terminal with advanced plugins. It's one of the most convenient and powerful ways to develop software today without sacrificing the operating system you use every day.

Leave a comment