Open MartinAbadie opened 2 years ago
It is possible to use existing VHDX file from one distribution in WSL2. For example,
wsl.exe --import-in-place
command to register that copied ext4.vhdx as Ubuntu-pentest.The last command requires WSL from Windows store. More details can be found here https://learn.microsoft.com/en-us/windows/wsl/basic-commands#import-a-distribution-in-place
Thanks @Biswa96 for this workaround.
I still think about the --name
feature, it could be practical and simplier.
I still think about the
--name
feature, it could be practical and simplier.
I like the idea, but given the way that WSL distributions work, it could be a bit tougher than you might think. There are really two different types of distributions:
Those installed by a distribution installer, whether through the Store or wsl --install -d <distro>
(which can also install either with or without the Store being involved, I believe.
These distributions, since they ultimately come in as a UWP package, are "installed" in two places:
The package files are installed in the "restricted" C:\Program Files\WindowsApps
. You can see the directories by using something like (from an elevated/admin PowerShell):
Get-ChildItem -Recurse 'C:\Program Files\WindowsApps\' | Where-Object {$_.Name -eq 'install.tar.gz' }
The distribution files are installed in $env:LOCALAPPDATA\Packages\<package_familyname>
.
These distributions must have an installer that conforms to the WSL Distro Launcher reference implementation. This is where ubuntu.exe
, ubuntu2204.exe
, alpine.exe
, etc. come into play. This installer is responsible for extracting the rootfs from the (1) application directory into the (2) distribution directory. It then asks for the default username/password. It may do more, such as the Ubuntu OOBE.
Those created manually through --import
(or its variations). These wouldn't be impacted by your suggested change.
With that in mind, it's not wsl --install
itself that chooses the location where things are installed (nor can change it, given the current implementation). It's the Distro Launcher, which is specific to each distribution.
Changing this would likely require not only changing WSL itself, but also every existing distribution that has a Distro Launcher and is available through wsl --install -d <distro>
.
Hi,
Sometimes I need to use many wsl context based on the same distro (ex: twice the Ubuntu distribution for dev and for pen testing), but it's not possible because of we can't specify a distribution name during the installation process
wsl --install -d Ubuntu
. So I need to export the first Ubuntu installation and import it with a specific name. Then I have to delete the original Ubuntu install to reinstall it to get a clean WSL.What could be nice, it's the ability to specify distro name at install step, ex:
wsl --install -d Ubuntu --name Ubuntu-dev
andwsl --install -d Ubuntu --name Ubuntu-pentest
.Thanks,