11

I'd like to have 'n' debian installed, not once per version, but litterally 'n' installations of the same debian 12.

Each instance should have a different set of php/nginx|apache/mysql|mariadb

Is it possibile, for first thing, to install multiple time debian 12 on the same wsl2 on the same windows 11 pro host?

If yes, can multiple apache|nginx instances be running on same port 80/443, setting up them to listen only to internal wsl instance ip?

NotTheDr01ds
  • 28,025
realtebo
  • 730

2 Answers2

11

Here is how to have several copies of the same distribution:

  • Install the base distribution from the Windows Store or using:

    wsl --install -d <distribution name>
    
  • Log into the environment and modify as needed, then exit it

  • Export the environment with the following command:

    wsl --export <distribution name> <export file name>
    
  • Create a new instance of the base environment by importing the .tar file:

    wsl --import <new distribution name> <install location> <export file name>
    
  • You may now open the new environment using:

    wsl -d <new distribution name>
    
  • In Windows 11, you can browse the file-system of distributions in Explorer via Desktop > Linux

  • The new distribution will have root as the default user. To login as another user, either use the -u <username> flag or create/modify a wsl.conf file in /etc directory inside the environment, with the following section:

    [user]
    default=<username>
    

For more information with screenshots see the article
Setting up multiple WSL distribution instances.

harrymc
  • 498,455
8

If you installed Debian (or another distribution) from the Microsoft Store, then the root filesystem tarball will usually still be on your system and can be directly --imported into a new distribution. This can be useful when you want a "pristine" version that doesn't include the changes you've made in your existing distro.

To do so:

  1. Start a PowerShell Admin shell. Admin access is only needed to run the following command, since the C:\Program Files\WindowsApps directory is protected from normal access:

    Get-ChildItem -Recurse 'C:\Program Files\WindowsApps\' | Where-Object {$_.Name -eq 'install.tar.gz' }
    

    This is going to return a list of (most) distributions that you have installed from the Microsoft Store, along with the location. Copy the directory name to the clipboard. For instance, on my system, Debian is at:

    C:\Program Files\WindowsApps\TheDebianProject.DebianGNULinux_1.12.2.0_x64__76v4gfsz19hv4
    

    and Ubuntu 22.04 is at:

    C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu_2204.1.8.0_x64__79rhkp1fndgsc
    

    The location may differ slightly if you have a different release.

  2. Exit the Admin PowerShell and start a regular PowerShell.

  3. Create the directory where you want the virtual SDD for the new distribution. Using a variable name since we'll use it again in a future step:

    $newDistroDir = "D:\WSL\DebianTesting\"
    mkdir $newDistroDir
    
  4. Assign the directory you copied above to a variable (optional, but makes it clearer):

    $rootFSDirectory = "C:\Program Files\WindowsApps\TheDebianProject.DebianGNULinux_1.12.2.0_x64__76v4gfsz19hv4"
    
  5. Import the new distribution:

    wsl --import DebianTesting $newDistroDir ($rootFSDirectory+"\install.tar.gz")
    

    Replace DebianTesting with your desired name.

  6. Start the new distribution:

    wsl ~ -d DebianTesting
    
  7. Create your regular user. This is normally done by the WSL Distro installer, but with an import from a root FS tarball, it will need to be done manually. The exact groups for your user will vary from distro-to-distro, so check your "original" one. This answer includes an example for Ubuntu 20.04.

  8. Proceed to Set Default User for a Manually Installed WSL Distro

NotTheDr01ds
  • 28,025