DEV Community

PRAHAR~1
PRAHAR~1

Posted on

Installing MSFT Store WSL Distros to a custom location

If you are running out of space on your C drive and want to keep your DEV environment and tools in a separate location for some reason, follow this guide.

By default the Linux distributions installed from the Microsoft Store are available in the same place as other Windows store apps (%USERPROFILE%\AppData\Local\Packages).

Grab the .appx package file:

To download the .appx package of a distro directly, run the following in PowerShell:

Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.appx -UseBasicParsing
Enter fullscreen mode Exit fullscreen mode

This will download Ubuntu 20.04 distro and save it under the name “Ubuntu.appx”

Available Distros:

Ubuntu 20.04 - https://aka.ms/wslubuntu2004
Ubuntu 20.04 ARM - https://aka.ms/wslubuntu2004arm
Ubuntu 18.04 - https://aka.ms/wsl-ubuntu-1804
Ubuntu 18.04 ARM - https://aka.ms/wsl-ubuntu-1804-arm
Ubuntu 16.04 - https://aka.ms/wsl-ubuntu-1604
Debian GNU/Linux - https://aka.ms/wsl-debian-gnulinux
Kali Linux - https://aka.ms/wsl-kali-linux-new
OpenSUSE Leap 42 - https://aka.ms/wsl-opensuse-42
SLES - https://aka.ms/wsl-sles-12

Unpack the distro:

Navigate to the directory and extract the package. Extract to a folder that has full access permission.
You can unzip the downloaded package using any archiver of your choice, or you can simply do it via PowerShell itself:

move .\Ubuntu.appx .\Ubuntu.zip
Expand-Archive .\Ubuntu.zip
Enter fullscreen mode Exit fullscreen mode

Initializing

In the unzipped folder there’s an EXE file (according to the name of the distribution)

Folder

Based on the version of Linux distro you are using, the executable name can be different.

Now, run the executable to start initializing…
This will extract the “rootfs” and Register the WSL.

NOTE: You can register with a different name using wsl --import and perform multiple installs :)

wsl.exe --import <DistributionName> <InstallLocation> <FileName>
Enter fullscreen mode Exit fullscreen mode

Eg:

wsl.exe --import Debian1 D:\Deb1 .\install.tar.gz
Enter fullscreen mode Exit fullscreen mode

Wait till the process completes and you’ll be prompted to create a new user account and rest of the process follows accordingly.

Img2

After the installation is complete, you’ll find the “rootfs” folder is created which has all the libraries, executables etc…

Img3

To verify installation use wsl --list --all or wsl -l --all to list names of installed or imported WSL distros.

Img4

Adding to PATH

You’ll have to use the distribution launcher application in target folder every time to run your distro. So, additionally you can add your distro path to PATH environment variable to invoke it from anywhere.

$userenv = [System.Environment]::GetEnvironmentVariable(“Path”, “User”) [System.Environment]::SetEnvironmentVariable(“PATH”, $userenv + “;D:\DebianWSL”, “User”)
Enter fullscreen mode Exit fullscreen mode

Useful Links:

Discussion (0)