Raspberry Pi Releases 1st SD Card Image (Debian) – How-to use it in QEMU

The Raspberry Pi Foundation has just released the first SD Card Image that you will be able to use with your Raspberry Pi board. This image is based on Debian Squeeze (6.0) and comes with  LXDE user interface and Midori browser, development tools, and sample code for accessing the multimedia functionality on the device.

You can download it using BitTorrent: debian6-17-02-2012.zip.torrent (preferred method) or via one of the many http mirrors available on RPi Community page.

This image contains all necessary files including the binary blob and closed source libraries, the kernel and the root file systems.

If you want to to prepare an SD Card with this image simply use dd in Linux:

unzip debian6-17-02-2012.zip
sudo dd if=debian6-17-02-2012/debian6-17-02-2012.img of={sd_card_path}

where sd_card_path is the device pointing to you SD Card (e.g. /dev/sdc). Make sure you use the correct device (e.g. with fdisk -l) or you may wipeout your hard drive with this command.

Since most of us (including myself), don’t have a Raspberry Pi board just yet, we can still run the rootfs of this image in qemu.

First we need to extract the root file system from the SD card image.  We can analyse the SD Card image with the file utility to find the rootfs partition.

#file debian6-17-02-2012/debian6-17-02-2012.img

debian6-17-02-2012/debian6-17-02-2012.img: x86 boot sector; partition 1: ID=0xc, starthead 0, startsector 2048, 153600 sectors; partition 2: ID=0x83, starthead 3, startsector 157696, 3256320 sectors; partition 3: ID=0x82, starthead 3, startsector 3416064, 391168 sectors, code offset 0xb8

This tool shows the SD image image contains three partitions:

  • FAT 32 Partition – with the GPU binary blob and relevant libraries, the kernel image and some configuration files
  • EXT-4 Partition – with the Debian rootfs (that’s what we want)
  • Swap Partition – ~200 MB swap partition (Virtual memory)

We can now extract the Debian rootfs using dd and the offset (startsector) and size returned the the file utility.

dd if=debian6-17-02-2012/debian6-17-02-2012.img of=rootfs_debian6_rpi.ext4 skip=157696 count=3256320

Good! We’ve got our rootfs. It contains some modules compiled against linux kernel 3.1.9, so we need to compile an ARM11 kernel 3.1.9 for qemu by following the instructions given at http://www.cnx-software.com/2011/10/18/raspberry-pi-emulator-in-ubuntu-with-qemu/, replacing kernel 3.0.4 by 3.1.9 AND enabling ext-4 with make menuconfig.

Once the build is complete copy linux-3.1.9/arch/arm/boot/zImage to zImage_3.1.9.

If you don’t want to experience the joy of building the kernel yourself, you can download the binary: http://dl.dropbox.com/u/45842273/zImage_3.1.9

We can now start the virtual machine with R-Pi Debian rootfs and our updated kernel:

qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda rootfs_debian6_rpi.ext4 -kernel zImage_3.1.9 -append "root=/dev/sda" -serial stdio -redir tcp:2222::22

During the system boot, there will be lots of error (like the GPU driver can’t find the GPU…) but you can still reach the login screen. The username/password: pi/suse.

[Update: An error (assertion in arp_table.c) with qemu occurs with many people. You may need to add “-net none” to make it work.  The problem seems somewhat random, some people also had success after downgrading or upgrading qemu).]

You’ll then have access to the command line. LXDE does not start automatically, you need to run:

startx

and after a short while you should see LXDE desktop

QEMU Runs Debian Squeeze LXDE Image
Raspberry Pi Debian LXDE in QEMU

Update: Since some of you have problems, here’s the detail of my setup: Debian Squeeze 6.0.4, Qemu 1.0 running in a Virtual Machine in Virtual Box 4.1.6

You may also wonder what’s inside the FAT partition. Let’s extract it, mount it and list the files:

dd if=./mnt2/debian6-17-02-2012.img of=rpi.fat skip=2048 count=153600
sudo mount -o loop rpi.fat mnt
$ ls -l mnt
total 28072
-rwxr-xr-x 1 root root  2001244 Feb 17 19:02 arm128_start.elf
-rwxr-xr-x 1 root root  2001244 Feb 17 19:02 arm192_start.elf
-rwxr-xr-x 1 root root  2001244 Feb 17 19:02 arm224_start.elf
-rwxr-xr-x 1 root root    16528 Feb 14 01:53 bootcode.bin
-rwxr-xr-x 1 root root      141 Feb 15 01:38 cmdline_testmode.txt
-rwxr-xr-x 1 root root      127 Feb 15 01:52 cmdline.txt
-rwxr-xr-x 1 root root 16412020 Feb 15 01:47 kernel_emergency.img
-rwxr-xr-x 1 root root  3990020 Feb 14 01:53 kernel.img
-rwxr-xr-x 1 root root   314691 Feb 14 01:53 loader.bin
-rwxr-xr-x 1 root root  2001244 Feb 17 19:02 start.elf
sudo umount mnt

