Benefits:
- no need to install ubuntu from the store
- choose the version you want
- choose the name you want
- choose the location you want
- install multiple versions of ubuntu
wsl --install -d ubuntu
First, download the Ubuntu rootfs tarball from the Ubuntu Cloud Images website:
https://cloud-images.ubuntu.com/wsl/mantic/current/ubuntu-mantic-wsl-amd64-wsl.rootfs.tar.gz
Then import it into WSL2:
wsl --import <Distribution Name> <Installation Folder> <Ubuntu WSL2 Image Tarball path>
wsl --import ubuntu-2 D:\Workspaces\wsl\ubuntu2 D:\Workspaces\wsl\ubuntu-mantic-wsl-amd64-wsl.rootfs.tar.gz
Launch ubuntu-2
wsl -d ubuntu-2
Inside ubuntu-2
NEW_USER=dotexec
useradd -m -G sudo -s /bin/bash "$NEW_USER"
passwd "$NEW_USER"
tee /etc/wsl.conf <<_EOF
[user]
default=${NEW_USER}
_EOF
shutdown ubuntu-2 to apply the changes
wsl --shutdown ubuntu-2