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 tar xvfj qemu-2.2.0.tar.bz2 
    • Compile and install Qemu
      cd qemu-2.2.0
      make install
  • Retrieve the special kernel for Qemu
  • Retrieve the last image of the network installation. Currently the version 1.0.6
    bzip2 -d raspbian-ua-netinst-v1.0.6.img.bz2
  • Retrieve the image to the address change script For my use I backed up its content in a file
    curl | tr -d 'r' >
    chmod 755
  • Install Kpartx if necessary
    apt-get install kpartx
  • Prepare the official image for use with Qemu
    ./ 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 :

You may also like...