By default when a Linux distro is being installed on WSL, it will be installed on the primary drive or OS drive. The default installation drive for installing applications is usually the primary drive, over time the primary drive might run out of space. Installing WSL on a secondary or a different drive would be an option if the primary drive is low in disk space or it would be the user’s preference.
Prerequisites
- User has admin rights to the PC/laptop
- WSL (Windows Subsystem for Linux) feature in Windows should be turned-on .
- Run Windows update to get WSL version 2
- Run the Linux kernel update
- Set the default version of WSL to 2.
- Go to Windows Command Prompt (i.e.
cmd
) - Run the following command
wsl --set-default-version 2
- Go to Windows Command Prompt (i.e.
- Powershell installed (by default it is installed with Windows)
- Identify the disk drive on where to install the Linux distro. The disk drive could be an internal disk drive in PC / laptop or it can be an external USB disk drive. The disk drive can be a HDD (hard disk drive) or SSD (solid state drive).
Downloading a WSL distro
For illustration purposes, Ubuntu 20.04 will be used.
Using Web Browser
Open your favorite browser and go to https://aka.ms/wslubuntu2004, this will download the Distro around (400MB+)
Using Windows Powershell
Open PowerShell terminal, and execute the following command
Note: Depending on your internet speed, downloading it through Powershell might take some time compared to doing it over the browser.
Installing the downloaded Distro
For illustration purposes, it uses D drive (i.e.D:
)
Step 1. Open Powershell terminal, change drive to D:
Step 2. Create a folder named “WSL” or whatever folder name to denote that it will be a placeholder for WSL distros.
Step 3. Move the downloaded file to D:WSL, below is an illustration once the file has been moved
Step 4. Rename the downloaded file, move .Ubuntu.appx .Ubuntu.zip
Step 5. Extract the zip to Ubuntu folder, by executing the Expand-Archive .Ubunutu.zip
Step 6. Go to Ubuntu folder, then run .Ubuntu2004.exe
. This will take time to install the distro once installed it would prompt for a username and password. Once the username and password is set you will be redirected to Ubuntu 20.04 as shown below
To go back to Windows, simply type exit
to end the session in Ubuntu. At this stage Ubuntu distro is successfully installed.
Step 7 Set default distro to Ubuntu. It is possible that there are multiple distro installed prior to the Ubuntu. To set Ubuntu as the default distro, run wsl -s Ubuntu-20.04
Where are the files installed?
Continuing on Step 7, view the files under D:WSLUbuntu
Take a look at the file,ext4.vhdx
, that is a virtual hard drive that will be used by WSL for Ubuntu.
To look into the files, go to File Explorer and type-in WSL$
in the search bar and press Enter. It would display all the mount drives on the WSL distros in your system. Below is a sample screenshot.
Takeaways
- Installing Linux distros in a different drive would avoid having disk space problems in the primary or OS drive. Initial vhdx (virtual hard disk) size is around 1.3GB, once additional updates or applications will be installed on the distro the vhdx file would grow.