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.
- Open Windows Terminal
- write the command
wsl --install -d Ubuntu
(change Ubuntu to what ever you wan’t from the list gotten) wsl --update
- You will be asked to give a Username and Password.
As this is a dev env I would highly recommend doing the following
touch /home/$USER/.hushlogin
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- Setup your dotfile, my setup can be found Linux dot Files
- 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
- 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#
Command | Description |
---|---|
wsl --list --verbose | List Running Distros |
wsl --distribution <distro> | Start/Restart a Distro |
wsl --t <distro> | Terminate a Running Distro |
wsl --shutdown | Terminate 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#
Command | Description |
---|---|
sudo ln -s /mnt/c/Users/<user>/.ssh ~/.ssh | Link .ssh folder |
sudo ln -s /mnt/c/Users/<user>/.kube ~/.kube | Link .kube folder |
Networking#
Command | Description |
---|---|
netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteaddr | Add Port Forwarding |
netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$port | Add Firewall Rule |
netsh interface portproxy delete v4tov4 listenport=$port | Delete PortForwarding |
netsh advfirewall firewall delete rule name=$port | Delete Firewall Rule |
netsh interface portproxy show v4tov4 | Show 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'