Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

macOS on VirtualBox on WSLg #525

Closed
myspaghetti opened this issue Aug 24, 2021 · 8 comments
Closed

macOS on VirtualBox on WSLg #525

myspaghetti opened this issue Aug 24, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request won't fix This will not be worked on

Comments

@myspaghetti
Copy link
Owner

Here's a sort-of tutorial for compiling the vboxdrv module for WSLg, adapted from the Darling guide and the Hanna J guide.

No support is offered for installing WSLg, compiling a kernel, or compiling and loading the vboxdrv module.

This process can and will break, since WSLg is still in beta. Without further ado:

  • Install Windows 11
  • Install WSLg, update WSLg, launch WSLg
  • On the WSLg command prompt, update the package repository: sudo apt update
  • Install the build dependencies: sudo apt install build-essential flex bison libssl-dev libelf-dev git -y
  • Clone the 5.10.y kernel branch: git clone --depth 1 --single-branch --branch linux-msft-wsl-5.10.y 'https://github.com/microsoft/WSL2-Linux-Kernel.git' linux-msft-wsl-5.10.y
  • cd linux-msft-wsl-5.10.y
  • cp Microsoft/config-wsl .config
  • sudo make -j $(expr $(nproc) - 1)
  • sudo make modules_install
  • sudo apt install virtualbox-source
  • tar -xf /usr/src/virtualbox.tar.bz2
  • cd modules/virtualbox/vboxdrv
  • sudo make -C ~/linux-msft-wsl-5.10.y/ M=${PWD}
  • sudo insmod vboxdrv.ko

Hooray, now you can run the script, version 0.99.1.0 or higher, and install macOS on VirtualBox on WSLg, super-slowly.

  • sudo apt install bash coreutils gzip unzip wget xxd dmg2img virtualbox -y
  • mkdir ~/macOS
  • cd ~/macOS
  • wget https://raw.githubusercontent.com/myspaghetti/macos-guest-virtualbox/master/macos-guest-virtualbox.sh
  • bash -i macos-guest-virtualbox.sh

Follow the script and you're done. Please mind that in my limited experience, there appears to be some disk I/O issue which slows the VirtualBox VM considerably, so booting macOS takes about ten minutes and installation takes many hours. If you're already compiling kernels and kernel modules, you might as well skip VirtualBox altogether and head directly to OSX-KVM on WSL2/WSLg which is a lot faster.

@myspaghetti myspaghetti added the enhancement New feature or request label Aug 24, 2021
@myspaghetti myspaghetti self-assigned this Aug 24, 2021
@IgnacioSanchezRamirez

This comment has been minimized.

@myspaghetti
Copy link
Owner Author

WSL2 uses Hyper-V which blocks VirtualBox from accessing VT-x/AMD-V. macOS guests on VirtualBox require VT-x/AMD-V. The script only works on WSL2/WSLg if you enable nested virtualization and load the vboxdrv kernel module. No support is offered for running the script on WSL2/WSLg.

@IgnacioSanchezRamirez

This comment has been minimized.

@myspaghetti myspaghetti added the won't fix This will not be worked on label Oct 7, 2021
@myspaghetti
Copy link
Owner Author

Right now I believe Oracle will not support VirtualBox on WSL2/WSLg, and I assume the extremely limited performance is here to stay, so the script isn't officially supported on WSL2/WSLg. I do heartily recommend QEMU/KVM as the performance on WSL2/WSLg is very good.

@jmaldon1
Copy link

jmaldon1 commented Nov 1, 2021

@myspaghetti Are there any tutorials online to get a mac virtual machine similiar to the one this script creates but on WSL2/WSLg? Or are we on our own?

@myspaghetti
Copy link
Owner Author

All the steps are here. When the WSLg kernel is updated you'll have to change the version number from 5.10.y to whichever you're running, but otherwise all the steps are stable. Regardless, VirtualBox is extremely slow on WSL2/WSLg so you'll save time going directly for OSX-KVM.

@tcab
Copy link

tcab commented Dec 6, 2021

VirtualBox has steadily improved over time. Version 6.1.3 runs OK under Hyper-V. For example, I am running Ubuntu in VirtualBox under WSLg in Windows 11. Does this fact improve the prospects of this project?

Unfortunately nested VT-x/AMD-V is still not supported - not sure if its just a matter of time or a technological limitation.

P.S. I looked at the OSX-KVM link and its a serious commitment to follow all those steps - we need a script for that!

@myspaghetti
Copy link
Owner Author

@tcab mind the difference between VirtualBox on Windows using NEM, and VirtualBox on a WSLg host.

To clear things up:

  • VirtualBox under a WSLg Linux host - VT-x/AMD-V available, macOS works (but very slowly)
  • VirtualBox under a Windows host when WSLg is enabled - VT-x/AMD-V not available, VirtualBox uses NEM, macOS doesn't work

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request won't fix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants