microsoft / WSL

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

Ability to install multiple instances of a distro with `wsl --install <distro> <instance_name> <location> --version 1/2` #6883

Open NotTheDr01ds opened 3 years ago

NotTheDr01ds commented 3 years ago

Is your feature request related to a problem? Please describe.

WSL instances are great as "single purpose", sometimes even "throwaway" containers for testing out a piece of functionality. Today, I do this by keeping "pristine" copies of each distro by wsl --exporting them immediately after installation. I can then spin up new instances by wsl --importing those tarballs.

I realize that it's also possible to get the pristine tarball from the Program Files\WindowsApps folder, but this is even more painful, IMHO, since you have to (a) find and get access to the right folder from an elevated PowerShell, and (b) unzip the tarball before wsl --import can handle it.

The new wsl --install <distro> sounds great (I'm not on Preview), but doesn't sound like it goes far enough towards solving this particular problem.

Describe the solution you'd like

Extend wsl --install <distro> to accept optional parameters for <instance_name>, <location>, and --version 1/2 similar to the wsl --import command.

Describe alternatives you've considered

Alternatives are listed in the "problem statement" above.

Additional context

N/A

ad-on-is commented 3 years ago

An alternative would be to wsl --export <distroname> <tarballlocation> an installed distro to a specific location, which already saves it as a tarball, and then wsl --import <distroname_x> <installlocation> <tarballlocation> it multiple times.

Baalkikhaal commented 3 years ago

@NotTheDr01ds is there a difference between multiple instances of a distribution and multiple terminals of a distribution πŸ€” ?

Biswa96 commented 3 years ago

The term "instance" is somewhat wrong in this context. The author means multiple installation of same distribution. For example, one can install Debian twice with different registered WSL distro names for two different development environment.

Baalkikhaal commented 3 years ago

@Biswa96 That is neat πŸ˜„ .

Testing multiple instances/installations

To test it, I did

C:\Users\fubar>wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-18.04    Stopped         2

Export the distro to a tar file

C:\Users\fubar>wsl --export Ubuntu18.04 D:\WSL_Backups\ubuntu_18_lts.tar

Import the distro as a new installation/instance

C:\Users\fubar>wsl --import Ubuntu-copy D:\WSL_Distro_Storage\Ubuntu D:\WSL_Backups\ubuntu_18_lts.tar

WSL distro listing

C:\Users\fubar>wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-18.04 (Default)
Ubuntu-copy

Nautilus is getting listed for both the copies.

image

Concerns

Will the exported backups be successfully imported after there is a wsl --update as this might upgrade Linux kernel πŸ€” ?

References:

Biswa96 commented 3 years ago

Updating the Linux kernel does not* affect the installed GNU/Linux distributions in WSL. Linux kernel folder is mounted separately in /tools folder by initrd.

*generally

NotTheDr01ds commented 3 years ago

An alternative would be to wsl --export <distroname> <tarballlocation> an installed distro to a specific location, which already saves it as a tarball, and then wsl --import <distroname_x> <installlocation> <tarballlocation> it multiple times.

Yes, that's what I do today as mentioned in the first paragraph in the issue ;-). The downside, of course, is that you have to keep the tarballs around (on each system, or in a central location, if you work on multiple machines). And you have to make sure that you wsl --export it first thing after installing from the Store, to have a pristine copy before you make any changes.

Being able to wsl --install the same distribution multiple times would solve these limitations.

NotTheDr01ds commented 3 years ago

The term "instance" is somewhat wrong in this context. The author means multiple installation of same distribution. For example, one can install Debian twice with different registered WSL distro names for two different development environment.

Agreed, "instance" or "installation". Either is better than the WSL doc/help which calls each installation a "distribution".

ohadschn commented 3 years ago

Ideally this would also create Start Menu shortcuts and Windows Terminal integration (specifically, create new terminal windows with specific instances conveniently from the dropdown), rather than manually executing something like wsl -d MyUbuntuInstance.