Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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..
@JasonGhent

This comment has been minimized.

Copy link
Owner Author

@JasonGhent JasonGhent commented Apr 6, 2015

# vagrant install ubuntu to use for custom pi linux kernel
# details:
#  - http://sourabhbajaj.com/mac-setup/Vagrant/README.html
#  - http://stevef1uk.blogspot.co.uk/2014/06/here-be-dragons-how-to-cross-compile.html
#  - http://stevef1uk.blogspot.co.uk/2014/06/how-to-run-docker-on-raspberry-pi.html
brew tap phinze/homebrew-cask && brew install brew-cask
brew cask install virtualbox vagrant vagrant-manager
vagrant box add precise64 http://files.vagrantup.com/precise64.box
@jasonlagaac

This comment has been minimized.

Copy link

@jasonlagaac jasonlagaac commented Oct 28, 2015

kernel-qemu is available here: https://github.com/dhruvvyas90/qemu-rpi-kernel

@mariohmol

This comment has been minimized.

Copy link

@mariohmol mariohmol commented Feb 13, 2016

after all working.. can i open .img file and save all files in a SD card, then just input in raspberrypi?

@mariohmol

This comment has been minimized.

Copy link

@mariohmol mariohmol commented Feb 14, 2016

Tested using both kernels and the latest raspbian img (2016-02-09-raspbian-jessie.img).
It closes the emulation window with message: "Kernel panic - not syncing : Attempted to kill init"

Looking in internet people say that is a problem with not compatible kernel, but image and kernel are same version 4.1.

Any tips? @jasonlagaac

Tested those commands:

  • qemu-system-arm -kernel kernel-qemu-4.1.13-jessie -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda 2016-02-09-raspbian-jessie.img
  • qemu-system-arm -kernel kernel-qemu-4.1.7-jessie -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda 2016-02-09-raspbian-jessie.img
@dpishchukhin

This comment has been minimized.

Copy link

@dpishchukhin dpishchukhin commented Mar 6, 2016

@mariohmol update image, edit /etc/ld.so.preload and comment line #/usr/lib/arm-linux-gnueabihf/libarmmem.so

source: http://blog.3mdeb.com/2015/12/30/emulate-rapberry-pi-2-in-qemu/

@MrDwZ

This comment has been minimized.

Copy link

@MrDwZ MrDwZ commented Apr 21, 2016

I wanna ask how to make the network able to work : (

@JPaulMora

This comment has been minimized.

Copy link

@JPaulMora JPaulMora commented Apr 29, 2016

Hello guys! Check this project out: Raspi Simulator (not mine). If you see in package contents, its all shell scripts in a wrapper.

@qris

This comment has been minimized.

Copy link

@qris qris commented Jun 15, 2017

I wasn't able to get a working init using this process. I had more luck with these instructions, although they are incomplete, and I don't have permission to edit the page. I had to mount the Ubuntu cloud image using qemu-nbd xenial-server-cloudimg-arm64-uefi1.img --connect=/dev/nbd0 and manually add a password for the ubuntu account as shown here, and wait for cloud-init to time out, before I could log into the machine and apt remove cloud-init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment