Emulate Raspberry Pi Using QEMU – A Step-by-Step Guide

arch linuxqemuraspberry piraspbian

I would like to run a RaspberryPi system on my MacOSX using QEMU. I tried the following, using this tutorial:

./qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda ArchLinuxARM-2014.06-rpi.img -kernel kernel.img -append "root=/dev/sda" -serial stdio

Where ArchLinuxARM-2014.06-rpi.img is my RPi image and kernel.img precisely comes from ArchLinuxARM-2014.06-rpi.img (I made a copy of it, I am not sure it was a brilliant idea though).

I get two QEMU windows as a result. One has a "Machine" and a "View" menu, and a black screen showing the following message:

Guest has not initialized the display (yet).

The second one is simply a black window.

I had the same problem using a Raspbian image and the same command. What am I doing wrong?

Best Answer

  • First of all, I had to use another kernel, kernel-qemu that I found here.

  • Then, I could make it work using QEMU 1.7.1:

    With Raspbian:

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

    With Arch Linux, I had to:

    1. Start in terminal mode (not sure if necessary, though) using:

      ./qemu-system-arm -kernel /path/to/kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda5 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda /path/to/ArchLinuxARM-2014.06-rpi.img

      (Note that init=/bin/bash was added here, and Arch Linux requires root=/dev/sda5 instead of sda2)

    2. Modify /etc/fstab as follows (the partition was wrong):

      # <file system> <dir>   <type>  <options>       <dump>  <pass>
      /dev/sda1       /boot   vfat    defaults        0       0
      
    3. Start normally using:

      ./qemu-system-arm -kernel /path/to/kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda5 panic=1 rootfstype=ext4 rw" -hda /path/to/ArchLinuxARM-2014.06-rpi.img

  • I finally realised that I could use the latest version of QEMU (2.1.1), but I had to specify the console output:

    ./qemu-system-arm -kernel path/to/kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "console=ttyAMA0 root=/dev/sda5 rootfstype=ext4 rw" -hda /path/to/ArchLinuxARM-2014.06-rpi.img

    (Note that I specified the console using console=ttyAMA0)

Related Question