Home Blog CV Projects Patterns Notes Book Colophon Search

macOS qemu

17 Dec, 2024

NOTE: I haven't tested this for a while but I need to. I also plan to have a go at using Arch on macOS in a similar way.

Here's how I got qemu working on macOS to run a Debian desktop on my M1 mac. This is based on my following https://sleepymug.me/fragments/guide_mac_qemu.html:

Install QEMU:

brew install qemu

Create a disk:

qemu-img create -f qcow2 debian.img 20G
Formatting 'debian.img', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=21474836480 lazy_refcounts=off refcount_bits=16

Now we need to faff around with the UEFI firmware. First find the edk2-aarch64-code.fd file:

find /opt/homebrew -name 'edk2-aarch64-code.fd'
/opt/homebrew/Cellar/qemu/9.2.0/share/qemu/edk2-aarch64-code.fd

and copy it locally:

cp /opt/homebrew/Cellar/qemu/8.2.2/share/qemu/edk2-aarch64-code.fd ./

Now create a ovmf_vars.fd file:

% dd if=/dev/zero conv=sync bs=1m count=64 of=ovmf_vars.fd
64+0 records in
64+0 records out
67108864 bytes transferred in 0.039603 secs (1694539909 bytes/sec)

Installing Debian from the debian-12.8.0-arm64-netinst.iso net insatller:

qemu-system-aarch64 -M virt \
                      -accel hvf \
                      -smp 2 -m 8G -cpu host \
                      -boot d -cdrom ~/Downloads/debian-12.8.0-arm64-netinst.iso \
                      -drive "format=raw,file=edk2-aarch64-code.fd,if=pflash,readonly=on" \
                      -drive "format=raw,file=ovmf_vars.fd,if=pflash" \
                      -hda debian.img \   
                      -device e1000,netdev=usernet \
                      -netdev user,id=usernet,hostfwd=tcp:0.0.0.0:10000-:22 \
                      -nographic
UEFI firmware (version edk2-stable202408-prebuilt.qemu.org built at 16:28:50 on Sep 12 2024)
ArmTrngLib could not be correctly initialized.
Error: Image at 0023FDB6000 start failed: 00000001
Error: Image at 0023FD6D000 start failed: Not Found
Error: Image at 0023FCBA000 start failed: Unsupported
Error: Image at 0023FC3F000 start failed: Not Found
Error: Image at 0023FB65000 start failed: Aborted
Tpm2SubmitCommand - Tcg2 - Not Found
Tpm2GetCapabilityPcrs fail!
Tpm2SubmitCommand - Tcg2 - Not Found
Image type X64 can't be loaded on AARCH64 UEFI system.
...

Then run the installer as usual.

Tips:

You can use Ctrl-a c to get to the QEMU shell and type exit to get out:

QEMU 8.2.2 monitor - type 'help' for more information
(qemu) exit

You might to run reset afterwards.

Once installation is complete you can make a backup if you like:

cp -pr debian.img debian.img.orig

And time to run it:

qemu-system-aarch64 -M virt \
                      -accel hvf \
                      -smp 2 -m 8G -cpu host \
                      -drive "format=raw,file=edk2-aarch64-code.fd,if=pflash,readonly=on" \
                      -drive "format=raw,file=ovmf_vars.fd,if=pflash" \
                      -hda debian.img \
                      -device e1000,netdev=usernet \
                      -netdev user,id=usernet,hostfwd=tcp:0.0.0.0:10000-:22 \
                      -nographic

Port forwarding like this:

ssh -p 10000 myuser@localhost

To have a desktop environment remove -nographic and add:

                    -device virtio-gpu-pci -display cocoa,zoom-to-fit=on \
                    -device usb-ehci \
                    -device usb-kbd \
                    -device usb-tablet  

Then you can do the usual things like install a desktop environment:

apt update
apt install -y task-lxde-desktop

You can also use -smp cpus=8 but is that the same as -cpu host?

Comments

Be the first to comment.

Add Comment





Copyright James Gardner 1996-2020 All Rights Reserved. Admin.