Virtualization

Windows Subsystem for Linux (WSL) Tips

Posted October 1, 2024

By Kevin Schwickrath1 min read

WSL lets you install a Linux distribution (such as Ubuntu) to use Linux command-line tools directly on Windows. You get Linux with a real Linux kernel right from Terminal. In my examples I’m using Windows 11.

Easy install

First, ensure your BIOS options are enabled. You will need to turn on the virtualization features if they are not enabled by default. Next, head over to the the Microsoft Store and search for the distribution you want.

Setup WSL via CLI

Open Terminal and type

Terminal window
wsl --install

Select the distribution

In Windows Terminal, you can list the available distribution.

Terminal window
wsl --list --online

Install your desired image either with the following command.

Terminal window
wsl --install -d <Distribution Name>

This command will install Ubuntu-24.04 in the specified directory with the distribution name of newdistro.

Terminal window
wsl --install Ubuntu-24.04 --location "C:\Users\Kevin\WSL\newdistro" --name newdistro

Start the distribution

Terminal window
wsl -d newdistro

Setup your distribution

Create your user account and password.

Terminal window
PS C:\Users\Kevin\WSL> wsl --install Ubuntu-24.04 --location "C:\Users\Kevin\WSL\newdistro" --name newdistro
Downloading: Ubuntu 24.04 LTS
Installing: Ubuntu 24.04 LTS
Distribution successfully installed. It can be launched via 'wsl.exe -d newdistro'
PS C:\Users\Kevin\WSL> wsl -d newdistro
Provisioning the new WSL instance newdistro
This might take a while...
Create a default Unix user account: kevin
New password:
Retype new password:
passwd: password updated successfully
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Thu Feb 27 21:14:10 CST 2025
System load: 0.43 Processes: 31
Usage of /: 0.1% of 1006.85GB Users logged in: 0
Memory usage: 1% IPv4 address for eth0: 192.168.230.185
Swap usage: 0%
This message is shown once a day. To disable it please create the
/home/kevin/.hushlogin file.

Edit the WSL config

WSL has many configuration options. Advanced settings configuration in WSL | Microsoft Learn

Use vi or a similar editor to edit the file.

Terminal window
vi /etc/wsl.conf

I typically use the following options in my config file.

[boot]
systemd=true
[network]
hostname=newdistro
[user]
default=kevin

Shutdown the image

Once you have made your initial changes, stop the distribution.

Terminal window
wsl --shutdown UbuntuDev2

Shutdown all the running distributions

Side tip: if you want to shut down all the distributions, use the following command.

Terminal window
wsl --shutdown

Verify distribution states

Terminal window
PS C:\Users\Kevin> wsl --list --all -v
NAME STATE VERSION
* Ubuntu Running 2
UbuntuDev1 Stopped 2
docker-desktop-data Stopped 2
docker-desktop Stopped 2

Restart the distribution and login

Terminal window
wsl -d UbuntuDev2

Updates

Don’t forget to run your updates.

Terminal window
sudo apt update
sudo apt upgrade

Check your release info with this command:

Terminal window
kevin@Dev2:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

Have fun!

Sources / Linkage

This post is licensed under CC BY 4.0 by the author.

Related Posts

Manually Update VMWare ESXi

Virtualization · Feb 18, 2022 · 3 min read

VMWare is in the news again. I feel the next 24 months will be rough for security teams across the board. Many have spent the last year or more in…