Skip to content

Instantly share code, notes, and snippets.

@Geek-MD
Forked from hfreire/qemu_osx_rpi_raspbian_jessie.sh
Last active December 30, 2020 10:51
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Geek-MD/d0d1506a91855d7a022b8cc8d0576b79 to your computer and use it in GitHub Desktop.
Save Geek-MD/d0d1506a91855d7a022b8cc8d0576b79 to your computer and use it in GitHub Desktop.
How to emulate a Raspberry Pi (Raspbian Jessie) on Mac OSX (Sierra)
# Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install QEMU OSX port with ARM support
brew install qemu
export QEMU=$(which qemu-system-arm)
# Dowload kernel and export location
brew install wget
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.4.34-jessie
export RPI_KERNEL=./kernel-qemu-4.4.34-jessie
# Download filesystem and export location
wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-11-29/2016-11-25-raspbian-jessie.zip
unzip 2016-11-25-raspbian-jessie.zip
export RPI_FS=./2016-11-25-raspbian-jessie.img
# Tweak filesystem: start qemu with init flag, switch to guest window to execute tweak and close window afterwards
$QEMU -kernel $RPI_KERNEL \
-cpu arm1176 -m 256 \
-M versatilepb -no-reboot -serial stdio \
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" \
-drive "file=$RPI_FS,index=0,media=disk,format=raw"
sed -i -e 's/^/#/' /etc/ld.so.preload
sed -i -e 's/^/#/' /etc/fstab
# Emulate Raspberry Pi
$QEMU -kernel $RPI_KERNEL \
-cpu arm1176 -m 256 \
-M versatilepb -no-reboot -serial stdio \
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \
-drive "file=$RPI_FS,index=0,media=disk,format=raw" \
-net user,hostfwd=tcp::5022-:22
# Login to Raspberry Pi
ssh -p 5022 pi@localhost
# Referenced from OSX raspberry pi emulation via QEMU - https://gist.github.com/JasonGhent/e7deab904b30cbc08a7d
# Referenced from Emulating Jessie image with 4.x.xx kernel - https://github.com/dhruvvyas90/qemu-rpi-kernel/wiki/Emulating-Jessie-image-with-4.x.xx-kernel
@markph0204
Copy link

Note the step:
export QEMU=$(which qemu-system-arm)

May return results you did not intend. For example, for me it returns:
qemu-system-arm is /usr/local/bin/qemu-system-arm

Which cannot be executed causing a failure when invoking $QEMU

I believe it may be due that I am using a version of bash from brew that is not the original bash version:

bash --version
GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin15.6.0)

@davibe
Copy link

davibe commented Jul 24, 2018

in the first setup steps i needed to do

touch /boot/ssh

in order to enable ssh

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