QEMU Raspberry Pi Emulation on Mavericks

Alan Jackson


To get started make sure you have the following items installed in your development environment. At the time of this writing I am running Xcode v5.02 on OS X 10.9 Mavericks.

  1. Xcode
  2. Homebrew


Install QEMU

QEMU is a generic and open source machine emulator and virtualizer. QEMU will allow us to emulate the ARM environment that is needed to run the version of Debian Linux for the Raspberry Pi called Raspbian. This is not specific to Raspbian and you can use QEMU to run other ARM environments or virtualize other architecture. Lets get started.

Update Brew Formulae (Optional):

~ ❯ brew update
~ ❯ brew upgrade

The default gcc compiler that is part of Mavericks throws errors when building QEMU. If you attempt to install QEMU in Homebrew with Xcode 5 you may get the following errors.

Mavericks gcc compile error:

==> ./configure --disable-maintainer-mode --disable-silent-rules --disable-dtrac
==> make
make[4]: *** [libglib_2_0_la-gbookmarkfile.lo] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

To get around this we are going to install gcc-4.2 with Homebrew and use that version to install QEMU. This will not have any effect on your default gcc compiler.

Install gcc-4.2:

~ ❯ brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb

Now we can install QEMU without issue using the gcc-4.2 compiler.

Install QEMU (Note the gcc-4.2 flag):

~ ❯ brew install qemu --env=std --use-gcc-4.2

Env Setup

At this point you may want to crete a working directory that will store the kernel image and the Raspbian image. This next step will be slightly different for everybody depending on your directory location. I am using ~/dev/rpi/.

Make a working directory for kernel and Raspbian images:

~ ❯ cd dev
dev ❯ mkdir rpi
dev ❯ cd rpi

Grab the Linux kernel:

rpi ❯ wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu

Download the latest Raspbian binaries and unzip to the same directory ~/dev/rpi/ in my case. At the time of writing the latex Raspbian image is 2013-09-25-wheezy-raspbian.img

Booting the Machine

First Boot

We are going to run a first boot to help complete the initial Pi setup and to add a better resolution to work in with Xorg. I am borrowing most of the information in this step from Here and for the Xorg tweak from this post here.

First boot:

rpi ❯ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda 2013-09-25-wheezy-raspbian.img

Upon initial boot you may be prompted to complete the initial setup. Just follow the instructions, no changes necessary. When complete you should be kicked out to the terminal shell with a root prompt. We are going to comment out one line in /etc/ld.so.preload. In the shell type the following:

#❯ nano /etc/ld.so.preload

Comment out the one line below by putting a # in front of the line.


To save the file in nano hit Ctrl+X and then Y and Enter to save file. We are going to make a couple more edits. Back in the shell do the following:

#❯ nano /etc/udev/rules.d/90-qemu.rules

This will create a new file so it should be blank. Add the following lines to the file, save and close out.

KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n",

Now we can add the following lines to /etc/X11/xorg.conf to bump up the resolution to 800x600. Use nano again to edit xorg.conf and add the following:

Section "Screen"
Identifier "Default Screen"
SubSection "Display"
Depth 16
Modes "800x600" "640x480"

After saving xorg.conf you can safely shutdown the machine at this point:

#❯ shutdown -h now

Second Boot

Now we can boot up a second time and we are ready to go. If you opted to not boot to a graphical interface in the initial setup in the first boot step you can load the graphical interface by entering startx at the shell after the boot up completes.

To boot the machine for the second time, and subsequently thereafter:

rpi ❯ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda 2013-09-25-wheezy-raspbian.img