Yesterday, I needed to compile MPD for ARM (git version, story for another article). Since it's way more easy to get dependencies satisfied through apt-get rather than building them by hand, I went for the native compiling option instead of a cross-compile tool-chain. Which I find very unattractive when compiling complex software with lots and lots of dependencies, tool-chain are much more suited for a "one" job like kernel (IMHO).

BUT ! I don't want to pollute my ARM machine with all the dev stuff that I don't need this it's not a machine where I want to compile anything (not much storage for the OS).

So I went for the QEMU solution, QEMU let you create a VirtualMachine of an OS with a virtualized ARM arch. Thanks to the post of Francisco Benitez Leon, I was able to do it painlessly. Just a few hints that Francisco omitted in his article, that's why I'm writing this one, well it's a big copy/paste with modifications all over the place.

Since, I'm on a Mac, I'm pretty f**** with qemu-system-arm so went with a VirtualMachine of Ubuntu with QEMU inside it (Inception, remember ?).

So it's going that way :

  • Install a VM of a Linux OS, don't care what it is, adapt the following command to yours if you don't have apt-get.
  • Start it

How to install QEMU ?

Simple : $ sudo apt-get install qemu qemu-kvm-extras qemu-arm-static

How to install Debian ARM with QEMU ?

Download the ARMEL kernel image and installer (initrd image) from this repo : The actual Debian Squeeze kernel on the official repo are bugged, the network card will not work with QEMU (only with QEMU as it seems).

So get theses one instead :

$ wget http://people.debian.org/~joeyh/d-i/armel/images/daily/versatile/netboot/initrd.gz
$ wget http://people.debian.org/~joeyh/d-i/armel/images/daily/versatile/netboot/vmlinuz-2.6.32-5-versatile

Create a disk image but use the raw format so you could mount it on your system after the installation process has finished. I recommend you much more than just 1G, I went with 5G to be able to build things in the future.

$ qemu-img create -f raw hda.img 1G

Start QEMU : $ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.26-2-versatile -hda hda.img -initrd initrd.gz -append "root=/dev/ram" -m 256

And follow the usual Debian installation instructions and get some coffee, it's slow as hell.

At the end of the installation process you will get a message pointing that Grub hasn’t been installed but don’t worry because QEMU is capable of loading the kernel and initrd images so the machine could boot up. After the installation has ended you will need another initrd to run the machine, remember that the one previously used contains the Debian installer. You can get that from the installed distro.

So, mount the created disk on your system (that’s why you needed to create it in raw format) and copy the image from the boot directory.

$ sudo mkdir -p /mnt/arm_qemu
$ sudo mount -o loop,offset=32256 hda.img /mnt/arm_qemu
$ sudo cp /mnt/arm_qemu/boot/initrd.img-2.6.26-2-versatile .
$ sudo umount /mnt/arm_qemu

Important note : On the mount line, you have an offset option, be careful, this one is for a 1G image. What is this offset ? You must keep in your mind that hda.img is not a simple partition but a whole drive with a MBR, padding and may be other stuff. So, you can't mount from the bytes 0 until the end of the file.

How to compute this offset for you ?

Read your image with fdisk :

$ fdisk -ul hda.img

You will obtain this :

Disk hda.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x000a51ec
Device Boot      Start         End      Blocks   Id  System
hda.img1   *        2048    15988735     7993344   83  Linux
hda.img2        15990782    16775167      392193    5  Extended
hda.img5        15990784    16775167      392192   82  Linux swap / Solaris

I want to mount the extended partition, that's where / is for me. So my offset would be : 2048 * 512 2048 : This number is the number of sector where my partition start, but mount will want bytes. 512 : It's the size of one sector. It's given by fdisk, look at the third line.

So in this cases I would do : $ sudo mount -o loop,offset=$((2048 * 512)) hda.img /mnt/qemu_arm

Start you new Debian

Once you've done everything, run your machine with : $ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img-2.6.32-5-versatile -hda hda.img -append "root=/dev/sda1"