Wsl2

From wikinotes

Windows Subsystem for linux 2, preceeded by wsl runs a real linux kernel instead of maintaining a translation layer for system calls.

NOTE:

requires windows-10-18362 or higher

NOTE:

I/O between windows/linux filesystems is faster in wsl than wsl2.
I/O while sticking within linux filesystem is faster in wsl2.

Documentation

official docs https://docs.microsoft.com/en-us/windows/wsl/about

Locations

C:\ProgramData\chocolatey\lib\wsl2 wsl root
C:\ProgramData\chocolatey\lib\wsl-${DISTRO} wsl distrobutions

Install

choco install -y wsl2
# reboot
choco install -y gsudo
choco install -y wsl-archlinux  # install same distros as wsl-1
choco install -y wsl-opensuse

Usage

Starting shell

wsl
wsl -l                       # list distros
wsl -d ${DISTRO}             # shell within distro
wsl -e ${CMD}                # run command within distro

interoperability

netstat -an | gsudo wsl grep 127.0.0.1  # wsl from windows (grep from wsl)
netstat.exe -an | grep 127.0.0.1        # windows from wsl (note .exe)

settings

wsl --set-default-version 2  # use wsl2 by default
wsl --set-version 2 <distro> # use wsl version for distro
wsl --set-default <distro>   #

Distros

Archlinux

https://github.com/yuk7/ArchWSL


Initial Setup:

Generate an updated mirrorlist here: https://archlinux.org/mirrorlist/

gsudo Arch.exe  # (or wsl -d Arch_Linux)
passwd          # set root passwd

# fix/update gpg keys and pacman
wget https://pkgbuild.com/~eschwartz/repo/x86_64-extracted/pacman-static 
chmod +x pacman-static
pacman-static -S archlinux-keyring
pacman-static -S libarchive
pacman-static -S zstd
pacman-static -S pacman

sudo pacman-key --init
sudo pacman-key --populate
sudo pacman-key --refresh-keys

sudo pacman -Syy
yes | sudo pacman -Syu

useradd -m will
passwd will

Usage:

# Start (search): windows terminal
gsudo wsl -u will
# do everything else within tmux