How to boot a Raspberry Pi SD card using Qemu on OSX

Viewed 2663

I’ve got a Raspberry Pi that has been malfunctioning and I’d like to try and debug it on my OSX laptop to try and determine whether the problem is related to the hardware, SD card or software.

I've taken the SD card from the pi and mounted it on my OSX machine, and have copied the files kernel7.img and bcm2709-rpi-2-b.dtb from the /boot partition to the OSX hard drive.

I’ve then unmounted the boot and RECOVERY partitions and then tried starting the emulator with:

sudo qemu-system-arm \
  -machine raspi2 \
  -no-reboot \
  -dtb ./bcm2709-rpi-2-b.dtb \
  -kernel ./kernel7.img \
  -drive file=/dev/disk2,format=raw

This gives me the output:

**qemu-system-arm: Invalid SD card size: 29.7 GiB SD card size has to be a power of 2, e.g. 32 GiB. You can resize disk images with 'qemu-img resize <imagefile> <new-size>' (note that this will lose data if you make the image smaller than it currently is).**

Is there any way I can get around this?

2 Answers

Don't try to pass the raw disk device directly to QEMU like that. Instead copy the contents off the disk onto a normal file (using dd, for instance), and then make sure that that file is the correct size, and tell QEMU to use that instead.

(Copying the contents of the SD card to your hard disk will also provide a check that the SD card is still actually readable and has no errors...)

Related