← Back to Blog

πŸš€ How to Run WSL Inside a Hyper-V Virtual Machine

πŸš€ How to Run WSL Inside a Hyper-V Virtual Machine Error ^^^ πŸ’‘ Want to run Windows Subsystem for Linux (WSL) inside a Hyper-V virtual machine? Here's a step-by-step guide to help you enable the necessary features on both the host machine and inside the Hyper-V VM.

πŸš€ How to Run WSL Inside a Hyper-V Virtual Machine

Error ^^^

πŸ’‘ Want to run Windows Subsystem for Linux (WSL) inside a Hyper-V virtual machine? You're in the right place! Here's a step-by-step guide to help you enable the necessary features on both the host machine and inside the Hyper-V VM.

🌐 On the Host Machine:

1. Enable Hyper-V (if not already enabled)

You need Hyper-V enabled on your host to set up nested virtualization. Open PowerShell as Administrator and run:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

⏸ Pause: Restart your computer when prompted.

2. Enable Windows Subsystem for Linux (WSL)

Next, let’s install WSL 2 on your host. In PowerShell as Administrator, run:

wsl --install

This command installs WSL 2 and ensures that the Virtual Machine Platform is set up.

3. Enable Virtualization in BIOS

Make sure virtualization (Intel VT-x or AMD-V) is enabled in your BIOS. Without this, nested virtualization won’t work!


πŸ–₯️ Inside the Hyper-V VM:

1. Enable Nested Virtualization

Nested virtualization allows you to run virtual environments inside a Hyper-V VM. On the host machine, run the following command in PowerShell:

Set-VMProcessor -VMName -ExposeVirtualizationExtensions $true

Replace <VMName> with the name of your virtual machine.

2. Enable WSL & Required Features in the VM

Once inside your VM, enable WSL and the necessary virtualization features. Open PowerShell as Administrator and run these commands:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

⏸ Pause: Restart the VM to apply these changes.

3. Install WSL 2

Now, let’s install WSL inside the VM:

wsl --install

4. Install a Linux Distribution

Finally, install your preferred Linux distribution from the Microsoft Store or using PowerShell. For example, to install Ubuntu:

wsl --install -d Ubuntu


πŸŽ‰ You're all set! You should now be able to run WSL inside your Hyper-V virtual machine.


πŸ“Έ Add a screenshot: At this point, you can take a screenshot of your terminal or the installed WSL environment for reference.


πŸ”— Connect with me:


Feel free to share your experience, ask questions, or drop a comment below!


Imported from rifaterdemsahin.com Β· 2024