Skip to content

Building a virtual Raspberry Pi

gunnar edited this page Apr 22, 2017 · 6 revisions

this is a D R A F T !!!

  • instruction shown here still have to be generalized
  • also it's grossly incomplete and not well structured yet

#1) get a raspbian image

save it on your host and unpack it

  • mkdir ~/rpi
  • cd ~/rpi
  • wget http://director.downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-04-10/2017-04-10-raspbian-jessie-lite.zip .
  • unzip 2017-04-10-raspbian-jessie-lite.zip

#2) tweak the image file to be working in a virtual environment (qemu/kvm)

  • $ sudo mount ~/rpi/2017-03-02-raspbian-jessie-lite.img -o loop,offset=70254592 /mnt
  • $ sudo vim ld.so.preload (and comment out the line in there)
  • $ cd /
  • $ sudo umount /mnt

#3) get a custom kernel for the virtual rpi we will be running

Raspbian kernel for qemu and howto: https://github.com/dhruvvyas90/qemu-rpi-kernel

we will be using the newest one (kernel-qemu-4.4.34-jessie)

wget https://raw.githubusercontent.com/dhruvvyas90/qemu-rpi-kernel/master/kernel-qemu-4.4.34-jessie

#4) run the virtual machine (using the kernel from #3)

  • $ qemu-system-arm -kernel /path/to/kernel-qemu-4.4.34-jessie -cpu arm1176 -m 256 -M versatilepb -append "root=/dev/sda2 panic=1 $ rootfstype=ext4 rw" -drive "file=/path/to/rpi/2017-04-10-raspbian-jessie-lite.img,index=0,media=disk,format=raw" -nographic -vnc :0

#5) Access your virtual Raspberry Pi

doubled port forwarding has to be applied

  • from another terminal
  • $ ssh user@server -L 9999:localhost:9999 (access the host)
  • $ ssh coder@10.1.80.203 -L 9999:localhost:5900 (access virtual rpi)