Building Qemu Based RaspberryPI Development Environment

TurnToJPG -->

First download the latest image from, mine is Wheezy. And we also have to download the qemu-compatible kernel from following address:

	$ wget

Change the img file according to http://localhost/blog/2013/09/04/qemu-for-raspberrypi/, follow this tutorial, you have to change the img file size and its content, but we have to do some modifications. The run-qemu file is changed to following:

	# Get name of newly created TAP device; see
	precreationg=$(/usr/bin/ip tuntap list | /usr/bin/cut -d: -f1 | /usr/bin/sort)
	sudo /usr/bin/ip tuntap add user $USERID mode tap
	postcreation=$(/usr/bin/ip tuntap list | /usr/bin/cut -d: -f1 | /usr/bin/sort)
	IFACE=$(comm -13 <(echo "$precreationg") <(echo "$postcreation"))
	# This line creates a random mac address. The downside is the dhcp server will assign a different ip each time
	printf -v macaddr "52:54:%02x:%02x:%02x:%02x" $(( $RANDOM & 0xff)) $(( $RANDOM & 0xff )) $(( $RANDOM & 0xff)) $(( $RANDOM & 0xff ))
	# Instead, uncomment and edit this line to set an static mac address. The benefit is that the dhcp server will assign the same ip.
	# macaddr='52:54:be:36:42:a9'
        macaddr = '52:54:79:3c:80:c0'
	qemu-system-arm -net nic,macaddr=$macaddr -net tap,ifname="$IFACE" -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" $*
	sudo ip link set dev $IFACE down &> /dev/null
	sudo ip tuntap del $IFACE mode tap &> /dev/null

In router, we add the static address for mac corresponding to, you can alter it according to your habit.

Now we want to disable the X at every startup and use vnc instead. And we can overlocking the raspberryPI to 1000MHZ, this will greatly improve the performance.

Enable the vncserver:

	$ apt-get install tightvncserver vim 

Now startup the vncserver and use vncviewer to view the desktop:


No, the correct method is listed as:

	cat /eroot@raspberrypi:~# cat /etc/init.d/startvnc 
	#!/bin/sh -e
	# Provides:          vncserver
	# Required-Start:    networking
	# Default-Start:     3 4 5
	# Default-Stop:      0 6
	# The Username:Group that will run VNC
	export USER="pi"
	# The display that VNC will use
	# Color depth (between 8 and 32)
	# The Desktop geometry to use.
	# The name that the VNC Desktop will have.
	OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
	. /lib/lsb/init-functions
	case "$1" in
	log_action_begin_msg "Starting vncserver for user '${USER}' on   localhost:${DISPLAY}"
	su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
	log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
	su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
	$0 stop
	$0 start
	exit 0

And now we can add this script into /etc/rc.local as:

	# Start the vncserver here:
	/etc/init.d/startvnc start

So everytime we startup the qemu based raspberryPI, we can easily attached to its geometry, and we can easily adapt the resolution.