Raymond Raymond

Install Windows Subsystem for Linux on a Non-System Drive

event 2019-05-15 visibility 67,535 comment 11 insights toc
more_vert
insights Stats

This page shows how to install Windows Subsystem for Linux (WSL) system on a non-system drive manually. It can work with both WSL 1 and WSL 2.

Enable Windows Subsystem for Linux system feature

Open PowerShell as Administrator and run the following command to enable WSL feature:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Create a folder in a non-system drive

Run the following command in PowerShell to create a folder for the installation. For my environment, I will create the folder in F drive.

cd F:\mkdir WSLcd WSL

Download a Linux distro

Run the following command in PowerShell to download a distro:

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu.appx -UseBasicParsing

The following distros are available:

Unpack the downloaded distro

Run the following PowerShell commands to unpack:

move .\Ubuntu.appx .\Ubuntu.zipExpand-Archive .\Ubuntu.zip

Initialize Linux distro

In the unzipped folder, there is one executable (*.exe).

cd .\Ubuntu\ls

Directory: F:\WSL\Ubuntu


Mode                LastWriteTime         Length Name

----                -------------         ------ ----

d-----       15/05/2019   7:40 PM                AppxMetadata

d-----       15/05/2019   7:40 PM                Assets

-a----       17/08/2018   3:15 AM         212438 AppxBlockMap.xml

-a----       17/08/2018   3:15 AM           3835 AppxManifest.xml

-a----       17/08/2018   3:17 AM          11112 AppxSignature.p7x

-a----       17/08/2018   3:15 AM      223983209 install.tar.gz

-a----       17/08/2018   3:15 AM           5400 resources.pri

-a----       17/08/2018   3:15 AM         211968 ubuntu1804.exe

-a----       17/08/2018   3:15 AM            744 [Content_Types].xml

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


Run the executable to initialize:

 .\ubuntu1804.exePS F:\WSL\Ubuntu> .\ubuntu1804.exe
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: raymond
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

* You need to input a user name and password. I am using username raymond with**‘password’** as password.


Once the installation is done, you can see a new folder is created:

PS F:\WSL\Ubuntu> ls

Directory: F:\WSL\Ubuntu


Mode                LastWriteTime         Length Name

----                -------------         ------ ----

d-----       15/05/2019   7:40 PM                AppxMetadata

d-----       15/05/2019   7:40 PM                Assets


da----       15/05/2019   7:47 PM                rootfs

d-----       15/05/2019   7:49 PM                temp

-a----       17/08/2018   3:15 AM         212438 AppxBlockMap.xml

-a----       17/08/2018   3:15 AM           3835 AppxManifest.xml

-a----       17/08/2018   3:17 AM          11112 AppxSignature.p7x

-a----       17/08/2018   3:15 AM      223983209 install.tar.gz

-a----       17/08/2018   3:15 AM           5400 resources.pri

-a----       17/08/2018   3:15 AM         211968 ubuntu1804.exe

-a----       17/08/2018   3:15 AM            744 [Content_Types].xml

If you install WSL from Microsoft Store, the default folder in your Windows user profile will be used:

%localappdata%\Packages

rootfs folder includes the following folders:

PS F:\WSL\Ubuntu> cd .\rootfs\
PS F:\WSL\Ubuntu\rootfs> ls

Directory: F:\WSL\Ubuntu\rootfs


Mode                LastWriteTime         Length Name

----                -------------         ------ ----

da----       15/05/2019   7:47 PM                bin

da----       15/05/2019   7:44 PM                boot

da----       15/05/2019   7:44 PM                dev

da----       15/05/2019   7:48 PM                etc

da----       15/05/2019   7:48 PM                home

da----       15/05/2019   7:44 PM                lib

da----       15/05/2019   7:44 PM                lib64

da----       15/05/2019   7:44 PM                media

da----       15/05/2019   7:47 PM                mnt

da----       15/05/2019   7:44 PM                opt

da----       15/05/2019   7:44 PM                proc

da----       15/05/2019   7:44 PM                root

da----       15/05/2019   7:44 PM                run

da----       15/05/2019   7:44 PM                sbin

da----       15/05/2019   7:44 PM                snap

da----       15/05/2019   7:44 PM                srv

da----       15/05/2019   7:44 PM                sys

da----       15/05/2019   7:56 PM                tmp

da----       15/05/2019   7:46 PM                usr

da----       15/05/2019   7:47 PM                var

-a----       15/05/2019   7:56 PM          87944 init

These folders include all the Ubuntu folders (libs, executables, etc.).

List all the WSL installations

You can install many Linux distributions in one Windows system.


wslconfig command can be used to list all the installed distributions and set default distribution:

wslconfig
Performs administrative operations on Windows Subsystem for LinuxUsage:     /l, /list [/all] - Lists registered distributions.         /all - Optionally list all distributions, including distributions that                are currently being installed or uninstalled.     /s, /setdefault <DistributionName> - Sets the specified distribution as the default.     /u, /unregister <DistributionName> - Unregisters a distribution.

