Wsl

πŸ›‘οΈ WSL Cheat-Sheet

This cheat-sheet provides essential commands for managing Windows Subsystem for Linux (WSL), including backing up and restoring distros, symbolic links, file permissions, networking, and running a Linux desktop in WSL2.


πŸ” Overview

  • Product Type: WSL Management Commands

  • Focus: Key commands for managing WSL distros, symbolic links, networking, and configuring advanced settings.


🧠 Key Commands

πŸ”„ Backup and Restore WSL

Listing Running Distros

wsl --list --verbose

Starting/Restarting a Distro

wsl --distribution DISTRO-NAME

Terminate a Running Distro

wsl --t DISTRO-NAME

Terminate All Running Distros and WSL Process

wsl --shutdown

Backup a WSL Distro

wsl --export (distribution) (filename.tar)

Restore a WSL Distro from Backup

wsl --import (distribution) (install location) (file location and filename)

sudo ln -s /mnt/c/Users/lempa/.ssh ~/.ssh
sudo ln -s /mnt/c/Users/lempa/.kube ~/.kube

πŸ” File Permissions

For advanced settings configuration in WSL, refer to WSL Config Parameters.

Example wsl.conf

[automount]
enabled = true
options = "metadata,uid=1000,gid=1000,umask=077,fmask=11,case=off"
mountFsTab = true

[interop]
enabled = false
appendWindowsPath = false

🌐 Networking

Port Forwarding

Find IP Address

bash.exe -c "ifconfig eth0 | grep 'inet '"

Add Port Forwarding

$port = 8080
$remoteaddr = 0.0.0.0

netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteaddr

netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$port

Delete Port Forwarding

$port = 8080

netsh interface portproxy delete v4tov4 listenport=$port
netsh advfirewall firewall delete rule name=$port

Show Port Forwardings

netsh interface portproxy show v4tov4

πŸ–₯️ Linux Desktop in WSL2

With WSL2, it’s possible to install and run a Linux desktop environment (such as XFCE). A tutorial on how to implement this can be found here.


πŸ“š Resources



πŸ” Explore More


🏷️ Tags

#wsl
#backup-restore
#symbolic-links
#file-permissions
#networking
#port-forwarding
#linux-desktop
#wsl2