[Note] WSL2 kernel build and use

image.png

Overview

On Ubuntu 20.04 of WSL2, build the kernel source brought from kernel.org and use it as the kernel of WSL2.

environment

procedure

  1. Install build tool

    sudo apt update && \
    sudo apt install -y build-essential flex bison libssl-dev libelf-dev pkg-config libncurses-dev
    
  2. Download kernel source

    • https://www.kernel.org/
      > stable: 5.9.6 2020-11-05 [tarball]
    cd ~
    wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.9.6.tar.xz
    tar xvf linux-5.9.6.tar.xz
    cd linux-5.9.6
    
  3. Get .config

    • https://github.com/microsoft/WSL2-Linux-Kernel/blob/master/Microsoft/config-wsl
    rm -rfv .config
    wget https://raw.githubusercontent.com/microsoft/WSL2-Linux-Kernel/master/Microsoft/config-wsl -O .config
    
  4. make menuconfig Exit with <Exit> => <Yes>

  5. Build

    make -j 5 && sudo make modules_install`
    
  6. Copy the kernel image (eg C: \ wslkernel \ kernel-5.9.6)

    mkdir -p /mnt/c/wslkernel
    cp -v arch/x86/boot/bzImage /mnt/c/wslkernel/kernel-5.9.6
    
  7. C:\Users\<username>\.wslconfig

    [wsl2]
    #memory=2GB
    #processors=2
    kernel=C:\\wslkernel\kernel-5.9.6
    localhostForwarding=true
    swap=0
    

Note that there are two backslashes (\\) in the path specification.

  1. Open PowerShell as an administrator and shut down the kernel.

    wsl --shutdown
    

    image.png

  2. Restart Ubuntu image.png

Other

Recommended Posts

[Note] WSL2 kernel build and use
Use a custom kernel with WSL2
Note until you use emacs with WSL
[Linux] [kernel module] Build and load a simple loadable kernel module
Use SQLAlchemy and multiprocessing
[Note] PCA and t-SNE
Linux kernel build time
Julia Quick Note [01] How to use variables and constants
Build a Docker environment that can use PyTorch and JupyterLab
Linux Kernel Build for DE10nano
Use Windows 10 fonts with WSL
[Note] How to use virtualenv
Use and integration of "Shodan"
Use Linux on Windows 10 (WSL2)
How to build a LAMP environment using Vagrant and VirtulBox Note