Skip to content

Instantly share code, notes, and snippets.

@bitplane
Last active June 9, 2025 00:37
Show Gist options
  • Select an option

  • Save bitplane/d282f0ae7c8cdce87872e51b47f16701 to your computer and use it in GitHub Desktop.

Select an option

Save bitplane/d282f0ae7c8cdce87872e51b47f16701 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Paste into bash like: xclip -selection clipboard -o | bash
#
set -euo pipefail
# Ensure dependencies are present
for cmd in curl xz qemu-system-aarch64 mktemp; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Missing: $cmd" >&2
exit 1
fi
done
# Set up working dir
TMPDIR=$(mktemp -d -t pi3b-qemu-XXXXXX)
cleanup() {
echo "Cleaning up..."
rm -rf "$TMPDIR"
}
trap cleanup EXIT
cd "$TMPDIR"
echo "πŸ“ Working in $TMPDIR"
# Step 1: Download Raspberry Pi OS Lite 64-bit
echo "πŸ“₯ Downloading Raspberry Pi OS Lite (64-bit)..."
curl -LO https://downloads.raspberrypi.org/raspios_lite_arm64_latest
mv raspios_lite_arm64_latest raspios.img.xz
echo "πŸ“¦ Decompressing image..."
xz -v -d raspios.img.xz
# Step 2: Resize image to 4 GiB (QEMU SD controller requires power-of-2)
echo "🧩 Resizing image to 4 GiB..."
truncate -s 4G raspios.img
# Step 3: Get firmware (kernel + dtb)
echo "βš™οΈ Downloading firmware kernel + DTB..."
curl -LO https://github.com/raspberrypi/firmware/raw/master/boot/kernel8.img
curl -LO https://github.com/raspberrypi/firmware/raw/master/boot/bcm2710-rpi-3-b-plus.dtb
# Step 4: Launch QEMU
echo "πŸš€ Launching Raspberry Pi OS in QEMU... Type here not in the QEMU window"
qemu-system-aarch64 \
-M raspi3b \
-m 1024 \
-cpu cortex-a53 \
-kernel kernel8.img \
-dtb bcm2710-rpi-3-b-plus.dtb \
-sd raspios.img \
-append "console=ttyAMA0 root=/dev/mmcblk0p2 rootfstype=ext4 rw rootwait fsck.repair=yes" \
-serial mon:stdio \
-netdev user,id=net0,hostfwd=tcp::5022-:22 \
-device usb-net,netdev=net0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment