Raspberry virtual machine from sdcard (linux/mac)

Kamil Tomšík
Jul 27, 2017 · 1 min read

If for whatever reason you need to setup Raspberry Pi Zero W without keyboard :)

Note: This will actually emulate Raspberry Pi 2 (different version) but it doesn't matter much because all I wanted was to run raspbian in qemu and make some changes to its fs.

Download latest raspbian

Flash to sdcard using Etcher (or whatever else)

Get qemu

brew install qemu

Get kernel and device tree from the first (vfat) partition of your sdcard.

cp /Volumes/boot/{*.img,*.dtb} ./

Start qemu with io forwarded to your terminal

# optionally unmount /dev/disk2 first
# Mac: sudo diskutil unmountDisk /dev/disk2
sudo qemu-system-arm \
-no-reboot \
-serial stdio \
-machine raspi2 -m 256 \
-dtb ./bcm2709-rpi-2-b.dtb \
-kernel ./kernel7.img \
-drive file=/dev/disk2,format=raw \

Setup network

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

Enable ssh

sudo raspi-config

Shutdown and boot with regular raspberry pi.

sudo shutdown now
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade