XEC Design >Mostly tutorials for Raspberry Pi

15Apr/1297

QEMU – Emulating Raspberry Pi the easy way (Linux or Windows!)

This page will shows how to emulate an ARM1176JZF-S system the quick and easy way.

UPDATE (17th of March, 2013): In order to run the latest image (2013-02-09-wheezy-raspbian.img) you need to comment out the contents of /etc/ld.so.preload. - kinsa

Linux users will find the necessary steps here .

I have created a patcher for windows users  and it's available here. When asked, give it the directory containing your 2013-02-09-wheezy-raspbian.img file. The patched img file should be properly bootable by qemu.

Assumptions

You have:

  • QEMU - Linux or Windows. Make sure you have a suitable version (see 'Quick note on QEMU and ARM1176').
  • A disk image for your distro of choice
    • Raspian and Debian should work out of the box, however Arch Linux requires a few tweaks to work. These will not be explored in this article, as they can only be done in Linux.
  • Ability to read and follow instructions carefully

Quick note on QEMU and ARM1176

ARM1176 support is relatively new. If you did not compile QEMU yourself from git, or download fairly recent binaries, replace -cpu arm1176 with -cpu arm1136-r2 whenever you see it. Note that you will be missing out on many important bug fixes and a few unimportant CPU features. If you boot with -cpu arm1176 and see something about unsupported instructions, you've got an older version of QEMU.

Preparing the environment

  1. Create and enter the work directory.
  2. Download the linux kernel:
  3.  Download and extract the disk image .img file to the working directory.
  4. All of the instructions will be carried out in this directory.

Check that you have everything

  1. Make sure you have kernel-qemu and your disk image files.
  2. qemu-system-arm -cpu ?

If everything looks right, you should be ready to go.

Booting the disc image

  1. qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda 2012-10-28-wheezy-raspbian.img

    • Make sure you replace '2012-10-28-wheezy-raspbian.img' with the name of your disc image.
    • Do not try to use more than 256 MB of RAM, the value is hard-coded in and QEMU will not work correctly.
QEMU running raspbian
That's it, you should see the system starting to boot.

Things to keep in mind

  • The disc image will only contain about 200MB of free space (if any at all) for you to play with, so don't expect to be able to install a full system. If you want to have a larger image, you will need to create it yourself. Check the full QEMU tutorial for details.
  • You may see a few steps failing while the image boots. That's normal, since QEMU cannot emulate ALL of the hardware exactly. Double check that all the important steps are fine, but in general, this isn't something to worry about.

 

