Last active
June 9, 2025 00:37
-
-
Save bitplane/d282f0ae7c8cdce87872e51b47f16701 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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