Find out all the WSL installations in your Windows system using the following command:

wslconfig /l
Windows Subsystem for Linux Distributions:
Ubuntu-18.04 (Default)

Set default distribution:

wslconfig /setdefault Ubuntu-18.04 

Run the following command to start the default WSL distribution:

wsl

image


To uninstall a distribution, use the following command:

wslconfig /u distribution_name

Now you have a WSL installed in a non-system drive. Have fun!

More from Kontext
comment Comments
Raymond Raymond #1784 access_time 2 years ago more_vert

Did you follow the exact steps in the guide? The error you encounter usually is caused by that fact the file to unzip us big a zip file. You can try downloading the file through browser and then unzip using GUI tools like 7zip and then follow other steps to install.

format_quote

person Graham access_time 2 years ago

I uninstalled everything then tried again and got this exception:-

"New-Object : Exception calling ".ctor" with "3" argument(s): "Zip 64 End of Central Directory Record not where
indicated."
At
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:934
char:23
+ ... ipArchive = New-Object -TypeName System.IO.Compression.ZipArchive -Ar ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand"

So my system is still trying to use the "C" drive, didn't get this last time but it installed correctly, just on my C drive.


G Graham Beard #1783 access_time 2 years ago more_vert

I uninstalled everything then tried again and got this exception:-

"New-Object : Exception calling ".ctor" with "3" argument(s): "Zip 64 End of Central Directory Record not where
indicated."
At
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:934
char:23
+ ... ipArchive = New-Object -TypeName System.IO.Compression.ZipArchive -Ar ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand"

So my system is still trying to use the "C" drive, didn't get this last time but it installed correctly, just on my C drive.


G Graham Beard #1782 access_time 2 years ago more_vert

Doesn't work for me, still uses my SSD drive not the one I want. I've also set the system to install on my "D" drive, but always installs on "C".

Raymond Raymond #1613 access_time 3 years ago more_vert

I’m glad you figured it out. Let me know if you encounter any other issue.

format_quote

person Taha C. access_time 3 years ago

Never mind I looked around some more a found a solution the kali exe is buried another layer in. So after the first extraction. You get this.



after renaming and extracting using the steps in the guide you get this.



and then moving into that folder and doing ls we see the kali.exe


TC Taha C. Raza #1612 access_time 3 years ago more_vert

Never mind I looked around some more a found a solution the kali exe is buried another layer in. So after the first extraction. You get this.



after renaming and extracting using the steps in the guide you get this.



and then moving into that folder and doing ls we see the kali.exe


TC Taha C. Raza #1611 access_time 3 years ago more_vert

Hi I tried to install kali linux using this guide but after extracting the zip file there was no executeble in the extracted directory. Just these files


How can I install the distro from these?
Raymond Raymond #1603 access_time 3 years ago more_vert

I'm glad it helps :).

format_quote

person Dmitry access_time 3 years ago

The only helpful tutorial to get WSL working on Win10 after c:\Program Files\WindowsApps\ folder was broken or something (running [...]\ubuntu.exe from there resulted "File not found" error although the file was there).
Thank you!

D Dmitry A #1602 access_time 3 years ago more_vert

The only helpful tutorial to get WSL working on Win10 after c:\Program Files\WindowsApps\ folder was broken or something (running [...]\ubuntu.exe from there resulted "File not found" error although the file was there).
Thank you!

F Fep Eva #1508 access_time 3 years ago more_vert
Although it has been a while since OPs comment, will be leaving this reply here to help out any future visitors.

This is because the article is outdated, and uses WSL1. Your Ubuntu 18.04 is probably installed with WSL2, which uses Virtual Hard Disk (.vhdx) to store your Linux files. Afaik, the way to install your WSL2 on a non system drive is to first install it on C: drive by default, then to export it to a tar file using 

wsl.exe --export <DistributionName> <FileName>

This will generate a tarball of your WSL distribution (It might take a while depending on .vhdx file size). After that, you can import that distribution to any other location, including a non-system drive, like so:

wsl.exe --import <DistributionName> <InstallLocation> <FileName>
format_quote

person Michael access_time 3 years ago

I have Ubuntu 18.04 installed and have it set as my default with wsl.  I do not have the rootfs after installing it.  What I have is

is the ext4.vhdx what the rootfs actually is?

I appreciate your help and the rest of everything that you posted was great.  I just want to see what I messed up.  XD

Raymond Raymond #1483 access_time 3 years ago more_vert

Hi Michael,

Did you see the installation logs like the following one?

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: raymond
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
format_quote

person Michael access_time 3 years ago

I have Ubuntu 18.04 installed and have it set as my default with wsl.  I do not have the rootfs after installing it.  What I have is

is the ext4.vhdx what the rootfs actually is?

I appreciate your help and the rest of everything that you posted was great.  I just want to see what I messed up.  XD

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts