Skip to content

Instantly share code, notes, and snippets.

@aruruka
Created March 10, 2023 04:45
Show Gist options
  • Save aruruka/2db1083f3713f202528564fecb0ed72c to your computer and use it in GitHub Desktop.
Save aruruka/2db1083f3713f202528564fecb0ed72c to your computer and use it in GitHub Desktop.
Create additional Ubuntu instance of WSL2

Create additional Ubuntu instance of WSL2

Obtain a tar file for the distribution

Prerequisite:

Run below command in your current WSL Linux distro has enabled integration with Docker:

  1. Download the official Ubuntu image:

    sudo -E docker pull ubuntu
  2. Run the Ubuntu container inside Docker:

    sudo -E docker run --name ubuntu-test -it ubuntu
  3. Grab the Ubuntu container ID using grep and awk:

    # Open another tab of terminal and run:
    dockerContainerID=$(sudo -E docker container ls -a | grep -i ubuntu | awk '{print $1}')
  4. Export the container ID to a tar file on your mounted d-drive:

    sudo -E docker export $dockerContainerID > /mnt/d/tmp/ubuntu.tar

Import the tar file into WSL

Once you have a tar file ready, you can import it using the command: wsl --import <Distro> <InstallLocation> <FileName>.

Importing Ubuntu example

To import the Ubuntu distribution tar file into WSL:

  1. Open PowerShell and ensure that you have a folder created where you'd like the distribution to be stored.

    cd D:\tmp
    mkdir D:\wslDistroStorage\Ubuntu
  2. Use the command wsl --import <DistroName> <InstallLocation> <InstallTarFile> to import the tar file.

    wsl --import Ubuntu-Test D:\wslDistroStorage\Ubuntu .\ubuntu.tar
  3. Use the command wsl -l -v to check which distributions you have installed.

Wsl-Import-Combined

  1. Finally, use the command wsl -d Ubuntu-Test to run your newly imported Ubuntu Linux distribution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment