17

I am trying to follow various guides on the Internet in order to emulate Raspberry Pi on my Fedora 22 machine. I have found this question: Emulating raspbian with QEMU and used it to find kernel-qemu to grab a kernel. I downloaded 2015-09-24-raspbian-jessie.img from the good folks at Raspberry Pi.

When I try to run qemu-system-arm I get a kernel panic. Is there something I'm missing?

Here is the qemu-system-arm command line that I typed:

qemu-system-arm -cpu arm1176 -m 256 -M versatilepb -no-reboot -nographic -kernel kernel-qemu -appc=2 console=ttyAMA0 rw" -hda 2015-09-24-raspbian-jessie.img -net nic -net user,hostfwd=tcp::9999-:22

Followed by the kernel messages:

sd 0:0:0:0: [sda] Attached SCSI disk
smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@fluxnic.net>
eth0: SMC91C11xFD (rev 1) at d089a000 IRQ 25 [nowait]
eth0: Ethernet addr: 52:54:00:12:34:56
mousedev: PS/2 mouse device common for all mice
TCP cubic registered
NET: Registered protocol family 17
input: AT Raw Set 2 keyboard as /devices/fpga:06/serio0/input/input0
input: ImExPS/2 Generic Explorer Mouse as /devices/fpga:07/serio1/input/input1
EXT2-fs (sda2): error: couldn't mount because of unsupported optional features (244)
EXT4-fs (sda2): couldn't mount as ext3 due to feature incompatibilities
EXT4-fs (sda2): recovery complete
EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) on device 8:2.
devtmpfs: mounted
Freeing init memory: 120K
Kernel panic - not syncing: Attempted to kill init!
[<c0032bec>] (unwind_backtrace+0x0/0xf0) from [<c03064dc>] (panic+0x58/0x170)
[<c03064dc>] (panic+0x58/0x170) from [<c0044054>] (do_exit+0x5d0/0x68c)
[<c0044054>] (do_exit+0x5d0/0x68c) from [<c004435c>] (do_group_exit+0x40/0xb0)
[<c004435c>] (do_group_exit+0x40/0xb0) from [<c004ed48>] (get_signal_to_deliver+0x1a8/0x378)
[<c004ed48>] (get_signal_to_deliver+0x1a8/0x378) from [<c002f124>] (do_signal+0x90/0x518)
[<c002f124>] (do_signal+0x90/0x518) from [<c002fa64>] (do_notify_resume+0x48/0x54)
[<c002fa64>] (do_notify_resume+0x48/0x54) from [<c002cc38>] (work_pending+0x24/0x28)
Mike S
  • 327
  • 1
  • 2
  • 7

5 Answers5

4

As @dastaan said, the kernel version needs to match the img file. I was trying to use a 4.1 kernel version image file with a 3.18 kernel.

Now that I am using the proper image, it works.

Thanks!

Edit: Getting this to work is pretty straightforward: Grab the image from https://github.com/dhruvvyas90/qemu-rpi-kernel/, then download the corresponding Raspian image you want at https://www.raspberrypi.org/downloads/raspbian/ . Currently, Jessie and Wheezy are up in both places but there is no guarantee in the future that the the appropriate kernel will be available on that Github site. In any event, I wasn't so impressed with the speed myself so I am looking at putting a real Pi onto the wired network port of my laptop and powering it through a 5200 mAh cellphone auxiliary battery thingy, and using VNC on the laptop as a display.

I didn't get Jessie to work; that was the problem- I had a Wheezy kernel and Jessie image, but I didn't have a Jessie kernel.

Mike S
  • 327
  • 1
  • 2
  • 7
2

Ubuntu 16.04, QEMU 2.9.0 -M raspi2, Raspbian 2016-05-27, vanilla kernel

enter image description here

Steps:

  1. Compile QEMU 2.9.0 from source:

    sudo apt-get build-dep qemu-system-arm
    git clone --recursive git://git.qemu-project.org/qemu.git
    cd qemu
    git checkout v2.9.0
    ./configure
    make `nproc`
    
  2. Download image and extract the kernel and dts from it:

    1. Download the image and unzip it:

      wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-05-31/2016-05-27-raspbian-jessie.zip
      unzip 2016-05-27-raspbian-jessie.zip
      
    2. Mount the second image of the partition. The easiest way is:

      sudo losetup -f --show -P 2016-05-27-raspbian-jessie.img
      

      This only works with latest losetup on Ubuntu 16.04, other methods at: https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device/496576#496576

      This prints a loop device, e.g.:

      /dev/loop0
      

      so we do:

      sudo mkdir /mnt/rpi
      sudo mount /dev/loop0p1 /mnt/rpi
      cp /mnt/rpi/kernel7.img bcm2709-rpi-2-b.dtb .
      sudo umount /mnt/rpi
      sudo losetup -d /dev/loop0
      
  3. Run:

    ./arm-softmmu/qemu-system-arm \
        -M raspi2 \
        -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2" \
        -cpu arm1176 \
        -dtb bcm2709-rpi-2-b.dtb \
        -sd 2016-05-27-raspbian-jessie.img \
        -kernel kernel7.img \
        -m 1G \
        -smp 4 \
        -serial stdio \
    ;
    

