microsoft / microsoft/WSL

Allow multiple instances of the utility VM to run simultaneously (WSL2)

Open
#13,096 4 comments 2 reactions 0 assignees View on GitHub
feature
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

**Is your feature request related to a problem? Please describe.**

1. Sometimes I want to run a WSL workload that requires a custom kernel.
I want that the rest of my workloads to run under the standard kernel distributed by Microsoft.
I want both those thing to happen concurrently.

2. I want to run a long-lasting workload (e.g. some server), or otherwise a workload that I very much prefer to run uninterrupted.
At the same time I want to run a bunch of less robust and trustworthy workloads (e.g. development, interactive, interacting with the custom kernel from the item above, etc.) that might crash WSL.
I want that the second kind of workloads crashing WSL won't interrupt the first kind of workloads.

**Describe the solution you'd like**

I'd like to be able to run simultaneously multiple instances of WSL2 - that is, multiple instance of the uVM - as the same Windows user.
It might look like an `--instance` parameter to `wsl.exe`:

```powershell
> wsl --instance foo -d kali-linux --exec whatever &
[... Job Id whatever]

> wsl --instance bar -d Debian --exec something_else &
[... Job Id whatever]

> wsl --instance foo --shutdown # terminates the foo uVM but the bar uVM keeps running

> wsl -d Ubuntu # interact with the default instance, which is unnamed or has some predefined name (e.g. "WSL2")
```

**Describe alternatives you've considered**

1. **Using standard Hyper-V VMs**
I lose all the fun WSL integrations. I could just use Linux VMs like we did before WSL existed. Who needs it anyway? Anyone who want to use everything WSL2 provides that regular VMs don't

2. **Create dedicated Windows users, one per uVM, and run multiple WSL2 instances in multiple Windows users** This has several problems:
1. It's messy. It requires setting up (and removing?) users all the time.
2. There are security difficulties - the other users might not have access to the host resources I want the guest to use. So in addition to creating users I have to adjusts DACLs all the time.
3. I may not be running as admin on the host, so I don't have permissions to create new users. WSL2 is nice in that the WSL service which runs with high privileges uses the HCS/HNS/... APIs, while the `wsl.exe` command asks it to create VMs for it, and doesn't have to run elevated. This ruins it.

**Additional context**

Contributor guide

Open the contributing guide

Research direction

Start at the wsl.exe entry point and trace how the requested instance name maps to the uVM lifecycle, including the HCS/HNS interactions described here. Done means separate named instances can run concurrently, support independent shutdown, and preserve the unnamed default instance behavior shown in the examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.