11 Feb

Emulating Raspbian for the Raspberry Pi on Linux using QEMU

I’ve recently been trying to emulate Raspbian for the Raspberry Pi on my desktop computer so that I can try a few things out when I don’t have my Pi to hand.

Some of the guides on the internet are a bit outdated and since I wanted to use the latest Jessie build some where not relevant.

Below you will find instructions for emulating Raspbian on a desktop PC.

Install QEMU

sudo pacman -S qemu

Download the latest Raspbian image from https://www.raspberrypi.org/downloads/. At the time of writing the latest version was Raspbian Jessie with a kernel version 4.4.

Download this QEMU compatible kernel from https://github.com/dhruvvyas90/qemu-rpi-kernel.

The image file needs to be slightly modified as the /etc/fstab file is referencing /dev/mmcblk0, which is the SD Card device. Inside the emulation environment, the disk will have device id /dev/sda.

Attach the image file on the loop device:

sudo losetup -Pf 2017-01-11-raspbian-jessie-lite.img
mkdir partition2
sudo mount /dev/loop0p2 partition2
vi partition2/etc/fstab

Inside vi change references to mmcblk0 to sda.

Now unmount and detach the image from the loop device:

sudo umount partition2
rm -rf partition2
sudo losetup -d /dev/loop0

We can finally run up the system:

qemu-system-arm -kernel kernel-4.4.34.img -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda 2017-01-11-raspbian-jessie-lite.img

Hopefully after the system has booted you will see a similar screen to this:

Leave a Reply

Your email address will not be published. Required fields are marked *