Skip to content

Instantly share code, notes, and snippets.

@thomasvanta
Last active January 1, 2019 16:06
Show Gist options
  • Save thomasvanta/29e26ae05237e3f87cd3eea1211145af to your computer and use it in GitHub Desktop.
Save thomasvanta/29e26ae05237e3f87cd3eea1211145af to your computer and use it in GitHub Desktop.
Raspi emulation for osx with QEMU

Install QEMU OSX port with ARM support

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
&& brew update 
&& brew install qemu 
export QEMU=$(which qemu-system-arm) 
brew install wget

get stretch kernel, device tree and raspbian image

wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.9.59-stretch
export RPI_KERNEL=./kernel-qemu-4.9.59-stretch
wget https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/versatile-pb.dtb
wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2018-11-15/2018-11-13-raspbian-stretch.zip
unzip 2018-11-13-raspbian-stretch.zip
export RPI_FS=./2018-11-13-raspbian-stretch.img

Here make sure to reference the .img file in the last EXPORT and not the .zip file as per original instructions.

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 \
-dtb versatile-pb.dtb \
-M versatilepb \
-no-reboot -serial stdio \
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" \
-drive "file=2018-11-13-raspbian-stretch.img,index=0,media=disk,format=raw"

So at this point you should get the emulator window and a terminal you can add the following commands in.

sed -i -e 's/^/#/' /etc/ld.so.preload
sed -i -e 's/^/#/' /etc/ld.so.conf
sed -i -e 's/^/#/' /etc/fstab

Exit that and the next command will start the actual raspberry pi emulation.

Emulate Raspberry Pi

$QEMU \
-kernel $RPI_KERNEL \
-cpu arm1176 -m 256 \
-dtb versatile-pb.dtb -M versatilepb \
-no-reboot -serial stdio \
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \
-drive "file=2018-11-13-raspbian-stretch.img,index=0,media=disk,format=raw" \
-net user,hostfwd=tcp::5022-:22 -net nic

Available over network with this SSH command.

Login to Raspberry Pi

ssh -p 5022 pi@localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment