blog about admin

WSL teaks

2022-12-30

A few tweaks I've found to make WSL just a little more awesome.

Assumptions

You've played with WSL before

If not, start here

https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux
https://learn.microsoft.com/en-us/windows/wsl/about

WSL v1

Used to be like WINE or Cygwin in reverse, pretty cool.

WSL v2

Eh, just make it a VM.
Ok, that's not fair. Virtualised, like a VM, but different. Reverse WINE is just way more cool to me, but v2 does work better / faster, and works with the whole virtualisation-based security thing, might be some security type cool stuff in the pipeline.
That said, at time of writing, it's not a security boundy, nor intended to be one. Stuff runs in the context of the parent process (you!)

Use a good distro

That does not include Ubuntu.

Not these either
https://learn.microsoft.com/en-us/windows/wsl/install-manual

wsl --list --online

The following is a list of valid distributions that can be installed.
Install using 'wsl --install -d <Distro>'.

NAME               FRIENDLY NAME
Ubuntu             Ubuntu
Debian             Debian GNU/Linux
kali-linux         Kali Linux Rolling
SLES-12            SUSE Linux Enterprise Server v12
SLES-15            SUSE Linux Enterprise Server v15
Ubuntu-18.04       Ubuntu 18.04 LTS
Ubuntu-20.04       Ubuntu 20.04 LTS
OracleLinux_8_5    Oracle Linux 8.5
OracleLinux_7_9    Oracle Linux 7.9

You can use a vanilla container image, clean and minimal, only install what you need.

https://learn.microsoft.com/en-us/windows/wsl/use-custom-distro

DistroSource
Rocky Linuxhttps://docs.rockylinux.org/guides/interoperability/import_rocky_to_wsl/
CentOS Streamhttps://cloud.centos.org/centos/
Arch Linuxhttps://gitlab.archlinux.org/archlinux/archlinux-docker/-/releases
  1. Don't need admin privs for any of this
  2. Using Rocky Linux here, but same process works for any other
  3. Substitute "myRockyLinux01" name and file paths
:: check if you have WSL installed, and any distros
wsl --list

:: import the image (auto creates the directory, there's a VHDX in there)
wsl --import "myRockyLinux01" "C:\Users\xxx\AppData\Local\Programs\WSL\myRockyLinux01" "C:\Users\xxx\Downloads\Rocky-9-Container-Base.latest.x86_64.tar" --version 2

:: should  now see your new install
wsl --list

I have another install already
wsl --list

:: should log you in as root
wsl
:: can make another account later

Won't have much installed, just the basics

It's like any other Linux box at this point, do some updates, install what you need to get started.

dnf -y update
dnf -y install epel-release
dnf -y install vim bind-utils curl wget tree ncdu ncurses iproute 

/etc/wsl.conf

Give this a good read, make your own decisions.

https://learn.microsoft.com/en-us/windows/wsl/wsl-config

I landed on the following, your use case might be different.

Big performance gain came from disabiling nested virtualisation and interop.

/etc/wsl.conf

[boot]
systemd=true

[automount]
enabled = true

[interop]
enabled = false
appendWindowsPath = false

[wsl2]
nestedVirtualization = false

[user]
default = notroot

wsl --terminate myRockyLinux01