Virtualize Raspberry Pi with QEmu under Debian in Virtualbox

If you are on this site it is surely for a tutorial. You may also want to know what you could do with this little machine. With Virtualbox you can test before you buy !

rpi+vb-300x187

It is a moment that I looked to see how to make the tests without having to redo images every two minutes. J’avais en tête une virtualisation qui facilite l’usage du Raspberry sans Raspberry 🙂 J’ai jamais réussi à trouver un moyen de le faire de simplement. Until I found a post on the forum of the Raspberry.

What surprised me it is that in the end the implementation is really simple ! So here is how I proceeded to install a distribution Moebius in

A big thank you to tonyhughes for explanations !

  1. I pass the explanations on how to install VirtualBox and install Ubuntu or Debian in VirtualBox. I went to a machine with Debian installed :Debian__Running_
  2. In your virtual machine, update all packages. From a console (as well, you can do it from:
    sudo apt - get update sudo apt - get upgrade
  3. My choice was to install all of the data (kernel and image) in my user's home. You choose where you want to put them. So I created a directory QEMU
    mkdir qemu cd qemu
  4. In this directory you install kernel that will be used by Qemu. For this you can download it at this address : http://xecdesign.com/downloads/linux-qemu/kernel-qemu (I've not managed nor too sought by wget).You should therefore with now in the directory QEMU created in step 2, the file kernel-qemu.
  5. Then you copy the image you want to always run in this directory QEMU. I have copied Raspbian and Moebius.Capture_d_écran_02_06_13_18_26-2
  6. Now we are going to mount the partition ext4 of your image to make a small modification on the filesystem. For this, We need to know where the beginning of the partition. Use the file command then take the start sector that multiply by 512 :capture_d_c3a9cran_02_06_13_18_28-2
    Here the beginning of the second partition is 122880. We therefore need to pass to the command Mount the parameter 62914560.
  7. Mount the partition (Here I always use Moebius) :
    Mount /home/chris/qemu/moebius-1.1.1.img o offset = 62914560/mnt
  8. Edit the /mnt/etc/ld.so.preload file to comment line. Add a # beginning of line, It is sufficient to disable the loading of the library ELF.
    #/usr/lib/arm-Linux-gnueabihf/libcofi_rpi.so
  9. Unmount the image
    umount/mnt
  10. Install Qemu
    apt - get install qemu-system
  11. Run Qemu with the image you want to emulate
    sudo qemu-system-arm - kernel/home/chris/qemu/kernel-qemu - cpu arm1176 m 256 -M versatilepb -no-reboot -serial stdio -append "root = / dev/sda2 panic = 1" -hda /home/chris/qemu/moebius-1.1.1.img - redir tcp:5022::22
  12. When you first launch you will get an error on the integrity of the partition. You will end up with a prompt asking for the password root. You grab. Attention it is the qwertz !Check the disk
    fsck/dev/sda2

    Then shut down the system

    halt
  13. You can now restart Qemu with the same command as in step 11 :
    sudo qemu-system-arm - kernel/home/chris/qemu/kernel-qemu - cpu arm1176 m 256 -M versatilepb -no-reboot -serial stdio -append "root = / dev/sda2 panic = 1" -hda /home/chris/qemu/moebius-1.1.1.img - redir tcp:5022::22
  14. You should arrive at the prompt without errorDebian__Running_

So now that you have your system launched, several constraints :

  • It's emulation in virtualization. It's not top but for an ARM processor that seems to be enough (I did not 50 tests). It works
  • You cannot extend the partition because the image file can be expanded. For example, you can copy the img on a SD card, make an image of the SD and use this new image.

I have not tested with Raspbian but initially the performance under X are not bad.

You can test !

 

Like this article ? Bear with me on patreon!

You may also like...