Comments (97) Trackbacks (7)
  1. I can confirm this is working with the latest 64-bit Windows QEMU build using the following command line –
    qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -serial stdio -append “root=/dev/sda2 panic=1″ -hda debian6-19-04-2012.img -clock dynticks

  2. I used

    http://qemu.weilnetz.de/w32/2012-06-28/qemu-system-arm.exe

    But is complains of missing DLLs.

    SDL.dll
    libcrypto.dll
    libcurl-4.dll
    libglib-2.0-0.dll
    libssl.dll

    Some, but not all of them, can be found here

    http://qemu.weilnetz.de/w32/mingw/

    Cheers, Steve

  3. Sorry for asking suck a stupid question.

    Is there a way to download all the necessarily qemu files from http://qemu.weilnetz.de without take them one by one ?

    • AFAIK you don’t need all of them. The one I know you need for sure is qemu-system-arm.exe. When I tried it just crashed on launch, but Steve (in the comment above yours) reports that http://qemu.weilnetz.de/w32/2012-06-28/qemu-system-arm.exe works.

    • For Win64 dowload:
      /w64/dll/*.dll (all dlls)
      /w64/2012-06-28/qemu-system.arm.exe
      /w64/2012-06-28/keymaps/en-us

      Put the dlls in the same directory of qemu-system.arm.exe and preserve the /keymaps subdirectory.

      I could execute it with the following command:
      qemu-system-arm -M versatilepb -m 128M -nographic -kernel c:\Temp\arm\test.bin

  4. Actually, you can expand your image file size without having to create a new one.

    First, launch following command on host :
    dd if=/dev/zero bs=1M count=2048 >> raspbian.img
    (In this example, the file raspbian.img is expanded with 2 GB)

    Then, launch your qemu, and inside the console, launch this :

    PART_START=$(parted /dev/sda -ms unit s p |grep “^2″ | cut -f 2 -d:)
    echo $PART_START # (to be sure that it’s not empty).
    fdisk /dev/sda <<EOF
    p
    d
    2
    n
    p
    2
    $PART_START

    p
    w
    EOF

    Then reboot and launch resize2fs on /dev/root .

    And, here you have your freshly expanded FS :) .

    Mainly inspired from raspi-config script ;) .

  5. Can you walk through how you built the kernel?

    • You can reach me on the #raspberrypi irc channel on freenode, I’ll be happy to help.
      Edit: But also, there’s the tutorial I wrote earlier which has the exact steps. =)

  6. This might be a noob question, but after getting RPi/Qemu running, how do I transfer cross-compiled binaries to it for testing? I don’t seem to have an accessible network connection, or file system.

    Is it a closed environment?

    Steve

  7. Ok, I am using Fedora 17 with the qemu version 1.0.1 that is available via the repository. I downloaded all of the various images from the raspberry site (2 wheezy debian and one Arch) and the kernel-qemu from your site. I followed the directions for the qemu-system-arm command and it boots initially, but gets a “Kernel panic – not syncing: attempted to kill init!” and stops before getting to a log in prompt.

    I don’t know how to grab the boot log so I can’t parse it in any better detail. I do see that I get some errors at the command line related to pulseaudio, but I don’t think that is the problem.

    Can you give any info on how to debug this thing?

  8. A quick follow up… I tried each of the 3 images from the raspberry pi site; same result. I have now moved on to ubuntu 12.04 with qemu-system-arm version 1.0.50; same result there. Note; both of the linux distributions have been 64 bit. I will try a 32 bit ubuntu next to see if that helps.

  9. Success. Ubuntu 12.10 32 bit with qemu-system-arm version 1.2. Works fine. Don’t know which of the variables made the difference (ubuntu version, qemu version or 32 bit vs 64 bit), but my bet is on 32 bit.

  10. Thanks – works for me with -cpu arm1136-r2.
    With arm1176 the kernel crashed soon after starting the boot process. It`s probably due to my laziness – my QEMU is latest stock, from Ubuntu Precise.
    I see only 256MB RAM despite i gave it 512 (need to emulate model B). Is it limit of the emulated CPU I set or it`s configured somewhere in the raspbian image ?

    • Self answering: 256MB is hardcoded in the emulated versatile platform. If someone needs more memory, he should create a second RAW file for the qemu on a tmpfs (RAM disk) and setup there a swap file. 1-2GB should be possible. Thus the emulated system will efectively extend it’s virtual memory.

  11. I have had reasonable success using the windows binaries from here
    http://lassauge.free.fr/qemu/

    On a separate note, this is an excellent site, very clear and useful information.

  12. Working on my Win XP 32-bit too……. Thanx…

  13. oss: Could not initialize DAC
    oss: Failed to open `/dev/dsp’
    oss: Reason: No such file or directory
    oss: Could not initialize DAC
    oss: Failed to open `/dev/dsp’
    oss: Reason: No such file or directory
    audio: Failed to create voice `lm4549.out’
    VNC server running on `127.0.0.1:5900′
    Uncompressing Linux… done, booting the kernel.
    pflash_write: Unimplemented flash cmd sequence (offset 0000000000000000, wcycle 0×0 cmd 0×0 value 0xf000f0)
    pflash_write: Unimplemented flash cmd sequence (offset 0000000000000000, wcycle 0×0 cmd 0×0 value 0xf0)

  14. Ok thank you anyway !

  15. Can some one please explain in detail how one of the previous posters meant it was possible to gain 512M of ram?

    • Use the qemu-img tool to create a file. Add ‘-hdb yournewfile’ to the qemu parameters. Onced booted, you can run ‘mkswap /dev/sdb’ and ‘swapon /dev/sdb’ as root to use that file as swap. If you have trouble with it, let me know and I’ll add a section about it to the article.

  16. Hello,

    Thank you for this great tutorial, however I get no luck with this. I was trying it on Windows 7 x64. I’ve downloaded QEMU for windows x64 listed here, kernel listed here and official rasbian for RPI.

    when I try to run qemu, I get no error, but just blank black screen. Files stderr.txt and stdout.txt are blank.

    Any ideas what’s wrong?

    • It’s a bit hard to tell given that there’s no output. Could you try again using this binary?
      http://qemu.weilnetz.de/w32/2012-06-28/qemu-system-arm.exe

    • Same problem here. System: Win7 ult x64 AMD 7750. Build 7600.16917

      Running (with any Pi image) the x86 ARM binary gives me error 0xc000007b. And x64 binary gives me a black qemu screen. stderr.txt gets created, but is deleted when the (blank) qemu window is closed. There is nothing in the file while it exists. Stdout.txt gets filled with 24 lines of garbled text, the first line is longer. All images pass hash checks. Clicking inside the blank window removes the mouse pointer from the screen and tells me that alt+ctl will “exit mouse grab”.

      I am using your guide for doing this. My steps are…

      (1) Get and run the windows qemu installer from “http://qemu.weilnetz.de/w64/”.
      (2) Get “qemu-system-arm.exe” from “http://qemu.weilnetz.de/w64/2012-12-04/”
      (3) Get all five *.ddl’s from “http://qemu.weilnetz.de/w64/dll/”
      (4) Move the files from step 2-3 to “C:\Program Files (x86)\qemu” (default install directory.)
      (5) Get the RaspberryPi images from “http://www.raspberrypi.org/downloads”
      (6) decompress the images to qemu directory.
      (7) Run “qemu-system-arm -cpu ?” Confirm that ‘arm1176′ is in Stdout.txt.
      (8) In a command prompt, navigate to the qemu directory, do one of these two commands…

      [code]qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda .img[/code]

      *OR* (Command provided by Bob above)

      [code]qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 panic=1" -hda .img -clock dynticks[/code]

      Doing “qemu-system-arm -cpu ?” with the x64 binary gives me the expected list of sported cpus in Stdout.txt. So it would appear that qemu is installed and working correctly. However, I tried a non RaspberryPi ARM test image from “http://wiki.qemu.org/Testing” and it did the same thing.

  17. Thanks, works nicely with Debian image. For arch linux the booting process fails after random seed (dependency failure for /boot …)

    • To get arch working, you need to edit fstab and change mmcblk0 to sda. Also, you need to add the rw parameter to the append string.

      • Thanks. It requires little work.
        – for record
        mount the image(for how to http://unix.stackexchange.com/questions/2661/mounting-a-img-file) and edit the fstab as mentioned and change the boot location to sda1.
        – remove the symbolic link in /etc/systemd for syslog (If not you can not login as the screen flooded with messages related to this) (why this required when journalctl takes care of this – I will check in their forum)

        • I am pretty sure simply adding rw to the append string fixes the journald flood. This happens because without rw, the root filesystem is mounted as read only, journald can’t write to it and fails to start, which causes the flood.

          • shift, thanks. fstab needs to be updated for both /boot and /. the default is for /boot only. I need to figure out why the default option is not working. I need to go thro’ your qemu article to get 512 MB memory.

  18. kgas, you’ll need a swap disk/partition or a swap file for that. As Angel Genchev mentioned above, 256 is hard-coded into the versatile platform. There is work in progress to give qemu a proper raspberry pi target though, which looks promising.

  19. Thanks for all the help.
    How to Create a larger image file.
    This seems to work on Ubuntu 12.04. I got the qemu source from Linaro and built it using the directions found on this website.

    qemu-img create boot.img 4G
    sudo mkfs.ext4 boot.img
    sudo mount boot.img /mnt/b -t ext4 -o loop
    sudo mount -o loop,offset=$(( 512 * 122880)) 2012-10-28-wheezy-raspbian.img /mnt/img
    cd /mnt/b
    sudo cp -R -a /mnt/img/* .
    cd -
    qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append “root=/dev/sda panic=1″ -hda boot.img

    (note /dev/sda)

    • You need a fat32 partition for booting. To grow the image you need extra work (there are other methods too)
      — create the image size you need ( 4 GB is enough)
      — Partition the image (first one for /boot fat32 (make this bootable) rest for / — you can get lot of how to from search please)
      — Mount the partitions and copy the files to the respective directory
      — un mount and boot with the new image ..

  20. Windows 7 x64:
    QEmu v1.3.0 from http://lassauge.free.fr/qemu/release/Qemu-1.3.0-windows.zip
    Kernel from http://xecdesign.com/downloads/linux-qemu/kernel-qemu

    Start with:
    qemu-system-armw.exe -M versatilepb -cpu arm1176 -hda Raspbian.img -kernel kernel-qemu -m 256 -serial stdio -append “root=/dev/sda2 panic=1″

    If set memory to any more than 256, then I get only a black screen and corrupted stdout.txt file.

    The only issue the low resolution.

    Good work, Thanks

  21. It is very nice idea!So interesting I am very thankful for this article. It helps me a lot by giving an idea about Raspberry Pi. Now i know that it is very useful. Just keep posting great ideas about Raspberry Pi.

  22. I am successfully able to run the emulator now I want to install java on it. Can anyone tell me how to do this. Also how can I view the IP address of the emulator?I have started o use linux as well as Raspberry just recently.

    Thanks in advance.

  23. I just wanted to thank you for this. I’ve written a few scripts for the RPi and this article was very useful. I just came back when trying Arch hard-float and had a running system five minutes later. It’s a shame one has to mount and edit the /etc/fstab but I’d already written a rpi_mount utility that made that painless. If anyone needing to modify /etc/fstab for Arch Linux would like to make use of what I’ve done then feel free to get it from my site (https://github.com/johnlane/rpi-utils).

  24. Works flawless on OS X Mountain Lion…

  25. Great tutorial! I followed the instructions and now I have the Debian VBox with the Raspberry Pi image running. However it seems there is a configuration problem with the mouse. After the Raspeberry Pi starts its LXDE desktop I can’t control the mouse. It works fine in the host LXDE (in the Debian virtual machine), but when I click in Pi’s windows it goes to the upper-left corner or desapears.
    Tried to include -usbdevice tablet command in the qemu-system-arm.exe command line, but it didn’t make any diffference.

    • Are you using something like VirtualBox or VMWare’s mouse integration features? They don’t play well with a guest running qemu.

      • I have vmware server installed so I assume that explains why my mouse is all wonky while emulating raspberry in qemu even when I change the mouse sensitivity settings. How would I disable the vmware servers’s mouse integration? I can only find how-to’s with other vmware products.

  26. Bingo!
    I disabled VirtualBox mouse integration and qemu’s Raspberry desktop worked perfectly.
    Thanks a lot Shift.

  27. Hi,
    Thanks for this tutorial. I couldn’t get QEMU to work in mountain lion so I tried in windows 8 in parallels. When I run qemu-system-arm -cpu ? I get a blank line, and when I run the full command it complained about DLLS, and then when I installed those now I get a blank window that just hangs. Any thoughts?
    I guess I’ll go try it in mountain lion again, since Adi says it works.
    Thanks–

  28. The error I’m getting in Mountain Lion is:
    pflash_write: Unimplemented flash cmd sequence (offset 0000000000000000, wcycle 0×0 cmd 0×0 value 0xf000f0)
    pflash_write: Unimplemented flash cmd sequence (offset 0000000000000000, wcycle 0×0 cmd 0×0 value 0xf0)
    The qemu window launches, but I see:
    EXt3-fs (sda2): error: couldn’t mount because of unsupported optional features (240)
    and then it kernel panics. Thoughts?

  29. It does not work with 2013-02-09-wheezy-raspbian.img
    I downloaded 2012-10-28-wheezy-raspbian.img and it works perfectly, thanks.

  30. @Alexandre It’s identical for me ;) in waiting a solution THX

  31. @Alexandre
    And the same here.

  32. How did you make your kernel-qemu file? I can successfully boot with your kernel, but when I use either of the official kernels (kernel.img or kernel_emergency.img) or the cross compiled kernel image I made myself, I just get an empty window. What did you have to do to your kernel to make it work with qemu? (My kernels do load on the Pi itself.)

  33. In order to run the latest image (2013-02-09-wheezy-raspbian.img) you need to comment out the contents of /etc/ld.so.preload.

    Cheers!

    • I guess you mean one should apply that change to the img itself. How can I do that ? any advisable tool ? (on linux please)

      • I am a bit lazy, so here is a nutshell version. The only tools you need are ‘file’, ‘mount’ and a text editor. Use file on the img to find the startsector of the root partition. Multiply that number by 512. sudo mount whatever.img location -o offset=newnumber. Now you can go to wherever you mounted the partition and make the changes you need. When you’re done, umount and the image should be ready.

  34. Followed your instructions above and successfully loads to the login, but upon login it reports “Raspberry Pi has not been fully configured. Please run ‘sudo raspi-config’” then throws you back to login to repeat the cycle.

    This is under Ubuntu 12.4 LTS with RPi 2013-02-09-wheezy-raspbian.iso

    Any ideas?

  35. Thank you so much for these instructions!

    Using a combination of the suggestions in these comments, I was finally able to get 2013-02-09-wheezy-raspbian working in Ubuntu 12.10 64-bit. I had to comment out /etc/ld.so.preload first as suggested, but it took me a while to figure out I had to mount the *second* partition, and I mounted it using

    http://unix.stackexchange.com/questions/2661/mounting-a-img-file

    as suggested.

    Then I ran into the file system corruption issue mentioned above and fixed it with “fsck /dev/sda2″ as suggested. CTRL+D to reboot.

    Finally raspi-config came up, I went through everything there, and after another CTRL+D I was presented with a login prompt (a little disappointing since I set it to boot to the desktop after login). Panicked for a bit when it wouldn’t let me in and some Googling showed that “pi” is the default login with “raspberry” the password.

    Then I remembered I had reset the password using raspi-config, used that as a password, and I was in to a shell.

    I started the desktop using “startx” and got the standard LXDE desktop!

    Still not sure why I don’t get a DE on startup, but anyway. I might experiment around with Openbox as a DE and fbpanel as a panel – that combination is extremely efficient and lean!

    Next…trying to get Gentoo on it. :-O

    All this is practice before my actual Raspberry Pi arrives…

  36. I’m using Windows and trying to get QEMU to work with the latest Pi image (2013-02-09-wheezy-raspbian.img), can someone please explain how to go about editing the image so that this will work on windows? or provide the pre-modified image file?

  37. i tried it with the last image (2013-02-09-wheezy-raspbian.img)
    i commented the context from /etc/ld.so.preload out und chroot works now fine. but i cant build anything.
    i get the following errors:

    “you need autoconf version 2.59 or newer installed”

    if i run /usr/bin/autoconf i get:
    This script requires a shell more modern than all the shells that i found on your system.

    installed bash version is 4.2.37(1)-release

    does anyone else have those problems?

  38. I followed all instructions related to setup of the system but I cannot run the game “Storm in a Teacup”. Is there any solution ?

  39. Windows 8 User. All directions followed and alot of trouble-shooting done. I can get the QEmu process to start. The process ramps to about 18% of my CPU and the QEmu window remains blank. Does anyone have any ideas?

  40. Im trying to emulate 2013-02-09-wheezy-raspbian.img using the settings listed here without any success.
    Im using QEMU 1.4.0 with the kernal-qemu version listed here (without any file extension).

    All qemu seems to do is lock up wont post or anything site on a blank screen for about 2 mins then just fails to respond.

    im running Windows 7 Ent 64 bit. Any help would be great.

  41. i got an error during booting even with the patch for the img file:

    EXT3-fs (sda2): error: couldn’t mount because of unsupported optional features (240)


Leave a comment