WSL stand for Windows Subsystem Linux. It allow us to get the best of both Linux and Windows world…

Get Started

Of course, As admin inside a powershell terminal :

 1# Update your WSL first
 2wsl --update
 3
 4# Install the distrib you want
 5wsl --install -d Ubuntu
 6
 7# Distrib you have to your disposition
 8wsl --list --online
 9
10# List all WSL installed
11wsl --list
12wsl --list -v
13
14# if needed to reinstall 
15wsl --shutdown
16wsl --unregister Ubuntu

Windows Terminal

WSL is your Linux VM on windows, you can also use Windows Terminal for your own confort.

Here some shortcut in Windows Terminal but not only 😉 :

  • alt + enter : mode full ecran
  • ctrl shift t : terminal
  • ctrl shift n : new windows
  • ctrl alt 1 2 3 : changer de fenetre
  • Windows + v : see the paste buffer
  • Alt Shift = : split vertical
  • Alt shit - : split horizontal
  • Alt arrow : to change panel
  • Alt shit arrow : resize panel
  • code . : open VSCode from your current directory

Free some space on your WSL

  • checks which directory contains the most data:
1du -h --max-depth 1
  • Activate Hyper-V module in windows features:

    Inside the control-panel -> Turn windows features on or off -> activate Hyper-v -> restart.
    This is required to activate optimize-vhd command.

  • Let’s shrink - As admin in powershell:

1wsl --shutdown
2
3#Find ext4.vhdx in \Users\USER\AppData\Local\Packages\
4optimize-vhd -Path C:\Users\<USER>\AppData\Local\Packages\AlmaLinuxOSFoundation.AlmaLinux8WSL_xxxxxxxxxxxxxx\LocalState\ext4.vhdx -Mode full

Export/Import your WSL

1wsl --export AlmaLinux-8 AlmaLinux-8-full.tar.gz
2wsl --import AlmaLinux8-full C:\Users\<USER>\AppData\Local\Packages\Alma8-full .\AlmaLinux-8-full.tar
3wsl -d AlmaLinux8-full -u <USER> -s
4wsl --unregister AlmaLinux8-full
5
6wsl --list -v

Activate Systemd

Need WSL2 and Windows 11, add below line a the top of the file /etc/wsl.conf

1# /etc/wsl.conf
2[boot]
3systemd=true

Install KVM on WSL

  • First you need systemd enable

  • inside %UserProfile%\.wslconfig :

1[wsl2]
2nestedVirtualization=true
  • restart WSL
1wsl.exe --shutdown
 1sudo apt update
 2sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cpu-checker \
 3network-manager iptables-persistent linux-headers-generic \
 4qemu uml-utilities virt-manager git \
 5wget libguestfs-tools p7zip-full make dmg2img tesseract-ocr \
 6tesseract-ocr-eng genisoimage vim net-tools screen firewalld libncurses-dev -y
 7sudo apt install virt-manager
 8sudo addgroup kvm
 9sudo adduser `id -un` libvirt
10sudo adduser `id -un` kvm
11newgrp libvirt

Make podman engine and kind work on WSL2

  • Update crun
 1CRUN_VER='1.11.2'
 2
 3curl -L "https://github.com/containers/crun/releases/download/${CRUN_VER}/crun-${CRUN_VER}-linux-amd64" -o "${HOME}/.local/bin/crun"
 4
 5chmod +x "${HOME}/.local/bin/crun"
 6
 7cat << EOF > $HOME/.config/containers/containers.conf
 8[engine]
 9cgroup_manager = "cgroupfs"
10
11[engine.runtimes]
12crun = [
13  "${HOME}/.local/bin/crun",
14  "/usr/bin/crun"
15]
16EOF
  • Adapt podman general config /usr/share/containers/containers.conf
1[engine]
2cgroup_manager = "cgroupfs"
3events_logger = "journald"
4
5[engine.runtimes]
6crun = [
7   "${HOME}/.local/bin/crun",
8   "/usr/bin/crun"
9]
  • Delegate service
1cat << EOF > /etc/systemd/system/user@.service.d/delegate.conf
2[Service]
3Delegate=yes
4EOF
  • Adapt %USERPROFILE%\.wslconfig to systemd in cgroup
1[wsl2]
2nestedVirtualization=true
3kernelCommandLine = cgroup_no_v1=all systemd.unified_cgroup_hierarchy=1