Is there any way to install WSL on non-C drive?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: City Beneath the Waves Looping
--
Chapters
00:00 Is There Any Way To Install Wsl On Non-C Drive?
00:23 Accepted Answer Score 53
01:30 Answer 2 Score 13
02:22 Answer 3 Score 6
04:45 Answer 4 Score 3
05:07 Thank you
--
Full question
https://superuser.com/questions/1572834/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows10 #windowssubsystemforlinux
#avk47
ACCEPTED ANSWER
Score 53
Yes. First, note the URL of the distribution you want to install in this list, ex: https://aka.ms/wslubuntu2204
Now open PowerShell:
# Substitute the drive on which you
# want WSL to be installed if not D:
Set-Location D:
# Create a directory for our installation and change to it, we'll call it WSL:
New-Item WSL -Type Directory
Set-Location .\WSL
# Using the URL you found above, download the appx package:
curl.exe -L -o Linux.appx <distribution_package_url>
# Make a backup and unpack:
Copy-Item .\Linux.appx .\Linux.zip
Expand-Archive .\Linux.zip
# Search for the installer:
Get-Childitem -Filter *.exe
You might find a file named <distribution>.exe
. Run that file, and the WSL distribution should be installed in the unpack folder of the other drive. If you don't see an executable, let's look for an .appx file that was just unpacked, that is the flavor you want, and unzip that, as follows:
Set-Location Linux
# look for correct appx file:
Get-Childitem -Filter *.appx
# rename to .zip so that Expand-Archive will work
ren .\Ubuntu_2204.1.7.0_x64.appx .\Ubuntu_2204.zip
Expand-Archive .\Ubuntu_2204.zip
Set-Location .\Ubuntu_2204
# Now exe should exist:
Get-Childitem -Filter *.exe
# run it
.\ubuntu.exe
After completion, you can now delete everything just downloaded/created except ext4.vhdx
(for WSL2) or rootfs
(for WSL1), and ubuntu.exe
file, which starts that distro and can change the default username.
ANSWER 2
Score 13
There seems to be a much easier answer to this, at least on windows 11 if your not really wanting to run around with powershell commands in your head.
Basically, install a distro. For example:
wsl --install -d Ubuntu
Unregister it:
wsl --unregister Ubuntu
This deletes your "root" drive as such, but doesn't remove the ubuntu image.
Go to Settings > Apps > Apps & Features, search for ubuntu, then click on the three dots button next to the result, should look something like this:
Click on move, then just choose the drive.... go to the start menu (or hit the windows key or whatever works for you), search for ubuntu and run it which kicks off the installer.
Everything it does will now be on the drive you chose including the running disk image.
ANSWER 3
Score 6
I really like @Wasif's answer, but I'll add some additional details that didn't seem appropriate for an edit:
First, and most importantly, as noted in the comments, the
<distribution>.exe
typically is no longer found directly in the Appx package. The Appx that you download is a now a MSIX package that can (and does, in this case) include packages for multiple architectures. For most distributions, after theExpand-Archive
, you'll find several additional Appx files, but no.exe
. For example, here are the contents of the Ubuntu 20.04 package:Directory: D:\WSL\instances\Ubuntu\installer\Linux Name ---- AppxMetadata AppxBlockMap.xml AppxSignature.p7x Ubuntu_2004.2021.825.0_ARM64.appx Ubuntu_2004.2021.825.0_scale-100.appx Ubuntu_2004.2021.825.0_scale-125.appx Ubuntu_2004.2021.825.0_scale-150.appx Ubuntu_2004.2021.825.0_scale-400.appx Ubuntu_2004.2021.825.0_x64.appx [Content_Types].xml
The important ones are the
_ARM64
and_x64
packages. Choose the one for your architecture (typically_x64
) andExpand-Archive
that package.Note that, if you are using PowerShell Core, you can
Expand-Archive
theappx
file directly. Otherwise you'll need to rename it to a.zip
as @Wasif's answer recommends.After expanding that archive, you should find the
<distribution>.exe
file you need to run.If you are concerned about disk space, realize that all that you need from the extracted archive are two files:
<distribution>.exe install.tar.gz
You can move these over to the top level directory that you created (e.g.
D:\WSL
) and delete everything else. I do recommend copying the files before running the.exe
as the location it is in will end up being the installation location.After installing, you can also remove the
install.tar.gz
. You could even remove the<distro>.exe
, but you might want to keep it around. It can be used to either run the distribution or to change the default username if needed.Note that installing this way will not create a Windows Start menu entry for the distribution. It's still possible to set one up manually to point to either
wsl.exe
(for the default distribution) orwsl ~ -d <distroname>
ANSWER 4
Score 3
WSL requires the C drive, but you can move distros to other drives;
wsl --export ".bak" wsl --unregister wsl --import <D:\Example> .bak
^This can lead to linker errors, but hopefully those are easier to resolve than this obscure feature of import was to find.