Run Raspberry PI on Desktop Linux
Although there is many articles on the web about easy setup QEMU for Raspberry PI software called "Raspbian" most of them are outdated. Many of them were written 3,4 years ago from now, and get failed when apply them to currently avilable Raspbian. Yesterday, I have found a Japanese blog describing this topic for most recent Raspbian 2014-09-09-wheezy.img, and it works perfect.
Here is the quick walkthough as memo:
Install Debian 8 (Jessie) on newly created virtual machine on Hyper-V, with 4GB RAM without dynamic memory option. No specific change for Debian 8 installation except for uncheck all software to be intalled, but ssh.
On root;
apt-get install sudo
#and then add myself to sudo group on /etc/groups file; then logout and back login
sudo apt-get qemu unzip
mkdir raspi
cd raspi
wget http://downloads.raspberrypi.org/raspbian_latest
unzip raspbian_latest
wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu
qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda 2014-09-09-wheezy-raspbian.img
It will up QEMU console, and give you root shell; Edit /etc/ld.so.preload on Raspbian and comment out 1st line. Add /etc/udev/rules.d/90-qemu.rules file with contents below;
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"
Finally, I can get Raspbian 2014-09-09.img up and running by;
qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda 2014-09-09-wheezy-raspbian.img
Expand image
Back to host Debian jessie, increase Raspbian image file;
qemu-img resize 2014-09-09-wheezy-raspbian.img +2G
And then back login on Raspbian; use fdisk
sudo fdisk /dev/sda
Take note where start block number for /dev/sda2, which was 122880 as of 2014-09-09-wheezy-raspbian.img. Delete 2nd partition, and create 2nd partition with using previous 122880 as start block instead of fdisk provided default (2048) but leave it default for last sector.
'w' command to write partition, and then reboot Raspbian.
Login to Raspbian, and run;
sudo resize2s /dev/sda2
That's it. You have enough room to install software on Raspbian on QEMU on desktop Debian Jessie.
Compile speed comparison
Build time for /opt/vc/src/hello_pi/rebuild.sh has compared with native raspbery pi (no overclocked) and Emulated version. Both are almost same performance.
|
QEMU |
R Pi |
Cross build |
real |
1m1.323s |
1m6.122s |
0m3.768s |
user |
0m51.830s |
0m54.100s |
0m2.120s |
sys |
0m7.880s |
0m4.800s |
0m0.468s |
References
https://blog.ymyzk.com/2013/12/raspberry-pi-qemu/
https://blog.ymyzk.com/2013/12/raspbian-image-resize/