WSL 2
Learn to install WSL, an easy Linux environment on Windows, and configure it for code development.
Last updated
Learn to install WSL, an easy Linux environment on Windows, and configure it for code development.
Last updated
It is possible to have multiple distributions on WSL.
After reboot, updates are applied, and the terminal is automatically started to continue Ubuntu installation on WSL.
It will ask you to setup your Unix user and password.
If everything went well running wsl
in terminal will open the connection to Ubuntu.
When using your WSL, do NOT run things on /mnt/c/*
because it will lose performance.
Accessing Windows files from inside Linux is possible by accessing from /mnt/c
.
On Windows the Linux filesystem is basically a network folder as \\wsl$
.
wsl "name"
Connect to a specific distribution, in case you have more than one.
wsl -l -v
List all distributions with detailed information.
wsl --shutdown
Shutdown ALL distributions.
wsl --terminate "name"
Shutdown specific distribution.
wsl --help
Show all wsl options and arguments.
.wslconfig
vs wsl.conf
The .wslconfig
is a global configuration file that applies configuration to ALL the distros.
This file is not automatically created.
Must be placed to your Windows User root folder. (%UserProfile%
or C:\Users\<UserName>
)
WSL will detect the existence of this file every time it is initiated. If the file is incorrect, WSL will initiate without the specified configurations.
If you want to setup configurations for specific distros then use the wsl.conf
file.
You will place this file in /etc
folder of the desired distribution. (/etc/wsl.conf
)
.vhdx
fileThe WSL2 virtual disk is a vhdx
file that grows as you use your linux distro. If you exclude files, the disk will not shrink automatically. (vhdx
always grows)
To make it auto reduce, active the sparse
mode of WSL2 on the .wslconfig
. (Only for future created virtual disks)
Don't forget to restart the distro after the changes.
For virtual disks that were already created you can convert them with:
If even after that the disk size does not decrease, you can manually shrink with this third-party tool.
After changes on this file don't forget to wsl --terminal "name".
Your code project would stay inside Linux, but you will code from Windows.
Before openning projects inside WSL in VSCode, make sure you have the Remote Development
plugin installed in VSCode.
.vhdx
fileYou can find the .vhdx
file, which is the virtual machine hard drive file here:
You could save this entire file to backup the entire Linux.
If you format your computer, on your new install:
Install wsl again.
Configure same user and password (maybe not needed).
Shutdown the Linux virtual machine.
Substitute the .vhdx
file with the backup one.