Skip to main content

Windows Subsystem for Linux (WSL)

·456 words·3 mins· ·
Table of Contents

Windows Subsystem for Linux (WSL)
#

WSL is Linux on Windows. It is free and there are multiple OS’es you can get.

PS C:\Users\ebdruplab> 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
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
Ubuntu-24.04                           Ubuntu 24.04 LTS
OracleLinux_7_9                        Oracle Linux 7.9
OracleLinux_8_7                        Oracle Linux 8.7
OracleLinux_9_1                        Oracle Linux 9.1
openSUSE-Leap-15.5                     openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed                    openSUSE Tumbleweed

Installation
#

To get the best expirence from WSL plece install windows terminal.

After that come back to this guide.

  1. Open Windows Terminal
  2. write the command wsl --install -d Ubuntu (change Ubuntu to what ever you wan’t from the list gotten)
  3. wsl --update
  4. You will be asked to give a Username and Password.

As this is a dev env I would highly recommend doing the following

  1. touch /home/$USER/.hushlogin
  2. USERNAME="ebdruplab";echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/$USERNAME" >/dev/null First time you will be asked for your password
  3. Setup your dotfile, my setup can be found Linux dot Files
  4. Setup your wsl config file sudo vi /etc/wsl.conf
[boot]
systemd=true

[wsl2]
memory = 18GB
processors = 16 # Makes the WSL 2 VM use six virtual processors (4 Cores x 8 Threads) x 1 CPU = 32 vCPUs
  1. Upgrade and update system: sudo apt-get update -y && sudo apt-get upgrade -y

Configuration
#

You can configure your windows terminal, but right now this is out of scope of this blog post, maybe I’ll add it later

WSL Cheat-Sheet
#

Backup and Restore WSL
#

CommandDescription
wsl --list --verboseList Running Distros
wsl --distribution <distro>Start/Restart a Distro
wsl --t <distro>Terminate a Running Distro
wsl --shutdownTerminate All Running Distros and WSL process
wsl --export (distribution) (filename.tar)Backup a WSL Distro
wsl --import (distribution) (install location) (file location and filename)Restore a WSL Distro from Backup

Symbolic Links#

CommandDescription
sudo ln -s /mnt/c/Users/<user>/.ssh ~/.sshLink .ssh folder
sudo ln -s /mnt/c/Users/<user>/.kube ~/.kubeLink .kube folder

Networking
#

CommandDescription
netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteaddrAdd Port Forwarding
netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$portAdd Firewall Rule
netsh interface portproxy delete v4tov4 listenport=$portDelete PortForwarding
netsh advfirewall firewall delete rule name=$portDelete Firewall Rule
netsh interface portproxy show v4tov4Show PortForwardings

Setup pbcopy and pbpaste on WSL
#

This is mac native and can be setup on wsl 2

sudo apt install xsel

# Then add to your .bash_profile
# Install using sudo apt install xsel
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
Kristian
Author
Kristian