Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bunam/ee03c7f62a874e312b654d9e33c20d4b to your computer and use it in GitHub Desktop.
Save bunam/ee03c7f62a874e312b654d9e33c20d4b to your computer and use it in GitHub Desktop.
Create Virtual Machines using QEMU on Silicon based Apple Macs

Install QEMU on Silicon based Apple Macs (June 2021)

Option 1 - Automatically

zsh -c "$(curl -fsSL https://raw.githubusercontent.com/nrjdalal/silicon-virtualizer/master/install-qemu.sh)"

Option 2 - Manually

  • Install Xcode command line tools

xcode-select --install
  • Install Homebrew arm64

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/$(logname)/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
  • Install necessary packages for building

brew install libffi gettext glib pkg-config autoconf automake pixman ninja
  • Clone qemu

git clone https://github.com/qemu/qemu
  • Change directory to qemu repository

cd qemu
  • Checkout to commit dated June 03, 2021 v6.0.0

git checkout 3c93dfa42c394fdd55684f2fbf24cf2f39b97d47
  • Apply patch series v8 by Alexander Graf

curl https://patchwork.kernel.org/series/485309/mbox/ | git am
  • Building qemu installer

mkdir build && cd build
../configure --target-list=aarch64-softmmu
make -j8
  • Install qemu

sudo make install

Create Ubuntu Server using QEMU on Silicon based Apple Macs

First run, close manually after installation aka first reboot.

curl https://cdimage.ubuntu.com/releases/20.04/release/ubuntu-20.04.2-live-server-arm64.iso -o ubuntu-lts.iso

qemu-img create -f qcow2 virtual-disk.qcow2 8G

cp $(dirname $(which qemu-img))/../share/qemu/edk2-aarch64-code.fd .

dd if=/dev/zero conv=sync bs=1m count=64 of=ovmf_vars.fd

qemu-system-aarch64 \
  -machine virt,accel=hvf,highmem=off \
  -cpu cortex-a72 -smp 4 -m 4G \
  -device virtio-gpu-pci \
  -device virtio-keyboard-pci \
  -drive "format=raw,file=edk2-aarch64-code.fd,if=pflash,readonly=on" \
  -drive "format=raw,file=ovmf_vars.fd,if=pflash" \
  -drive "format=qcow2,file=virtual-disk.qcow2" \
  -cdrom ubuntu-lts.iso

Second run, enjoy your Ubuntu Server.

qemu-system-aarch64 \
  -machine virt,accel=hvf,highmem=off \
  -cpu cortex-a72 -smp 4 -m 4G \
  -device virtio-gpu-pci \
  -device virtio-keyboard-pci \
  -drive "format=raw,file=edk2-aarch64-code.fd,if=pflash,readonly=on" \
  -drive "format=raw,file=ovmf_vars.fd,if=pflash" \
  -drive "format=qcow2,file=virtual-disk.qcow2"

Bonus, connect via SSH and serve port 80 at localhost.

  1. Start server using -
qemu-system-aarch64 \
  -machine virt,accel=hvf,highmem=off \
  -cpu cortex-a72 -smp 4 -m 4G \
  -device virtio-gpu-pci \
  -device virtio-keyboard-pci \
  -drive "format=raw,file=edk2-aarch64-code.fd,if=pflash,readonly=on" \
  -drive "format=raw,file=ovmf_vars.fd,if=pflash" \
  -drive "format=qcow2,file=virtual-disk.qcow2" \
  -nic hostfwd=tcp:127.0.0.1:9922-0.0.0.0:22,hostfwd=tcp:127.0.0.1:9980-0.0.0.0:80 &
  1. Login via SSH using -
ssh <username>@127.0.0.1 -p 9922
  1. Visit http content at -
open http://127.0.0.1:9980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment