microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.56k stars 823 forks source link

Ability to specify the name during installation #9210

Open MartinAbadie opened 2 years ago

MartinAbadie commented 2 years ago

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 and wsl --install -d Ubuntu --name Ubuntu-pentest.

Thanks,

Biswa96 commented 2 years ago

It is possible to use existing VHDX file from one distribution in WSL2. For example,

  1. Create Ubuntu-dev as usual.
  2. Copy the ext4.vhdx file to another path.
  3. Use 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

MartinAbadie commented 2 years ago

Thanks @Biswa96 for this workaround. I still think about the --name feature, it could be practical and simplier.

NotTheDr01ds commented 2 years ago

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:

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>.