5

I have an existing Ubuntu distro, I want a 2nd one that is a fresh Ubuntu image.

I suspect I can:

  1. export my existing distribution to tar with wsl.exe --export
  2. unregister my existing distro with wsl unregister
  3. uninstall Ubuntu from Microsoft Store
  4. reinstall Ubuntu from Microsoft Store, giving me a fresh install
  5. import from tar via wsl --import

That should give me 2 distros, my existing plus one fresh. Is there an easier/better way?

This is for latest (as of writing) Windows 10 Build 19035

10

Important: The following procedure works only in Windows 10 Build 18305 or above. Please make sure wsl.exe has --import option in commandline. For older Windows 10 version, try this alternative method.

Procedure:

  • First we need the rootfs tarball from Ubuntu. Open https://cloud-images.ubuntu.com/releases/ in a web browser. Go to the folder with the required Ubuntu version.

  • Download the ubuntu-x.x-server-cloudimg-amd64-wsl.rootfs.tar.gz file (x.x used as version number). Make sure the file name has amd64-wsl and the file type is .tar.gz (GZIP tarball). As example, the direct link will be like this:

https://cloud-images.ubuntu.com/releases/eoan/release/ubuntu-19.10-server-cloudimg-amd64-wsl.rootfs.tar.gz
  • Now we are going to install it using wsl.exe in commandline. Open Command Prompt. The actual command format will be like this:
wsl.exe --import <Distribution Name> <Install Folder> <.TAR.GZ File Path>
  • Run the command twice to install Ubuntu with different distribution name. The folder name and distribution name must be different otherwise there will be error shown in output. Here are the two example:
wsl.exe --import DistroA FolderA ubuntu-x.x-server-cloudimg-amd64-wsl.rootfs.tar.gz
wsl.exe --import DistroB FolderB ubuntu-x.x-server-cloudimg-amd64-wsl.rootfs.tar.gz
  • The installed distributions can be executed like this wsl.exe -d DistroA.

Notes:

  • The procedure can be used with any GNU/Linux distribution user space.

  • This does not use Windows Store. So, Windows Store neither show the name nor update the installation.

  • In Windows 10 ARM64 (AArch64), use the arm64-wsl cloud image for Ubuntu.

  • In this procedure the installation folder can be accessed by other users in that same machine. If you are using a shared machine, use proper permissions.

  • If you are willing to share the installation with other users of same machine then just export this registry HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss. Then import it in other users of same machine.

Further Readings:

| improve this answer | |
  • This will not create the non-root user like the distro from the Windows Store does. See my answer for details on creating non-root user: superuser.com/a/1531220/714595 – pleasemorebacon Mar 8 at 15:40
  • "This will not create the non-root user" -- that depends on the user and it's not the topic of the question. – Biswapriyo Mar 8 at 15:41
  • Completely agree that it depends on the user, but if the goal is to have multiple distros similar to the one created by the Windows Store, I believe it is useful supplemental information. – pleasemorebacon Mar 8 at 15:45
9

Answer by Biswapriyo works great, but additional steps are required to change the default user. Note that this requires build 18980 and above.

Add the non-root user via adduser command:

PS C:\Users\Username> wsl -d DistroA
root@DESKTOP:/mnt/c/Users/Username# NEW_USER=username
root@DESKTOP:/mnt/c/Users/Username# adduser "${NEW_USER}"
Adding user `username' ...
Adding new group `username' (1000) ...
Adding new user `username' (1000) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
New password: ****
Retype new password: ****
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
        Full Name []: User Name
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n]

Enable sudoer privileges for ${NEW_USER}:

adduser ${NEW_USER} sudo

Add set the default user in /etc/wsl.conf:

tee /etc/wsl.conf <<_EOF
[user]
default=${NEW_USER}
_EOF

Exit WSL via logout, and then issue the WSL shutdown command for the changes to take effect:

wsl --shutdown DistroA

The next time wsl -d DistroA is invoked, the ${NEW_USER} user will be active.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.