Why: I wanted to have builder environment for Raspberry PI. Emulating it it much faster that running something on it
Disclaimer: I am not a qemu/raspberry-pi expert - Some things may be wrong here
Introduction
Running qemu-arm is slightly different than running qemu for x86. There is no BIOS there and it needs to boot with a kernel image directly. The tricky part is that this image is not the standard Raspberry Pi (from now on mentioned as "raspi"). You can either download one from online or create your own.
I ended up creating my own qemu arm image
Disk image
Get the official raspberry pi disk image from here. Place it somewhere and uncompress it.
By default the image does not have much free space. A trick to change that is to extend it with something like the following:
# dd if=/dev/zero of=2013-02-09-wheezy-raspbian.img \
bs=1024000 conv=notrunc \
seek=4000 count=1
This will write 1MB after the first 4000 MBytes on the image. This will cause the image to become approximately 4GB but it will leave a hole in the file if the underlying filesystem supports it.
Kernel Image (optional)
If you want to compile your own kernel image for qemu then follow first the instructions here. Follow just the instructions on cloning git and patching the kernel.
Instead of configuring it yourself get this configuration (will speed your life) which has some additional stuff like
# make ARCH=arm oldconfig
# nice make ARCH=arm -j 4 # Adjust for your number of cores
# cp arch/arm/boot/zImage /path/to/raspi/directory
You will need the arm compilation toolchain. If you're running Debian then follow the instructions in http://www.emdebian.org/
The package you are looking for is gcc-4.4-arm-linux-gnueabi
Note: Raspberry Pi supports hardfloat while the above compile is not using hardfloat. There should be no problems with that since the kernel is not using floating point math itself and it won't make a difference. The attached kernel configuration however has hardfloat support and so does qemu.
Booting
I am using vde networking with qemu so your setup may be slightly different. In any case, this is a nice setup to get you started:
# qemu-system-arm \
-cpu arm1176 \
-kernel kernel-v13-qemu-130323 \
-name 'builder-raspi' \
-hda 2013-02-09-wheezy-raspbian.img \
-m 256 \
-M versatilepb \
-no-reboot \
-serial stdio \
-net vde,sock=/var/run/vde2/tap0.ctl \
-net nic \
-append "root=/dev/sda2 panic=0 ro
Use the proper path for the disk image and the kernel.
Now, here's the catch: The latest (as of 2013-03-23) raspberry pi image will have some issues booting with the above setup.
Fix latest filesystem image
Change the qemu -append parameter to: "root=/dev/sda2 panic=0 ro single" and boot the image.
This should leave you with a nice prompt. Then:
# mount / -o remount,rw
Next, edit fstab and change mmcblk0p1 and mmcblk0p2 to sda1 and sda2 respectively
Then create the file /etc/udev/rules.d/90-qemu.rules with the following contents:
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n",
This should ensure that /dev/mmcblk0p1/2 exist and will make other stuff work.
Also edit /etc/ld.so.preload (if it exists) and remove or comment everything in it.
Now shutdown the qemu image, restore the -append parameter and run it again. If raspi-config does not start by itself, run it yourself after logging in as user "pi". You can now select "expand_rootfs" and do another reboot to get more space on the root partition.