Skip to content

Instantly share code, notes, and snippets.

@chetbox
Last active March 5, 2025 16:04
Show Gist options
  • Save chetbox/3d2624b3727b35cf82d68f21f2449e2c to your computer and use it in GitHub Desktop.
Save chetbox/3d2624b3727b35cf82d68f21f2449e2c to your computer and use it in GitHub Desktop.
Run Raspberry Pi 64 system image with QEMU on macOS
#!/bin/bash
# Requirements:
# - macOS
# - qemu - `brew install qemu`
# - A raw 64-bit Raspberry Pi system image to boot (Usually a .img)
set -e
if [[ -z "$1" ]]; then
echo "Disk image expected as argument" 1>&2
exit 1
fi
# Mount disk and find where /boot is mounted
BOOT_MOUNT=$(
hdiutil attach -imagekey diskimage-class=CRawDiskImage "$1" | grep 'Windows_FAT_32' | sed 's/.*\t//'
)
# Copy required files to local folder
cp "$BOOT_MOUNT/bcm2710-rpi-3-b-plus.dtb" ./
cp "$BOOT_MOUNT/kernel8.img" ./
# Unmount disk
hdiutil detach "$BOOT_MOUNT"
# Make sure the disk is on a power of two boundary for QEMU
qemu-img resize -f raw "$1" 8G
qemu-system-aarch64 \
-M raspi3b \
-cpu cortex-a72 \
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" \
-dtb bcm2710-rpi-3-b-plus.dtb \
-drive "if=sd,format=raw,file=$1" \
-kernel kernel8.img \
-m 1G -smp 4 \
-serial mon:stdio \
-device usb-net,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:22 \
-usb -device usb-mouse -device usb-kbd \
@chetbox
Copy link
Author

chetbox commented Feb 21, 2025

Have you managed to boot a Raspberry Pi OS image on UTM?

@jon-ESA
Copy link

jon-ESA commented Feb 21, 2025

Nope not virtualised at least. I'm experimenting with the aarch64 build on UTM for Arch linux, and also installing arch linux on the raspberry Pi. It seems Arch Linux has better support for electronics / robotics anyway over RaspbianOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment