Virtualization inside the OSX VM #313

Open
opened 2025-12-29 00:24:04 +01:00 by adam · 8 comments
Owner

Originally created by @saied89 on GitHub (Jan 26, 2022).

I can't run android emulator inside the vm with android studio complaining that "Your CPU does not support VT-x"
I think it might be due to the virtual cpu that is set.
When I run sysctl -n machdep.cpu.brand_string from here it reports a core 2 Dou Penryn which surely doesn't support VT-x.
Is is possible to set a more up to date virtual cpu for the vm?

Originally created by @saied89 on GitHub (Jan 26, 2022). I can't run android emulator inside the vm with android studio complaining that "Your CPU does not support VT-x" I think it might be due to the virtual cpu that is set. When I run `sysctl -n machdep.cpu.brand_string` from [here](https://osxdaily.com/2011/07/15/get-cpu-info-via-command-line-in-mac-os-x/) it reports a core 2 Dou Penryn which surely doesn't support VT-x. Is is possible to set a more up to date virtual cpu for the vm?
Author
Owner

@sickcodes commented on GitHub (Jan 27, 2022):

I think we need to try qemu-system-x86_64 -M accel=hvf --cpu host or something

Does the iPhone simulator work?

@sickcodes commented on GitHub (Jan 27, 2022): I think we need to try `qemu-system-x86_64 -M accel=hvf --cpu host` or something Does the iPhone simulator work?
Author
Owner

@saied89 commented on GitHub (Jan 27, 2022):

yes the iPhone simulator works

@saied89 commented on GitHub (Jan 27, 2022): yes the iPhone simulator works
Author
Owner

@saied89 commented on GitHub (Jan 30, 2022):

If we add these and build a new docker image, can it handle an existing mac disk image or do we need to create a new one from scratch?

@saied89 commented on GitHub (Jan 30, 2022): If we add these and build a new docker image, can it handle an existing mac disk image or do we need to create a new one from scratch?
Author
Owner

@sickcodes commented on GitHub (Feb 8, 2022):

You can always use existing images, in fact, you can change serial numbers on an existing machine.

@sickcodes commented on GitHub (Feb 8, 2022): You can always use existing images, in fact, you can change serial numbers on an existing machine.
Author
Owner

@arsinclair commented on GitHub (Mar 3, 2022):

I need to install and run docker inside of an running OSX image. When I start docker, it reports that the hardware is incompatible with Docker Desktop, a problem which I think is kinda similar to the one in question.

Is there anything that can be done in order to make it work?

sysctl kern.hv_support reports 0.

@arsinclair commented on GitHub (Mar 3, 2022): I need to install and run docker inside of an running OSX image. When I start docker, it reports that `the hardware is incompatible with Docker Desktop`, a problem which I think is kinda similar to the one in question. Is there anything that can be done in order to make it work? `sysctl kern.hv_support` reports `0`.
Author
Owner

@julianxhokaxhiu commented on GitHub (Dec 9, 2022):

I just landed on the same issue as we speak. I'm currently running this stack on top of WSL, everything works fine, but when trying to run Lima the Qemu machine inside refuses to work. Is there a way I can workaround this even without waiting for an offical patch to come up?

//EDIT: Regarding the how I found we can pass an EXTRA env var to the container, now I need to figure out which is the right set of flags to pass to enable the nested virtualization.

//EDIT2: I see the image by default assigns the kvm:tcg accelerators via the KVM env var. Maybe enabling hvf is enough? Although on my own Arch system when I install qemu and run the help command this is the output I get:

$ qemu-system-x86_64 -accel help
Accelerators supported in QEMU binary:
tcg
kvm

Is hvf supported on the binary provided in this container?

//EDIT3: Ok scratch that, hvf is supposed to be used on Apple Host machines. So what is missing to correctly allow nested virtualization inside macOS itself? 🤔

//EDIT4: I was successfully able to get nested virtualization by simply passing these two ENV vars to the container!

-e "CPU=max" \
-e "BOOT_ARGS=+vmx" \

Tested on an Intel i7-8550U machine that runs Arch with KDE/Wayland and it works 🎉 sysctl kern.hv_support now returns 1 and lima VMs can be successfully started.

I'll test it later on WSL on Win11 which runs on an AMD Ryzen 7 5800H.

@julianxhokaxhiu commented on GitHub (Dec 9, 2022): I just landed on the same issue as we speak. I'm currently running this stack on top of WSL, everything works fine, but when trying to run Lima the Qemu machine inside refuses to work. Is there a way I can workaround this even without waiting for an offical patch to come up? //EDIT: Regarding the how I found [we can pass an `EXTRA` env var](https://github.com/sickcodes/Docker-OSX/blob/master/Dockerfile#L148) to the container, now I need to figure out which is the right set of flags to pass to enable the nested virtualization. //EDIT2: I see the image by default assigns the `kvm:tcg` accelerators via the [KVM env var](https://github.com/sickcodes/Docker-OSX/blob/master/Dockerfile#L316). Maybe enabling `hvf` is enough? Although on my own Arch system when I install qemu and run the help command this is the output I get: ```bash $ qemu-system-x86_64 -accel help Accelerators supported in QEMU binary: tcg kvm ``` Is `hvf` supported on the binary provided in this container? //EDIT3: Ok scratch that, `hvf` is supposed to be used on Apple Host machines. So what is missing to correctly allow nested virtualization inside macOS itself? 🤔 //EDIT4: I was successfully able to get nested virtualization by simply passing these two ENV vars to the container! ```bash -e "CPU=max" \ -e "BOOT_ARGS=+vmx" \ ``` Tested on an Intel i7-8550U machine that runs Arch with KDE/Wayland and it works 🎉 `sysctl kern.hv_support` now returns `1` and lima VMs can be successfully started. I'll test it later on WSL on Win11 which runs on an AMD Ryzen 7 5800H.
Author
Owner

@sickcodes commented on GitHub (Dec 11, 2022):

That's awesome thank you. Do you want to submit a PR to update the docs? I can otherwise

@sickcodes commented on GitHub (Dec 11, 2022): That's awesome thank you. Do you want to submit a PR to update the docs? I can otherwise
Author
Owner

@julianxhokaxhiu commented on GitHub (Dec 11, 2022):

You're welcome :) Feel free as I'd have no idea where to put it at the moment. Thanks for all the great work you've put around this project!

Oh forgot to mention that unfortunately this method does NOT work on AMD CPUs as QEmu needs to pass the CPU capabilities 1:1 and VMX is not a supported extension on AMD CPUs. This is why this method works only on Intel CPUs.

I did try to do a bit of research regarding emulating this extension on AMD CPUs but unfortunately I wasn't able to find anything useful. In case you do please let me know!

@julianxhokaxhiu commented on GitHub (Dec 11, 2022): You're welcome :) Feel free as I'd have no idea where to put it at the moment. Thanks for all the great work you've put around this project! Oh forgot to mention that unfortunately this method does NOT work on AMD CPUs as QEmu needs to pass the CPU capabilities 1:1 and VMX is not a supported extension on AMD CPUs. This is why this method works only on Intel CPUs. I did try to do a bit of research regarding emulating this extension on AMD CPUs but unfortunately I wasn't able to find anything useful. In case you do please let me know!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Docker-OSX#313