Using QEmu to create a Raspbian image
If like me for a particular project or simply to test without going through a Raspberry Pi and its SD card, you can quickly test the creation of image using Qemu and the network installable version of Raspbian.
For my project Pi Home Connect, I want to be able to simply deploy an image “ready-to-use” for those who wish to embark on the adventure. For this, It is convenient to have a quick and simple way under the hand. I found it by combining Qemu to virtualize the Raspberry and the network installation image of Raspbian which generates a minimalist and up to date image.
Subsequently, I can configure this installation to add additional packages and then download on GitHub for example some sources. Practice to set up a NodeJS server and associated data bases.
- Update the system
apt-get update
- Install qemu 1.5+
- Install the necessary compilation tools
apt-get build-dep qemu devscripts quilt libiscsi-dev libusbredirparser-dev libssh2-1-dev libvdeplug-dev libjpeg-dev
- Retrieve the sources of Qemu. At the time of the writing of its article this is the stable version 2.2.0 the most recent
wget http://wiki.QEMU-project.org/download/QEMU-2.2.0.tar.bz2 tar xvfj qemu - 2.2.0.tar.bz2
- Compile and install Qemu
cd qemu-2.2.0
configure
make
make install
- Install the necessary compilation tools
- Retrieve the special kernel for Qemu
wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu
- Retrieve the last image of the network installation. Currently the version 1.0.6
wget https://github.com/debian-pi/raspbian-ua-netinst/releases/download/v1.0.6/raspbian-ua-netinst-v1.0.6.img.bz2
bzip2 -d raspbian-ua-netinst-v1.0.6.img.bz2
- Retrieve the image to the address change script http://pastebin.com/sqtQ19Ci. For my use I backed up its content in a file prepare.sh
curl http://pastebin.com/download.php?i=sqtQ19Ci | tr -d 'r' > prepare.sh
chmod 755 prepare.sh
- Install Kpartx if necessary
apt-get install kpartx
- Prepare the official image for use with Qemu
./prepare.sh raspbian-ua-netinst-v1.0.6.img
The process will generate you a specific file installer-qemu.cpio that will be used in the start-up phase
- Run Qemu with the following command
qemu-system-arm -kernel "kernel-qemu" -initrd "installer-qemu.cpio" -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "consoleblank=0" "raspbian-ua-netinst-v1.0.6.img"
The process will take several minutes during which it will download and install the packages needed. At the end the window will close, It will be the end of the installation
- Run Qemu to use your image :
qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -append "root=/dev/sda2 rw vga=normal console=ttyAMA0,115200" -hda raspbian-ua-netinst-v1.0.6.img -redir tcp:5022::22 -serial stdio
Now here you are with a up-to-date system for Raspberry Pi.
To connect use the login root and password raspbian
Congratulations to the team that makes the image netinstall for the great job done !
Sources :
- http://www.gluster.org/community/documentation/index.php/Building_QEMU_with_gfapi_for_Debian_based_systems
- https://github.com/debian-pi/raspbian-ua-netinst/issues/34