start.elf is the GPU binary blob, bootcode.bin / loader.bin are the first files the GPU looks for when booting (I assume), kernel.img is the kernel image and cmdline.txt the configuration file.

There are 3 other binary blob files that can be used to replace start.elf:

  • arm128_start.elf – 128 MB for Linux and the rest (128 MB) for the GPU. To be used for application where the GPU requires a lot of memory (e.g. XBMC)
  • arm192_start.elf – 192 MB for Linux and the rest (64 MB) for the GPU. To be used for application where the GPU requires a moderate amount of memory.
  • arm224_start.elf – 224 MB for Linux and the rest (32 MB) for the GPU. To be used for application where the GPU is not used (for graphics tasks) such as a headless server. The GPU still needs some memory has it performs some other tasks internally.
Share this:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK Pi 4C Plus

61 Replies to “Raspberry Pi Releases 1st SD Card Image (Debian) – How-to use it in QEMU”

  1. You unpack the rootfs to file named “debian6_rootfs.ext2” and then use file “rootfs_debian6_rpi.ext4” as rootfs for qemu. Is it just different name or these are different files?

  2. (note there is a little typo rootfs_debian_rpi.ext4 and rootfs_debian6_rpi.ext4)

    I follow the istructions but here the error i got:

    vlad@debian:~/Downloads/debian6-17-02-2012$ qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda rootfs_debian_rpi.ext4 -kernel zImage_3.1.9 -append “root=/dev/sda” -serial stdio -redir tcp:2222::22
    Uncompressing Linux… done, booting the kernel.
    qemu-system-arm: /build/qemu-dWylvc/qemu-1.0+dfsg/slirp/arp_table.c:41: arp_table_add: Assertion `(ip_addr & (__extension__ ({ register unsigned int __v, __x = (~(0xf <> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24)); else __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); __v; }))) != 0' failed.
    Aborted

    note i run debian testing on real hardware

  3. This may be a dumb question, but isnt it possible to change the resolution? I have it running in qemu under windows and when i go to “start”–>preferences–>monitor settings i can only choose 640*480 while i would like some higher resolutions.

  4. Having a swap on an SD card is not a very good idea, for 3 reasons:

    1- It significantly slows down the OS (since SD cards are extremely slow in simultaneously read/writing.
    2- It increases the chance of errors (Almost any SD card, once it handles more than 2 or 3 transactions at a time, errs)
    3- It decreases the lifetime of the SD card significantly (SD swap space will be written to frequently. This area might wear out a lot faster than the rest of the card , which mainly gets reads.
    4- A 200MB flash space is not very big anyways, but then again, the RAM isn’t very large neither. If the Rpi had 1GB of RAM, or even 512MB, we would not need a Swap space. The problem with the machine is, once you go browsing. Nowadays browsers by themselves use up at least 300MB, due to websites contents running flash and movies, and other multimedia.

    Having no swap will improve system performance, for as long as you stay under the required swap space.
    Once you hit the max swap size limit, the system usually shuts down or crashes.

  5. You could compress the archive using 7z, and if you want to use a swap space, format it with all zeroes if possible.
    That will increase compression.

    For now it’s only ran from PC’s anyway.
    Smaller size means faster up/downloads and precious bandwidth saved

  6. Thank you for posting the information.

    My QEMU session hangs during startup with this error: VFS: Cannot open root device=”1f03″ or unknown-block(31,3)
    Please append a correct “root=” boot option; here are the available partitions:
    0b00 1048575 sr0 driver: sr
    0800 1628160 sda driver: sd
    Kernel panic – not syncing: VFS: Unable to mount root fs on unknown block(31,3)

    I am running Ubuntu 11.10 with the kernel from http://dl.dropbox.com/u/45842273/zImage_3.1.9. My qemu-system-arm came from doing “apt-get install qemu-system”.

    Any suggestions?

  7. request to cnxsoft (and to all this article works)
    Please post your OS/kernel/qemu version because for me and others people (see above) it does not work.
    i run debian testing linux 3.2 qemu 1.0+dfsg-3, in post #3 you can see the error i got.

  8. Here’s the command line shell script that I’m using, which seems to work (reasonably) well on Ubuntu 11.10 x64

    #!/bin/sh
    qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda rootfs_debian6_rpi.ext4 -kernel zImage_3.1.9 -append “root=/dev/sda” -serial stdio -redir tcp:2222::22

    I’m still getting a ” every time I type @ (and vice versa) Anyone know why this is? I explicitly set -k en-us in qemu-system, but that didn’t seem to help…

  9. @ flits
    From r-Pi forums;

    By the way, to get an 800×600 X11 display under QEMU, create the file “/etc/X11/xorg.conf” with the following content:

    Section “Screen”
    Identifier “Default Screen”
    DefaultDepth 16
    SubSection “Display”
    # Viewport 0 0
    Depth 16
    Modes “800×600”
    EndSubsection
    EndSection

    And then restart X11.

  10. mpesce :@ cnxsoft But it’s happening in the shell, not just in LXDE, so there must be something going on system-wide?

    @ cnxsoft
    And I’ve just learned what to do to fix the keyboard:

    sudo dpkg-reconfigure keyboard-configuration

    Select the correct options, reboot, and Bob’s Your Uncle!

  11. @ cnxsoft
    sorry, it is not clear to me. Do you mean you was running Debian linux 3.0.4 inside a virtual box and the inside it you run qemu to run raspberry OS like in follow?

    0. Real hadware with OS (win/lin)
    v
    1. virtualbox
    v
    2. debian linux 3.0.4
    v
    3. qemu-arm-system
    v
    4. raspberry OS

    if it is, then you got problem as i report, you recompile kernel to have 3.1.9 for point #2 of for point #4?

    The OS that run qemu is relevant or not? i mean , no matter the OS that run qemu that run raspberry OS?
    Im getting crazy, i wish so bad to test the raspberry OS 🙁

  12. @ itsme
    Yes, you are correct this is my setup. (Except my kernel in Debian Squeeze 6.0 is “Linux debian 2.6.32-5-686”).

    I just cross-compiled kernel 3.1.9 instead of kernel 3.0.4 as I did in: http://www.cnx-software.com/2011/10/18/raspberry-pi-emulator-in-ubuntu-with-qemu/

    This morning I tried with an Ubuntu 10.04 machine (native with Virtual Box) and I got the same problem as you.
    The only way I found to make it work (as somebody mentioned in Raspberry Pi forum) was to disable the network by adding “-net none” to the qemu command line.

  13. @ cnxsoft
    GOOD! I add “-net none” and it works! Of course there is not network so I cannot try some tests I had in mind. Better tan nothing, anyway! If someone know the trick to make network running, it is wellcome!
    I suspect problem is in “host” system, tomorrow i will try to “downgrade” to debian stable (linux 2.6.32-5) and test again.

  14. @ cnxsoft

    I tried to updated qemu-system-arm command. After adding -net none, it worked. Thanks again. Here is the full command: qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda rootfs_debian6_rpi.ext4 -kernel zImage_3.1.9 -append “root=/dev/sda” -serial stdio -redir tcp:2222::22 -net none

    I seem to be running an older version of qemu:
    $ qemu-system-arm -version
    QEMU emulator version 0.15.50 (Debian 0.15.50-2011.08-0ubuntu4), Copyright (c) 2003-2008 Fabrice Bellard

  15. i downgraded to 0.12.5+dfsg-3squeeze1 and it works also. note i must change -cpu arm1176 in -cpu arm1136 because qemu 0.12.5 does not suppot cpu arm1176.

    NOTE: in emulation color red change in blue, so all color are falsed: i suppose because -cpu arm1136.

    here the command line:

    qemu-system-arm -M versatilepb -cpu arm1136 -m 256 -hda rootfs_debian_rpi.ext4 -kernel zImage_3.1.9 -append root=/dev/sda -serial stdio -redir tcp:2222::22

  16. @cnxsoft

    I was wondering, why will the kernel.img from the boot partition not work? I tried to use it instead of building my own but no dice. Maybe there is a nuance here that I’m missing.

    For the record, I was able to get it working with a locally built kernel and “net -none”. Thanks for the tutorial!

  17. @ alanyih
    So many people reporting different problems and solutions… Networking worked out of the box on one machine for me, and on another I had to run “sudo dhclient eth2” (as for some reason, eth0 was renamed to eth2 during boot) to make network work.

  18. @ cnxsoft
    Thats strange when it try GParted, Root terminal etc in LXDE the “Enter Admin password” window appears and “suse” or {Blank} is not accepted. I tried a sudo command at the command line as well.. not good.
    Rod

  19. @ cnxsoft
    Yes that worked. I think the hour of the day was a contributing factor (2am) 🙂
    With regards to the networking issue I rad a bit, googled a bit, tried a few suggestions but
    ended up with “-redir tcp:2222::80”

    I’d like to say thanks for all the good work and patience will all us noobs.

    Regards
    Rod

  20. @ Rod
    In my command line, I use “-redir tcp:2222::22″ in order to connect to qemu via ssh: ssh -p 2222 pi@localhost.
    “-redir tcp:2222:80” would only be useful if you had a webserver running in qemu and you want to access it with http://localhost:2222. This is also achievable using the tap interface.

    Having said that, I’ve noticed the network issue is kind of random, so it’s still possible the modified command line “fixed” it for you.

  21. @ cnxsoft
    Ah Ok
    I had it round the wrong way, I though I was redirecting TCP 2222 on QEMU to TCP 80 on the host (Weird but now I can connect to the WEB and the local network).
    Another silly question as I cant use admin in LXDE, how do I change the colour depth. Xorg -configure [fail], gdmconfig (I understand LXDE uses gnome).

    Yes I’m showing that I lived in GUI land far too long.

    Rod

  22. @ Rod
    If you use “sudo startx” you should be able to use LXDE as admin.

    To change the settings, you need to edit /etc/X11/xorg.conf (see previous comments here or in raspberry pi forum), but I’m not sure you can change the bit depth (although there is a field for it). It also seems the framebuffer driver supports 800×600 max. You might be able to change that however by recompiling the kernel.

  23. @ cnxsoft
    Thanks mate
    Super steep learning curve, I’ll do a search on the xorg.conf in the forum.
    I’ve just tried completing your step by step instruction substituting newer version of any files i found had newer versions.
    (Cause newer is better)
    I’m up to the” make ARCH=arm menuconfig” and the later kernel or maybe the tool chain has more options than I can find on any howto.

    Anyway Its fun learning, besides its a change from the day job of SDH networks and unix network management system I have no control of. (On their next visit the grand-kids will have to get used to linux as the two PC I have here for them have had a new OS “fall” on them)

    Cheers Rod

  24. The images from Windows XP SP2 Qemu working with this command only.

    C:\Qemu>qemu-system-arm.exe -M versatilepb -cpu arm1136-r2 -kernel zImage_3.1.9
    -hda debian6-17-02-2012.img -append “root=/dev/sda” -m 256

  25. Windows XP SP2 qemu working , sorry for the prenious error.
    C:\Qemu>qemu-system-arm.exe -M versatilepb -cpu arm1136-r2 -kernel zImage_3.1.9
    -hda debian6-17-02-2012.img -append “root=/dev/sda2” -m 256

  26. It worked well for me except that I had to make the -cpu arm1136-r2 or arm1136 rather than 1176 as in your initial instructions. [Looks like Nicos from Kyrenia found the same bug]

    Colour depth on my laptop meant that it came out in funny colours – but that’s OK 🙂

  27. For those having problems with being unable to use the network, I have a workaround (my system is Ubuntu 11.10 64-bit):

    Get the latest qemu from git:

    git clone git://git.savannah.nongnu.org/qemu.git
    cd qemu
    ./configure –target-list=arm-softmmu,arm-linux-user
    make
    sudo make install

    I ran into some problems with the make. I got a handful of warnings about variables being set but not used, but the warnings were set to be fatal for some reason. I tweaked the code (commenting out and whatnot) until it compiled. It probably would have been better to just set the compiler flags to ignore that warning. Anyway, once it compiled, the version is:

    QEMU emulator version 0.13.50, Copyright (c) 2003-2008 Fabrice Bellard

    When I ran the command-line above, it doesn’t recognize arm1176, so I used arm1136-r2 which works. It runs more slowly and the color palette seems a bit off, but everything works correctly, including networking.

  28. @ Eric

    EDIT: Actually, it is better to download qemu 1.0.1 on qemu.org. It also works and supports arm1176. The color palette is correct.

  29. Hi,

    anybody out there who has this running on MacOS? I currently have troubles to launch QEMU and don’t know where to start troubleshooting …

    I followed the instructions from http://igor.gold.ac.uk/~mas01mjy/wp/?p=95 but when starting QEMU, a window opens but remains blank. CPU usage goes up but nothing happens. No log entries either …

    Any hints welcome

    Cheers,
    Ralph

  30. @ ralph

    Ralf, I get exactly the same problem, have re-downloaded the files again, no luck. I am on 10.7.3.
    Did you get any further?
    Has anybody got it to work on mac?

  31. Perfectly working with:
    – VirtualBox 4.1.10
    – Debian Squeeze 6.0.5
    – Qemu 1.1 (compiled locally)
    – The new Raspberry Pi Debian image (as of April 2012)

    Thanks,
    M

  32. Managed to get qemu raspberry pi running on Ubuntu 12.10 Alpha, Midori onto internet. There’s some changes in qemu install for Ubuntu will try to reconstruct what I did to get going.

Leave a Reply

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

Khadas VIM4 SBC
Khadas VIM4 SBC