Multiple same OS (Ubuntu 22.04) with WSL2 on Windows 11

This is a memo when I prepared an environment to use multiple same OS (Ubuntu 22.04) with WSL2 on Windows 11, referring to other web pages. The procedure is based on Windows 11 WSL2 with one Ubuntu 22.04 already installed.

1. Start Power Shell with administrator privileges and execute the following command.

PS C:\Users\username> wsl -l --verbose
  NAME                   STATE           VERSION
* Ubuntu                 Running         2

2. Execute the following command to export the OS environment (Ubuntu).

PS C:\Users\username> wsl --export Ubuntu Ubuntu-22.04.4.Copy.tar

3. Run the following command to import the exported OS environment with the name Ubuntu-22.04.4.Copy.

PS C:\Users\username> wsl --import Ubuntu-22.04.4.Copy Ubuntu-22.04.4.Copy Ubuntu-22.04.4.Copy.tar

4. Execute the command in step 1. again, and it will show the following output.

PS C:\Users\username> wsl -l --verbose
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  Ubuntu-22.04.4.Copy    Stopped         2

5. I confirmed that I can log in to the imported OS environment (Ubuntu-22.04.4.Copy) with the specified user name using the following command.

PS C:\Users\username> wsl -d Ubuntu-22.04.4.Copy -u username

6. Sets the default login user name in the OS environment (Ubuntu-22.04.4.Copy) for the next time the imported OS environment (Ubuntu-22.04.4.Copy) is launched. Add the following highlighted line to /etc/wsl.conf using a vi editor, etc. In the example below, the user name is username.

username@ESPRIMOWD2H2:~$ cat /etc/wsl.conf

[boot]
systemd=true

[user]
default=username

7. I confirmed that the imported OS environment includes directories, files, etc. created in the exported environment as shown in the example below.

fukagai@ESPRIMOWD2H2:~$ ls /repos/
images  yolov9
fukagai@ESPRIMOWD2H2:~$ sudo docker ps -a
[sudo] password for fukagai:
CONTAINER ID   IMAGE                              COMMAND                  CREATED        STATUS                    PORTS     NAMES
0c38c2a0b984   nvcr.io/nvidia/pytorch:21.11-py3   "/opt/nvidia/nvidia_…"   14 hours ago   Exited (0) 14 hours ago             yolov9-gpu

8. The following command removes the OS environment (Ubuntu).

PS C:\Users\username> wsl --unregister Ubuntu

9. Memo

I wanted to reconfirm the procedure for setting up Docker to use NVIDIA’s GPGPU in an Ubuntu 22.04 environment, so I checked the procedure for running multiple operating systems of the same version on WSL2.

I confirmed that steps 1. through 7. allow us to back up the original OS environment.

The original Ubuntu 22.04 environment was removed in step 8. and Ubuntu 22.04 was reinstalled on WSL2 with the following command. The installed Ubuntu 22.04 is confirmed to be the environment immediately after installing Ubuntu 22.04, as shown in the example command below.

PS C:\Users\username> wsl --install
Ubuntu is already installed.
Ubuntu is running...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: fukagai
New password:
Retype new password:
passwd: password updated successfully
This operation was completed correctly.
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.146.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


This message is shown once a day. To disable it please create the
/home/fukagai/.hushlogin file.
fukagai@ESPRIMOWD2H2:~$ ls
fukagai@ESPRIMOWD2H2:~$ sudo docker ps -a
[sudo] password for fukagai:
sudo: docker: command not found
fukagai@ESPRIMOWD2H2:~$ history
    1  ls
    2  sudo docker ps -a
    3  history
fukagai@ESPRIMOWD2H2:~$ cat /etc/issue
Ubuntu 22.04.3 LTS \n \l

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA