emulate raspbian in qemu [debian]

qemu-raspbian-jessi

based on:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=37386

install git-core and qemu:
sudo apt-get install -y git-core qemu

install qemu from source 2.6: after install qemu-arm -cpu ? # will also list “arm1136” so this version works with pi
(make took round about an hour)
cd ~
wget http://wiki.qemu-project.org/download/qemu-2.6.0.tar.bz2
tar -xjvf "qemu-2.6.0.tar.bz2"
rm qemu-2.6.0.tar.bz2
cd ~/qemu-2.6.0
./configure
make
sudo make install

remove qemu from source:
based on:
https://mywebspace.wordpress.com/2006/04/27/make-uninstall-no-rule-to-make-target-uninstall
cd ~
sudo rm -r /usr/local/share/doc/qemu
sudo rm -r /usr/local/share/qemu
sudo rm /usr/local/share/man/man1/qemu.1
sudo rm /usr/local/share/man/man1/qemu-img.1
sudo rm /usr/local/share/man/man8/qemu-nbd.8
sudo rm /usr/local/share/man/man8/qemu-ga.8
sudo rm /usr/local/libexec/qemu-bridge-helper
cd /usr/local/bin
sudo rm qemu*
cd ~

preparing things:
cd
mkdir -p ~/qemu_vms/
cd qemu_vms/
wget http://vx2-downloads.raspberrypi.org/raspbian/images/raspbian-2015-05-07/2015-05-05-raspbian-wheezy.zip #latest wheezy image
unzip 2015-05-05-raspbian-wheezy.zip -d ~/qemu_vms/
git clone https://github.com/dhruvvyas90/qemu-rpi-kernel.git
cp ~/qemu_vms/qemu-rpi-kernel/kernel-qemu-3.10.25-wheezy ~/qemu_vms/kernel-qemu-3.10.25-wheezy
file ~/qemu_vms/2015-05-05-raspbian-wheezy.img

#From the output of the file command, take the partition 2 ‘startsector’ value an multiply by 512, and use this figure as the offset value in the mount command below.
#for me it was:bc 122880*512=62914560

sudo mount ~/qemu_vms/2015-05-05-raspbian-wheezy.img -o offset=62914560 /mnt
sudo sed -i -e 's/^/#/' /mnt/etc/ld.so.preload
#to put a ‘#’ infront of every line to comment it out

sudo nano /mnt/etc/udev/rules.d/90-qemu.rules

KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"

sudo umount ~/qemu_vms/2015-05-05-raspbian-wheezy.img

create a startscript:
touch ~/qemu_vms/selfmade_rpi_emulator.sh
chmod +x ~/qemu_vms/selfmade_rpi_emulator.sh
nano ~/qemu_vms/selfmade_rpi_emulator.sh

cd ~/qemu_vms/ && \
qemu-system-arm \
-kernel kernel-qemu-3.10.25-wheezy \
-cpu arm1176 \
-m 256 \
-M versatilepb \
-no-reboot \
-serial stdio \
-append "root=/dev/sda2 panic=1" \
-hda ~/qemu_vms/2015-05-05-raspbian-wheezy.img \
-redir tcp:5022::22 \
-redir tcp:5080::80

now you can run the script with:
~/qemu_vms/selfmade_rpi_emulator.sh

create a starter:
cd ~/.local/share/icons/
wget -O rpi.png https://www.raspberrypi.org/favicon.ico

nano ~/.local/share/applications/selfmade-rpi-emulator.desktop

[Desktop Entry]
Name=Selfmade Raspberry Pi Emulator
Comment=A Selfmade Raspberry Pi emulator
Exec=/home/xxUserxx/qemu_vms/selfmade_rpi_emulator.sh
Icon=/home/xxUserxx/.local/share/icons/rpi.png
Terminal=true
Type=Application
Categories=Utility;Application;Development;
StartupNotify=true

use the correct username in starter:
cd ~/.local/share/applications
sed -i 's/xxUserxx/'$USER'/' selfmade-rpi-emulator.desktop

if you start it and you have a german keyboard the password might be:
raspberrz #cause the y and z are inverted

startx #to boot into graphical userinterface from console
then it starts your graphical user interface
to exit mouse grap (ctrl+alt+G)

ssh into the emulated machine:# i had to wait 2 minutes after it was booted then i was able to login
ssh pi@127.0.0.1 -p 5022
or
ssh -p 5022 pi@localhost

installing webserver nginx:
sudo apt-get install nginx

start webserver nginx:
sudo service nginx start

now you can reach it in your webbrowser on your host machine at:
http://localhost:5080

more info about setting up nginx:
http://workshop.botter.ventures/2013/09/05/how-to-setup-a-web-server-with-nginxphp-on-raspberry-pi/

expand the size of .img:
based on:
http://linuxlugcast.com/?p=307
cd ~/qemu_vms/
qemu-img resize 2016-03-18-raspbian-jessie.img +1G
#this worked but the next steps failed for me.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s