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 cpu-checker
 3sudo kvm-ok
 4
 5#Basic
 6sudo apt -y install libvirt-daemon-system bridge-utils qemu-kvm libvirt-daemon
 7
 8#Extra tools
 9sudo apt install virtinst libosinfo-bin virt-top libguestfs-tools 
10sudo apt install xsltproc uidmap
11
12# GUI tools
13sudo apt -y install qemu-system virt-manager 
14
15sudo addgroup kvm
16sudo adduser `id -un` libvirt-qemu
17sudo adduser `id -un` kvm
18newgrp libvirt

Make podman engine and kind work on WSL2

  • Adapt %USERPROFILE%\.wslconfig to systemd in cgroup
1[wsl2]
2nestedVirtualization=true
3kernelCommandLine = cgroup_no_v1=all systemd.unified_cgroup_hierarchy=1
  • Update UID map and podman user config:
 1# rootless podman 4.9.3 on WSL2 + Ubuntu 24.04:
 2sudo apt-get install uidmap
 3
 4echo "ubuntu:100000:2097152" | sudo tee  /etc/subuid
 5echo "ubuntu:100000:2097152" | sudo tee  /etc/subgid
 6
 7cat << EOF > $HOME/.config/containers/containers.conf
 8unqualified-search-registries=["docker.io"]
 9
10[aliases]
11"library"="docker.io/library"
12
13[engine]
14cgroup_manager = "cgroupfs"
15events_logger = "journald"
16EOF
  • Install Kind
1[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.27.0/kind-linux-amd64
2chmod +x ./kind
3sudo mv ./kind /usr/local/bin/kind

Make WSL copy the host network

  • Usefull when you change WIFI, add to %USERPROFILE%\.wslconfig:
1[wsl2]
2networkingMode=mirrored
3dnsTunneling=true
4autoProxy=true