> For the complete documentation index, see [llms.txt](https://harsha-vallamkonda.gitbook.io/harshavallamkonda/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://harsha-vallamkonda.gitbook.io/harshavallamkonda/ultimate-guide-running-multiple-ubuntu-vms-on-wsl-like-a-pro.md).

# 🚀 Ultimate Guide: Running Multiple Ubuntu VMs on WSL Like a Pro!

### 🛠️ Install WSL & Ubuntu

First, let's get WSL up and running with Ubuntu:

```sh
wsl --install
wsl --set-default-version 2
wsl --install -d Ubuntu
```

👉 **This installs WSL and sets it to version 2 by default.**

***

### ✅ Move WSL & Ubuntu to D Drive

By default, WSL installs everything in `C:\`, which isn’t ideal. Let’s \**move it to D:\** for better organization:

```sh
wsl --export Ubuntu D:\Linux\ubuntu.tar
wsl --unregister Ubuntu
wsl --import Ubuntu D:\Linux\Ubuntu D:\Linux\ubuntu.tar --version 2
```

🚀 Now, Ubuntu is installed in `D:\Linux\Ubuntu` instead of `C:\`.

***

### 📌 Create Multiple VMs (Ubuntu Clones)

We need multiple Ubuntu instances for Kubernetes, DevOps, or just messing around. Let's create three VMs:

```sh
wsl --import Ubuntu-Node1 D:\Linux_Node1 D:\Linux\ubuntu.tar --version 2
wsl --import Ubuntu-Node2 D:\Linux_Node2 D:\Linux\ubuntu.tar --version 2
wsl --import Ubuntu-Node3 D:\Linux_Node3 D:\Linux\ubuntu.tar --version 2
```

✅ **Boom! You now have three Ubuntu instances.**

***

### 🔹 Set Up Users for Each VM

Each VM needs its own user. Let's set them up:

#### **For Node1:**

```sh
wsl -d Ubuntu-Node1
sudo adduser vm1user
sudo usermod -aG sudo vm1user
su - vm1user
exit
wsl -d Ubuntu-Node1 -u vm1user
```

#### **For Node2:**

```sh
wsl -d Ubuntu-Node2
sudo adduser vm2user
sudo usermod -aG sudo vm2user
su - vm2user
exit
wsl -d Ubuntu-Node2 -u vm2user
```

#### **For Node3:**

```sh
wsl -d Ubuntu-Node3
sudo adduser vm3user
sudo usermod -aG sudo vm3user
su - vm3user
exit
wsl -d Ubuntu-Node3 -u vm3user
```

👉 **Now, each VM has its own unique user!**

***

### 🔧 Fix Home Directory Issues

By default, WSL might not open in the home directory. Fix it with:

```sh
echo "cd ~" >> ~/.bashrc && source ~/.bashrc
```

💡 **Now, every time you open a VM, it will start in the correct home directory.**

***

### 🔍 Manage & Verify Your VMs

Check all installed WSL distributions:

```sh
wsl --list --verbose
```

Terminate a running VM:

```sh
wsl --terminate Ubuntu-Node1
```

Completely remove a VM:

```sh
wsl --unregister Ubuntu-Node1
```

👉 **Use these commands to manage your Ubuntu instances.**

***

### 🎨 Fix Missing Icon Error (For Windows Terminal)

If your Ubuntu instances don’t show icons in Windows Terminal, do this:

1. Open Windows Terminal JSON settings (**Ctrl + Shift + ,** in Windows Terminal)
2. Find the profile for your WSL instance and add:

```json
"icon": "C:\\Windows\\System32\\shell32.dll"
```

✅ **Now, your terminal will show a proper icon!**

***

### 🔥 Bonus: Open WSL VMs with a Simple Command

Instead of typing `wsl -d vm1` every time, let's make it easier!

👉 **For PowerShell**

```powershell
Set-Content -Path $PROFILE -Value "`nfunction vm1 { wsl -d Ubuntu-Node1 }" -Append
```

Now, just type `vm1` to open **Ubuntu-Node1**! 🚀

👉 **For CMD (Batch File Approach)**

1. Create a file named `vm1.bat` in `C:\Windows\System32`.
2. Add this line inside it:

   ```bat
   @echo off
   wsl -d Ubuntu-Node1
   ```

Now, just type `vm1` in CMD to open it instantly! 🔥

***

### 🎯 Conclusion

BoomBam! You now have: ✅ WSL installed on **D drive** ✅ Multiple **Ubuntu VMs** for Kubernetes, DevOps, or testing ✅ Fixed **sudo & home directory issues** ✅ Set up **easy VM launching commands** ✅ Fixed the **missing icon error**
