Skip to content

Instantly share code, notes, and snippets.

@duquesnay
Forked from JasonGhent/pi_qemu.sh
Created March 7, 2017 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duquesnay/cc8a9287e59222645f323f297f15846f to your computer and use it in GitHub Desktop.
Save duquesnay/cc8a9287e59222645f323f297f15846f to your computer and use it in GitHub Desktop.
OSX raspberry pi emulation via QEMU. v2 attempt @ https://gist.github.com/JasonGhent/922f38f57c8cb77b10f3
# pulled from http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/
# expanded via http://superuser.com/questions/690060/how-to-enable-network-with-a-raspberry-pi-emulated-on-qemu
# tested with 2015-02-16-raspbian-wheezy.zip on OSX Mavericks
# OSX terminal
brew install qemu
# kernel-qemu is a linux kernel compiled with ARM1176 support.
# learn more here: http://xecdesign.com/compiling-a-kernel/
curl -OL http://xecdesign.com/downloads/linux-qemu/kernel-qemu
curl -o raspbian_latest.zip -L http://downloads.raspberrypi.org/raspbian_latest
unzip raspbian_latest.zip
mv 20* raspbian_latest.img
# not easily possible to mount ext4 to make the following change to the image, so we load the filesystem by running the image
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 raspbian_latest.img
# QEMU window (guest) - spawned by previous line
sed -i -e 's/^/#/' /etc/ld.so.preload
# TODO: clean this up with a bash var for path
touch /etc/udev/rules.d/90-qemu.rules
echo 'KERNEL=="sda", SYMLINK+="mmcblk0"' >> /etc/udev/rules.d/90-qemu.rules
echo 'KERNEL=="sda?", SYMLINK+="mmcblk0p%n"' >> /etc/udev/rules.d/90-qemu.rules
echo 'KERNEL=="sda2", SYMLINK+="root"' >> /etc/udev/rules.d/90-qemu.rules
exit
# OSX terminal (host)
# start the final raspberry pi image and specify a network mapping
# of local port 5022 to the pi's port 22
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 raspbian_latest.img -redir tcp:5022::22
# QEMU (guest) - raspberry pi emulation
# @FIXME
# for some reason it drops out of the startup procedure
# and dumps you to the terminal prematurely
exit
# if this is not first-run, we are done..
# else we are ushered into raspi-config (first run only)
# select "Finish" when done configuring
# OSX terminal (host)
ssh -p 5022 pi@localhost
# If we want to create a Heroku-like atmosphere, we can do
# with Dokku
## Still figuring this part out..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment