DEV Community

Harsh Kumar
Harsh Kumar

Posted on • Updated on

Setting Up WSL in windows 10 and above

Hi Devs,
The purpose of this blog is to explain how to configure WSL (Window subsystem Linux) and how to move the installed WSL distribution to a different drive.

So let's start with some basic questions-:

1. What is WSL ?

Basically WSL or Windows Subsystem for Linux is a feature of using both Windows and Linux at the same time.

2. Why WSL ?

Because it doesn't require any separate virtual machine or dual booting for running Linux distributions.

3. How WSL ?

Below are the simple steps for running WSL on your Windows machine-:
a) Open your Windows PowerShell or Windows CMD in administrator mode.
b) write the command
wsl --install (First-time user who has never installed WSL)
or
wsl --install -d Ubuntu (If WSL is installed but none of the distribution is present)

This will install the default Linux distribution, Ubuntu, after which you'll be asked for a username and password. Type whatever you want to use.

Important Commands to keep in mind

  • wsl -l -v gives the version of your WSL

  • wsl --set-default-version <v> set the version of your WSL by replacing <v> to 1 or 2

  • wsl -l -o gives the list of all available Linux distributions online

  • wsl -l gives the list of all installed Linux distributions in your machine

  • wsl --install -d <d> install new distribution by replacing <d> with the distribution name

  • wsl -s <d> set the default distribution of your WSL by replacing <d> to any other distro

  • wsl --set-version <d> 2 set the distribution version to 2 by replacing <d> with distribution name

  • wsl --unregister <d> delete the existed distribution by replacing <d> with the distribution name

  • wsl pwd gives the path of where the current directory is mounted in ws

  • wsl date provide the date from the Linux file system

FAQ

  1. Can we run more than one distribution in WSL at same time ? Yes
  2. How to install additional distributions from inside a Linux/Bash command line? replace wsl -> wsl.exe in the above installation command
  3. How to move my WSL distribution to a different drive or location?
# Create a folder where you would like to store your distro
New-Item -ItemType Directory -Path <fp>

# Export your distro to that folder as a VHD
wsl --export --vhd <d> <fpe> 

# Unregister your old distro
# Please note this will erase your existing distro's file contents
# Ensure the above command has executed successfully
wsl --unregister <d>

# Import your VHD backup
wsl --import-in-place <d> <fpe>
Enter fullscreen mode Exit fullscreen mode

replace <fp> by the folder path of another drive where you want to keep the distro
replace <fpe> by the file path

example your previously installed distro is in C Drive
now you want to move it to the E drive
then <fp> is E:\WSLDistros\distroName
and <fpe> is E:\WSLDistros\distroName\ext4.vhdx

Thanks !! All feedbacks are appreciated.

Top comments (0)