Qemu for x86-64 and ARM Emulation
Qemu provides the ability to emulate a CPU so you can run code built for a different CPU architecture than what you actually have. For example, if you have an Apple Silicon M1 CPU and you want to run code compiled for the AMD x86-64 CPU, you can emulate an x86-64 CPU to run the application.
To get started, install Qemu (on MacOS: brew install qemu
) create a disk image to use as the primary storage for your virtual machine:
qemu-image create -f qcow2 mydisk.qcow2 20G
Then, start up the “virtual machine” specifying the resources to allocate and the ISO image to boot up using the command:
qemu-system-x86_64 -hda mydisk.qcow2 -smp 2 -m 4G -cdrom somelinux-amd64.iso -usb -device usb-keybd -device usb-mouse -device usb-tablet -display virtio,show-curson=on
This starts the emulator with 2 CPUs, 4GB RAM, the ISO image mounted in the virtual CD rom, and with a virtual keyboard and mouse attached to the VM.
Note: Use -daemonize to run qemu in the background
To emulate ARM64, we use qemu-system-aarch64 instead of qemu-system-x86_64 but we also have to provide a BIOS image for the virtual machine to start:
qemu-system-aarch64 -hda mydisk.qcow2 -smp 2 -m 4G -cdrom somelinux-aarch64.iso -machine virt -cpu max -bios /opt/homebrew/Cellar/qemu/7.2.0/share/qemu/edk2-aarch64-code.fd -accel hvf -device virtio-gpu-pci -device qemu-xhci -device usb-kbd -device usb-mouse -display default,show-cursor=on -device usb-tablet
When I attempted to start an ARM64 emulated machine, I also had to specify the “qemu-xhci” device to get the mouse and keyboard working.
The machines I have been running with were quite stable, but I wouldn’t recommend these for production workloads because emulated CPUs are slow-ish.
Also see: The “-vnc :0” parameter can make the display available remotely.