Skip to content

Instantly share code, notes, and snippets.

@eb4x
Last active July 17, 2025 16:33
Show Gist options
  • Select an option

  • Save eb4x/7974cf88881d4180d62a439087cec0a9 to your computer and use it in GitHub Desktop.

Select an option

Save eb4x/7974cf88881d4180d62a439087cec0a9 to your computer and use it in GitHub Desktop.
raspbian on qemu

raspbian on qemu

Download an image

https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-32-bit

Extract and resize it

Resizing could be somewhat optional, but check the current size and go bigger.

xz --decompress 2024-11-19-raspios-bookworm-armhf-lite.img.xz
qemu-img resize 2024-11-19-raspios-bookworm-armhf-lite.img 4G

Create partition devmappings from image, and mount the first one

(Your devmappings may vary)

sudo kpartx -a 2024-11-19-raspios-bookworm-armhf-lite.img

sudo mkdir /mnt/raspbian-boot
sudo mount -o loop /dev/dm-0 /mnt/raspbian-boot

Install qemu-system-{arm,aarch64} # arm for raspi2b, aarch64 for raspi3b

sudo dnf install -y qemu-system-arm qemu-system-aarch64

Run as a RPI2b (32-bit)

qemu-system-arm -machine raspi2b -cpu cortex-a7 -m 1G -serial stdio \
  -dtb /mnt/raspbian-boot/bcm2709-rpi-2-b.dtb \
  -kernel /mnt/raspbian-boot/kernel7.img \
  -append "root=/dev/mmcblk0p2 rootwait dwc_otg.fiq_fsm_enable=0" \
  -device usb-kbd \
  -device usb-tablet \
  -netdev bridge,br=virbr0,id=network0 -device usb-net,netdev=network0 \
  -drive if=sd,file=2024-11-19-raspios-bookworm-armhf-lite.img,format=raw

Run as a RPI3b

qemu-system-aarch64 -machine raspi3b -cpu cortex-a72 -m 1G -serial stdio \
  -dtb /mnt/raspbian-boot/bcm2710-rpi-3-b-plus.dtb \
  -kernel /mnt/raspbian-boot/kernel8.img \
  -append "root=/dev/mmcblk0p2 rootwait" \
  -device usb-kbd \
  -device usb-tablet \
  -netdev bridge,br=virbr0,id=network0 -device usb-net,netdev=network0 \
  -drive if=sd,file=2024-11-19-raspios-bookworm-armhf-lite.img,format=raw

Expand the storage

From a shell on the pi

sudo parted /dev/mmcblk0 resizepart 2 100%
sudo resize2fs /dev/mmcblk0p2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment