crc-org / vfkit

Apache License 2.0
130 stars 25 forks source link

Running macOS guests #139

Closed williamtheaker closed 1 month ago

williamtheaker commented 4 months ago

It looks like the most common use of vfkit is running GNU/Linux guests, but of course the Virtualization framework also supports running macOS guests and vz can download and run macOS guests from .ipsw files. Is it possible to run a macOS guest using vfkit (ideally from a .ipsw)?

gbraad commented 4 months ago

It is not a use case we (dependent applications; Podman Machine, CRC) have, but nothing that prevents this.

williamtheaker commented 4 months ago

I found this project via Podman actually! Have you been able to run macOS guests with vfkit? I've tried using .img files built by UTM and the last AGPLv3 build of Tart (0.38.0), but neither seem to actually boot despite vz not throwing an error. It's the same behavior as using an empty disk image.

vfkit \
    --cpus 2 --memory 2048 \
    --bootloader efi,variable-store=efi-variable-store,create \
    --device virtio-blk,path=/Users/foo/.tart/vms/sonoma001/disk.img --device virtio-input,keyboard --device virtio-input,pointing --device virtio-gpu,width=1920,height=1080 --gui
INFO[0000] &{2 2048    {[efi variable-store=efi-variable-store create] true}  [virtio-blk,path=/Users/foo/.tart/vms/sonoma001/disk.img virtio-input,keyboard virtio-input,pointing virtio-gpu,width=1920,height=1080] none://  true}
INFO[0000] boot parameters: &{EFIVariableStorePath:efi-variable-store CreateVariableStore:true}
INFO[0000]
INFO[0000] virtual machine parameters:
INFO[0000]  vCPUs: 2
INFO[0000]  memory: 2048 MiB
INFO[0000]
INFO[0000] Adding virtio-blk device (imagePath: /Users/foo/.tart/vms/sonoma001/disk.img)
INFO[0000] Adding virtio-input keyboard device
INFO[0000] Adding virtio-input pointing device
INFO[0000] Adding virtio-gpu device
INFO[0000] virtual machine is running
INFO[0000] waiting for VM to stop
INFO[0000] VM is stopped

^ running vfkit version: 0.5.1

I can get a code signing cert to compile vz with the required entitlements and test building an image with it, but wanted to make sure I'm not doing something obviously wrong first.

williamtheaker commented 4 months ago

It looks like this might not work even when supplying an image that works with other tools because vfkit hasn't implemented VZMacPlatformConfiguration or VZMacOSBootLoader.

If you compare the vz examples for macOS and Linux, you can see the Linux VM uses slightly different calls, like VZGenericPlatformConfiguration.

I could be wrong about all this though 😅

cfergeau commented 4 months ago

It looks like this might not work even when supplying an image that works with other tools because vfkit hasn't implemented VZMacPlatformConfiguration or VZMacOSBootLoader.

If you compare the vz examples for macOS and Linux, you can see the Linux VM uses slightly different calls, like VZGenericPlatformConfiguration.

I could be wrong about all this though 😅

Yes, a few things are missing in vfkit to run macOS guests, including the ones you mention (haven't checked if there are more :) This would be a nice addition to vfkit, but not something I'm planning to work on soon.

If you want to try to implement this, I'd be happy to help with guidance/suggestions/... if needed.

cfergeau commented 4 months ago

A few thoughts about this (which might be wrong ;)

cfergeau commented 4 months ago

you can see the Linux VM uses slightly different calls, like VZGenericPlatformConfiguration.

vfkit does not make use of this, I don't know if it should..

williamtheaker commented 4 months ago

Thank you for the suggestions on how to get started. I'll open up a draft pull request when I have something worth sharing.

williamtheaker commented 4 months ago

you can see the Linux VM uses slightly different calls, like VZGenericPlatformConfiguration.

vfkit does not make use of this, I don't know if it should..

Implementing VZGenericPlatformConfiguration would require dropping macOS 11 support.