Home > Linux, Linux 2.6, Testing > Emulate an ARM Plaform with QEMU on Ubuntu 10.10

Emulate an ARM Plaform with QEMU on Ubuntu 10.10

February 10th, 2011 Leave a comment Go to comments

When developing software for embedded systems, you may need to support multiple architectures such as  arm, mips, x86, powerpc, alpha etc.. but you may not have the hardware required on hand to test them.

This is where QEMU – a processor emulator – comes to the rescue. In a way, QEMU is similar to VirtualBox, VMWare or Citrix Xendeskop except it can support multiple architectures.

I’ll show how to run Debian Lenny ARMEL in QEMU on a computer running Ubuntu 10.10 (aka Ubuntu Maverick Meerkat).

QEMU (Qemu-kvm) Installation

First install qemu-kvm and qemu-kvm-extras (the latter contains qemu-system-arm):

sudo apt-get install qemu-kvm qemu-kvm-extras

Let’s check qemu version:

jaufranc@CNX-TOWER:~/edev$ qemu –version
QEMU PC emulator version 0.12.5 (qemu-kvm-0.12.5), Copyright (c) 2003-2008 Fabrice Bellard

Debian ARM Installation in QEMU

Create a directory to store the required files for the emulator and  download the Debian Lenny ARMEL kernel (vmlinuz) and debian installer rootfs (initrd.gz):

mkdir ~/arm-emul

cd ~/arm-emul

wget ftp://ftp.debian.org/debian/dists/lenny/main/installer-armel/current/images/versatile/netboot/vmlinuz-2.6.26-2-versatile

wget ftp://ftp.debian.org/debian/dists/lenny/main/installer-armel/current/images/versatile/netboot/initrd.gz

Create a raw virtual hard disk large enough (e.g. 2GB) for Debian:

qemu-img create -f raw hda.img 2G

Run the ARM virtual machine and follow the instructions to install Debian. This may take several hours, since all instructions are decoded by software:

qemu-system-arm -m 256 -M versatilepb -kernel ~/arm-emul/vmlinuz-2.6.26-2-versatile -initrd ~/arm-emul/initrd.gz -hda ~/arm-emul/hda.img -append “root=/dev/ram”

After the system reboots, close QEMU.

Running Debian ARM in QEMU

Once the installation is complete, mount the first disk partition of the QEMU disk image with a loop device (offset 32256) in order to copy the initrd (rootFS) (mount QEMU images):

mkdir mount
sudo mount -o loop,offset=32256 ~/arm-emul/hda.img ~/arm-emul/mount
cp ~/arm-emul/mount/boot/initrd.img-2.6.26-2-versatile ~/arm-emul/
sudo umount ~/arm-emul/mount

Then run Debian ARMEL in QEMU as follows:

qemu-system-arm -m 256 -M versatilepb -kernel ~/arm-emul/vmlinuz-2.6.26-2-versatile -initrd ~/arm-emul/initrd.img-2.6.26-2-versatile -hda ~/arm-emul/hda.img -append “root=/dev/sda1″

That’s it, you now have a running ARM virtual machine. You can cross-compile your application or library in your host PC (compiling them in the emulator would be very slow), copy them to the VM (via NFS for example) and run them in your ARM emulator. As long as those are not graphics intensive or processor intensive, they should work just fine.

Once the emulator is running you can check the emulated CPU is an ARM926E-JS Core.

QEMU ARM926ej-s-linux-2.6.26.2

