1*59f4d655SAlexander Graf.. SPDX-License-Identifier: GPL-2.0-or-later 2*59f4d655SAlexander Graf 3*59f4d655SAlexander GrafVMApple machine emulation 4*59f4d655SAlexander Graf======================================================================================== 5*59f4d655SAlexander Graf 6*59f4d655SAlexander GrafVMApple is the device model that the macOS built-in hypervisor called "Virtualization.framework" 7*59f4d655SAlexander Grafexposes to Apple Silicon macOS guests. The "vmapple" machine model in QEMU implements the same 8*59f4d655SAlexander Grafdevice model, but does not use any code from Virtualization.Framework. 9*59f4d655SAlexander Graf 10*59f4d655SAlexander GrafPrerequisites 11*59f4d655SAlexander Graf------------- 12*59f4d655SAlexander Graf 13*59f4d655SAlexander GrafTo run the vmapple machine model, you need to 14*59f4d655SAlexander Graf 15*59f4d655SAlexander Graf * Run on Apple Silicon 16*59f4d655SAlexander Graf * Run on macOS 12.0 or above 17*59f4d655SAlexander Graf * Have an already installed copy of a Virtualization.Framework macOS 12 virtual 18*59f4d655SAlexander Graf machine. Note that newer versions than 12.x are currently NOT supported on 19*59f4d655SAlexander Graf the guest side. I will assume that you installed it using the 20*59f4d655SAlexander Graf `macosvm <https://github.com/s-u/macosvm>`__ CLI. 21*59f4d655SAlexander Graf 22*59f4d655SAlexander GrafFirst, we need to extract the UUID from the virtual machine that you installed. You can do this 23*59f4d655SAlexander Grafby running the shell script in contrib/vmapple/uuid.sh on the macosvm.json file. 24*59f4d655SAlexander Graf 25*59f4d655SAlexander Graf.. code-block:: bash 26*59f4d655SAlexander Graf :caption: uuid.sh script to extract the UUID from a macosvm.json file 27*59f4d655SAlexander Graf 28*59f4d655SAlexander Graf $ contrib/vmapple/uuid.sh "path/to/macosvm.json" 29*59f4d655SAlexander Graf 30*59f4d655SAlexander GrafNow we also need to trim the aux partition. It contains metadata that we can just discard: 31*59f4d655SAlexander Graf 32*59f4d655SAlexander Graf.. code-block:: bash 33*59f4d655SAlexander Graf :caption: Command to trim the aux file 34*59f4d655SAlexander Graf 35*59f4d655SAlexander Graf $ dd if="aux.img" of="aux.img.trimmed" bs=$(( 0x4000 )) skip=1 36*59f4d655SAlexander Graf 37*59f4d655SAlexander GrafHow to run 38*59f4d655SAlexander Graf---------- 39*59f4d655SAlexander Graf 40*59f4d655SAlexander GrafThen, we can launch QEMU with the Virtualization.Framework pre-boot environment and the readily 41*59f4d655SAlexander Grafinstalled target disk images. I recommend to port forward the VM's ssh and vnc ports to the host 42*59f4d655SAlexander Grafto get better interactive access into the target system: 43*59f4d655SAlexander Graf 44*59f4d655SAlexander Graf.. code-block:: bash 45*59f4d655SAlexander Graf :caption: Example execution command line 46*59f4d655SAlexander Graf 47*59f4d655SAlexander Graf $ UUID="$(contrib/vmapple/uuid.sh 'macosvm.json')" 48*59f4d655SAlexander Graf $ AVPBOOTER="/System/Library/Frameworks/Virtualization.framework/Resources/AVPBooter.vmapple2.bin" 49*59f4d655SAlexander Graf $ AUX="aux.img.trimmed" 50*59f4d655SAlexander Graf $ DISK="disk.img" 51*59f4d655SAlexander Graf $ qemu-system-aarch64 \ 52*59f4d655SAlexander Graf -serial mon:stdio \ 53*59f4d655SAlexander Graf -m 4G \ 54*59f4d655SAlexander Graf -accel hvf \ 55*59f4d655SAlexander Graf -M vmapple,uuid="$UUID" \ 56*59f4d655SAlexander Graf -bios "$AVPBOOTER" \ 57*59f4d655SAlexander Graf -drive file="$AUX",if=pflash,format=raw \ 58*59f4d655SAlexander Graf -drive file="$DISK",if=pflash,format=raw \ 59*59f4d655SAlexander Graf -drive file="$AUX",if=none,id=aux,format=raw \ 60*59f4d655SAlexander Graf -drive file="$DISK",if=none,id=root,format=raw \ 61*59f4d655SAlexander Graf -device vmapple-virtio-blk-pci,variant=aux,drive=aux \ 62*59f4d655SAlexander Graf -device vmapple-virtio-blk-pci,variant=root,drive=root \ 63*59f4d655SAlexander Graf -netdev user,id=net0,ipv6=off,hostfwd=tcp::2222-:22,hostfwd=tcp::5901-:5900 \ 64*59f4d655SAlexander Graf -device virtio-net-pci,netdev=net0 65*59f4d655SAlexander Graf 66