You can then login on the terminal that shows on your host terminal.

Current limitations:

  • -M raspi2 was added in QEMU 2.6.0, and Ubuntu 16.04 only has QEMU 2.5.0, so we have to compile QEMU from source. But this is not hard.
  • the GUI shows but is not responding to the mouse / keyboard, tested on both SDL and VNC. But CLI works perfectly however. So you might as well use the Lite image which has go GUI for now.
  • no networking

Ubuntu 16.04, QEMU 2.5.0, Raspbian 2016-05-27, modified kernel

This method uses -M versatilepb which is present on the QEMU 2.5.0 of Ubuntu 16.04.

The downside is that you have to download a modified kernel (see Emulating with Qemu: why the extra kernel?), and modify the image, so it is less representative of the real system.

  1. Download: https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/36ede073f4ccb64f60200ede36c231afe9502070/kernel-qemu-4.4.12-jessie

    We pick 4.4.12 since that is the kernel version in the Raspbian image.

    The process to generate that kernel blob is described at in the repository at: https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/36ede073f4ccb64f60200ede36c231afe9502070/tools

    Why this extra kernel image is needed: Emulating with Qemu: why the extra kernel?

  2. Modify the Raspbian image as mentioned at: https://github.com/dhruvvyas90/qemu-rpi-kernel/wiki/Emulating-Jessie-image-with-4.x.xx-kernel/0068f0c21d942b0f331e18014ff8e22c20cada5c

    Summary:

    1. Mount the image just as we did for the -M raspi2, but use the second partition instead of the first:

      sudo mount /dev/loop0p2 /mnt/rpi
      
    2. Edit the image:

      # Comment out the line present there with #
      sudo vim /mnt/rpi/etc/ld.so.preload
      # Comment out the lines of type: "/dev/mmcblk*"
      sudo vim /mnt/rpi/etc/fstab
      
  3. Run:

    sudo apt-get install qemu-system-arm
    qemu-system-arm \
        -kernel kernel-qemu-4.4.12-jessie \
        -cpu arm1176 \
        -m 256 \
        -M versatilepb \
        -no-reboot \
        -serial stdio \
        -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \
        -hda 2016-05-27-raspbian-jessie.img
    

[failed] Ubuntu 17.04, QEMU 2.8.0 -M raspi2, Raspbian 2016-05-27, vanilla kernel

On this newer Ubuntu, QEMU 2.8.0 is the default, so we don't need to compile QEMU from source for -M raspi2. However, 2.8.0 hangs on boot after the message:

Console: switching to colour frame buffer device 100x30

This goes to show how unstable -M raspi2 still is.

[failed] Ubuntu 16.04, QEMU 2.9.0 -M raspi2, Raspbian 2017-08-16, vanilla kernel

On this newer image, using the same method for 2016-05-27, the kernel panics at boot with:

Please append a correct "root=" boot option; here are the available partitions:
...
[    4.138114] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

bztsrc/raspi3-tutorial RPI3 bare metal on QEMU

https://github.com/bztsrc/raspi3-tutorial is a good set of examples that just work on QEMU, ultraquick getting started at: How to do QEMU emulation for bare metal Raspberry Pi images

1

Feel free to take a look at my qemu enabled kernel: https://github.com/diederikdehaas/raspbian-kernel
In the commit messages you can find detailed descriptions on what and how things were changed.
Most of it was based on this article: https://web.archive.org/web/20131210001638/http://xecdesign.com/compiling-a-kernel/

Diederik de Haas
  • 809
  • 8
  • 12
0

Most guides are outdated and contain broken links. You must use a patched kernel that matches the raspbian version you are using.

The following guide works as of feb 2017. It features a script that takes care of changing the raspbian image for running on QEMU, and also shares your network connection with raspbian automatically.

https://ownyourbits.com/2017/02/06/raspbian-on-qemu-with-network-access/

nachoparker
  • 141
  • 4
-1

You can download my custom kernel (4.1.7) for Raspbian Jessie on my github, polaco1782. Follow instructions on doc files.

Greenonline
  • 2,969
  • 5
  • 27
  • 38