WSL2 not working within Windows 10 VM in VirtualBox on Ubuntu 18.04.5 LTS

7,535

Solution 1

After 3 work days of messing with this, the only solution I have found: use VMWare Workstation 16. I downloaded the Windows 10 VMware VM from Microsoft, verified the Ubuntu distribution was using WSL2 with 'wsl -l -v', then launched the Ubuntu distribution successfully on first try.

I duplicated the exact Virtualbox error posted with the following:

Host: P53; BIOS: Virtualization is enabled; OS: Ubuntu 20.04 LTS; Hypervisor: Oracle VirtualBox 6.1.16_Ubuntu r140961 (Qt5 12.8); VM: Windows 10, version 2004 (10.0.19041.0); VM Settings Enabled: System->Processor-> Enable Nested VT-x/AMD-V (same results if you also Enable PAE/NX); Windows Settings -> Optional Features -> More; Windows Features Checked: Virtual Machine Platform; Windows Subsystem for Linux

I also duplicate a similar issue when using VM: VirtualBox VM downloaded here: https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/

I kept all of the VM settings Microsoft defaulted for their WSL2 Ubunutu dist to run. When I open the Ubuntu dist I get an error saying I need to enable "Virtual Machine Platform" and or enable virtualization in bios. Clearly these were enabled.

I tried uninstalling and reinstalling multiple times. I have concluded the virtualization feature needed for HyperV virtualizaiton to work in a VM, which is leveraged by WSL2, does not work on Virtualbox version 6.1 on Ubuntu 20.04, despite any claims VirtualBox has made about the feature listed on version 6.1.

Please see here: https://forums.virtualbox.org/viewtopic.php?f=6&t=98448 "Microsoft makes its OS's a moving target now, so the devs have to catch up." If the Virtualbox 6.1 virtualization feature ever worked when installed on Ubuntu, it doesn't now.

A final note, I needed this solution to work for the same reason as the poster. I am testing a powershell script I am writing that will install all of the needed software to run our local development environment. The local env includes an installation of minikube which uses the default docker driver, which on Windows is experimental but works with the workaround posted in the minikube documentation (I wish my teammates would use Ubuntu like I do). When testing the install script, its much easier to snap and restore between test runs on a VM then it is to on bare-metal.

Solution 2

Same failure trying with KVM/QEMU and nested virtualisation. WSL2 does not want to start, after installing the W10 Guest is stuck at restart with "Preparing to repair..." I guess Hyper-V does not like to be run within another hypervisor!

Share:
7,535

Related videos on Youtube

eaglet3d
Author by

eaglet3d

Updated on September 18, 2022

Comments

  • eaglet3d
    eaglet3d almost 2 years

    WSL2 isn't working for me. Virtualization is enabled in Laptop BIOS AND within VirtualBox VM settings. Here is my configuration.

    • Host: Alienware17r3, Intel i7, 32GB RAM
    • BIOS: Virtualization is enabled
    • OS: Ubuntu 18.04.5 LTS
    • Hypervisor: Oracle VirtualBox 6.12r139181(Qt5.9.5)
    • VM: Windows 10 Home 20H2 (19042.450)
    • VM Settings Enabled: System->Processor-> Enable PAE/NX Enable Nested VT-x/AMD-V
    • Windows Settings -> Optional Features -> More
    • Windows Features: Checked
      • Virtual Machine Platform
      • Windows Hypervisor Platform
      • Windows Subsystem for Linux

    Finally tried to launch Ubuntu 20.04 LTS within wsl2:

    WslRegisterDistribution failed with error: 0x80370102
    Error: 0x80370102 The virtual machine could not be 
    started because a required feature is not installed.
    
    Press any key to continue...
    

    I've tried many times to experiment with docker running in WSL2 on Windows after every Windows update. Virtualization is enabled in the bios and the OracleBox Windows10 VM. However, something is still preventing me from using WSL2 within a licensed Windows OS which is running in a VirtualBox VM on Linux.

    • Nmath
      Nmath over 3 years
      Why are you trying to run WSL inside a Windows VM with the host system running Ubuntu? What exactly is it that you want to achieve? Is there some reason you need a "russian nesting doll" situation? Why can't you just run another VM on the host OS (Ubuntu).
    • eaglet3d
      eaglet3d over 3 years
      I need to ensure that docker and docker-compose based microservices work within a Windows 10 environment as one of the local build/test/dev environments for my teammates. However, I have Ubuntu 18.04 running on my laptop. Hence, need to run Windows 10 within a VM and get wsl2 running with docker embedded. I don't want to buy a separate computer when my Ubuntu laptop has 32GB, and an i7 with 8 threads.
    • Nmath
      Nmath over 3 years
      Your scenario is not a reliable way to test this. Also, WSL is not intended to run services. You should not use WSL to run services: docs.microsoft.com/en-us/windows/wsl/… You don't need WSL for docker. WSL is an inappropriate tool for the job.
    • eaglet3d
      eaglet3d over 3 years
      According to Microsoft's "WSL 2 FAQs" ( ref: Can I run WSL 2 in a Virtual Machine? "Yes! You need to make sure that the virtual machine has nested virtualization enabled."
    • eaglet3d
      eaglet3d over 3 years
      I have confirmed that virtualization is enabled within the Windows VM: Task Manager -> Performance -> CPU: Virtualization = Yes. WSL 2 is different than WSL. WSL 2 adds docker which runs "services". As a test environment, having a Linux box run a Windows VM could be a most effective test environment for building and testing local microservice test/dev deployments using docker.
    • Nmath
      Nmath over 3 years
      The FAQ I linked from Microsoft was updated in September. It states: "even though you will be able to run many popular server applications (e.g. Redis), we do not recommend WSL for hosting production services – Microsoft offers a variety of solutions for running production Linux workloads in Azure, Hyper-V, and Docker.". If you read further into the technical documentation there's a better explanation for why you should not use WSL for services. Isn't an important qualification of a test environment that it should be the same as production?
    • eaglet3d
      eaglet3d over 3 years
      I don't understand your reasoning. I am trying to use WSL2 as advertised from Microsoft and Docker (ref: "Could you describe a typical development workflow that incorporates WSL?" and "Docker Desktop WSL 2 backend" ). I never said that this was to be run "in Production" so why do you keep harping on it? This is to test a test/dev environment deployment for actual test/dev environments.
    • Christian Stewart
      Christian Stewart over 3 years
      @eaglet3d it makes total sense to run WSL2 in a VM to test things out , especially if you are trying to develop a WSL 2 distribution. The person replying to you is on another planet.
    • Dylan Kerler
      Dylan Kerler over 3 years
      @eaglet3d Did you manage to find a solution to this? I'm currently experiencing the same problem Ubuntu -> Virtual Box (Windows) -> Docker. But docker keeps failing to start due to wsl2 errors.