I got most of the instructions from http://blog.troyastle.com/2010/07/building-arm-powered-debian-vm-with.html

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Categories: Linux, Linux 2.6, Testing Tags: arm, debian, qemu, ubuntu
  1. Datanasty
    March 8th, 2011 at 04:24 | #1

    You need to be consistent with your image name; first you use ‘flash.img’, then proceed to reference it as ‘hda.img’. Pick one or the other.

  2. March 8th, 2011 at 09:23 | #2

    @ Datanasty
    Thanks. The inconsistency has been fixed.

  3. rafal98
    April 19th, 2011 at 05:24 | #3

    Thx a lot, it’s a very useful topic.

  4. Sander
    August 29th, 2011 at 01:58 | #4

    After “mkdir arm-emul” I suppose there must be a “cd arm-emul”?

    • August 29th, 2011 at 08:02 | #5

      Yes. Thanks for letting me know, I’ll update it.

  5. Sander
    August 29th, 2011 at 12:57 | #6

    PS: I had to “mkdir ~/arm-emul/mount” too. Correct?

  6. August 29th, 2011 at 13:36 | #7

    Correct. Sorry, it seems I made a lot of errors in this entry. I’ll correct it as well. Thanks.

  7. Sander
    August 29th, 2011 at 14:18 | #8

    And some more remarks:

    Thanks to your blog I was able to run Debian on ARM on Qemu on Ubuntu 11.04. Thank you.

    On the first try, I choose to also install X / the Desktop Environment, but that lead to problems, probably because the 2 GB virtual disk was too small. On the second try, I choose only the default install (without X). Maybe worth to mention.

    Sometimes Qemu will ‘grab’ the mouse and I couldn’t switch to Ubuntu anymore. You must press CTRL + ATL to escape it again (as Qemu clearly says in it’s Window ;-( )

    Is there a graphical but non-X game I can install and play in Debian?

  8. August 29th, 2011 at 17:14 | #9

    You’d need some form of graphical framework to replace X such as Qt or DirectFB. Some years ago I’ve used microwindows (nano-X) and they have some demo games (chess). You’d have to make sure the kernel installed in the emulator supports framebuffer (/dev/fb/0 or /dev/fb0) and cross-compile microwindows for ARM.

    Another (simpler) solution would be to increase the size of the virtual disk so it’s big enough to install X11.

  9. Sander
    August 31st, 2011 at 02:10 | #10

    And some more feedback:

    The last instruction ( to run Debian ARMEL in QEMU) contains a new line (making it harder to copy-paste) and strange double-quotes at the end (maybe caused by your web layout program): plain ” is needed.

    FWIW: I created a 5GB harddisk, installed Debian including “Desktop Environment”. However, at ‘startx’ I get an old-skool X server error message. I have never learned how to solve those problems :-(

    Strangely enough wget en lynx work, but ping and mtr show no response …

  10. Someone Special
    September 11th, 2011 at 14:40 | #11

    Why in the world are you using KVM to emulate ARM architechture? KVM is x86(-64) only! It makes no sense to try to use KVM, unless you are also emulating x86 CPUs. Just install qemu-system, that is all you need!

  11. September 11th, 2011 at 15:25 | #12

    @Someone Special
    Since we need qemu-kvm-extras (qemu-system-arm is inside that package), I thought we would also need qemu-kvm. But apparently, it’s also OK to just install qemu instead of qemu-kvm. But I think that does not make a difference, since we only use qemu-system-arm.

  12. marcegarba
    September 23rd, 2011 at 01:32 | #13

    Thanks very much for your blog post.

  13. October 5th, 2011 at 03:41 | #14

    Even worked for Ferdora13 64bit…
    Very nicely written….

  14. Greg
    September 18th, 2012 at 10:00 | #15

    Hi, nice blog post. I wasn’t able to get the loopback mount command to work. It gives the following error.

    mount: you must specify the filesystem type

    I tried things like ext2, ext3, etc but still could not mount. Any idea what to do?

  15. September 18th, 2012 at 18:11 | #16

    @Greg
    ์Not sure what the problem is. These instructions start to date a bit. Maybe the offset has changed, you can check with
    file ~/arm-emul/hda.img
    or
    fdisk ~/arm-emul/hda.img

  16. Greg
    September 21st, 2012 at 10:30 | #17

    Hi cnx, here is what I got. N.b. this is the 3.2 kernel & installer, so maybe that is why the offset don’t match. Everything else seems working fine.

    $ file hda.img
    hda.img: x86 boot sector; partition 1: ID=0x83, active, starthead 32, startsector 2048, 3911680 sectors; partition 2: ID=0x5, starthead 190, startsector 3915774, 276482 sectors, code offset 0xb8
    $ fdisk hda.img
    Command (m for help): p

    Disk hda.img: 2147 MB, 2147483648 bytes
    255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x000664f1

    Device Boot Start End Blocks Id System
    hda.img1 * 2048 3913727 1955840 83 Linux
    hda.img2 3915774 4192255 138241 5 Extended
    hda.img5 3915776 4192255 138240 82 Linux swap / Solaris

  17. Greg
    September 21st, 2012 at 10:40 | #18

    Ah, figured it out. The “startsector 2048″ means that the partition starts at 2048 * 512 = 1048576.

    Using the new offset works great!

  18. Brian
    September 26th, 2012 at 04:21 | #19

    @Greg: Thanks for the tip!

    @cnxsoft: What are you using for compiler options to gcc on the host? When I build a “hello world” with “arm-linux-gnueabi-gcc-4.6 -mcpu=arm926ej-s -o /tmp/hello hello.c” and copy it to the VM, I end up with an illegal instruction error.

  19. Sahil
    May 15th, 2013 at 12:16 | #20

    But this only gives the console.
    Is there any way to get the GUI??

  20. Sahil
    May 15th, 2013 at 18:07 | #22

    @cnxsoft
    Thanks a lot!

  1. October 10th, 2012 at 10:40 | #1
  2. March 5th, 2013 at 13:00 | #2