How to add second WSL2 Ubuntu distro (fresh install)
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 hasamd64-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:
- Command Reference for Windows Subsystem for Linux
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.