Skip to content

Instantly share code, notes, and snippets.

@sidneys
Last active September 14, 2019 02:24
Show Gist options
  • Save sidneys/656cce643d4e275ee2c00c0dbd566178 to your computer and use it in GitHub Desktop.
Save sidneys/656cce643d4e275ee2c00c0dbd566178 to your computer and use it in GitHub Desktop.
Emulating a Raspberry Pie on macOS Mojave 10.14+ (2019-09-11)

Emulating a Raspberry Pie on macOS Mojave 10.14+ (2019-09-11)

This guide explains how to emulate a Raspberry Pi and its ARM-based hardware stack under macOS Mojave – running the recent Raspbian Buster 1.

The light QEMU open-source Quick Emulator framework, will be used.

Homebrew as well as some basic level shell-fu is required.


Overview

  1. Installing required Software
  2. Create the System Disk Image
  3. Running QEMU
  4. Fixing the System Partition Layout
  5. Author

Installing required Software

Create a working directory at /Users/username/qemu.

$ mkdir ~/qemu

Open a Terminal and install Homebrew.

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install qemu via Homebrew.

$ brew install qemu

Grab the operating system by downloading 3 separate components: Kᴇʀɴᴇʟ, Sʏsᴛᴇᴍ Iᴍᴀɢᴇ und Dᴇᴠɪᴄᴇ Tʀᴇᴇ Bɪɴᴀʀʏ.

$ cd ~/qemu
$ curl --remote-name-all --location \
    https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.14.79-stretch \
    https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/versatile-pb.dtb \
    https://downloads.raspberrypi.org/raspbian/images/raspbian-2019-07-12/2019-07-10-raspbian-buster.zip

Create the System Disk Image

Unpack the operating system disk image.

$ unzip ~/qemu/2019-07-10-raspbian-buster.zip

Increase the disk size to 8GB (or larger – as required).

$ qemu-img resize -f 'raw' ~/qemu/2019-07-10-raspbian-buster.img '8G'

Starting the Emulator

Start QEMU by running `qemu-system-arm.

$ qemu-system-arm \
  -kernel ~/qemu/kernel-qemu-4.14.79-stretch \
  -dtb ~/qemu/versatile-pb.dtb \
  -drive file=~/qemu/2019-07-10-raspbian-buster.mod.img,index=0,media=disk,format=raw \
  -cpu 'arm1176' \
  -m '256' \
  -M 'versatilepb' \
  -serial 'mon:stdio' \
  -net 'nic' \
  -net 'user,hostfwd=tcp::5022-:22' \
  -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' \
  -no-reboot \
  -vga 'std'

When the boot process concludes after a few minutes, log in using the default credentials:

  • user: pi, password: raspberry).

Fixing the System Partition Layout

In order to access the entirety of the free space just assigned to the disk image, its operating system needs to know about it. We'll now slightly adjust the filesystem partition layout from within the emulator, using the raspi-config utility .

By default, raspi-config refuses its service because it cannot find any SD-card based filesystems (the Pi's main means of storage). Thus, we'll apply a small tweak to make it comply.

Create a backup of raspi-config:

$  cp -v /usr/bin/raspi-config /usr/bin/raspi-config.backup

Find all textual occurences to SD-card-type filesystems (/dev/mmcblk0p) within /usr/bin/raspi-config and replace them with references to the standard filesystem type, /dev/sda:

$  sed -E 's/mmcblk0p?/sda/' /usr/bin/raspi-config

Now, start raspi-config:

$  sudo /usr/bin/raspi-config

Within raspi-config...

  • Select [Aᴅᴠᴀɴᴄᴇᴅ Options], then [Exᴘᴀɴᴅ Fɪʟᴇsʏsᴛᴇᴍ], then confirm.

  • Wait until after the resizing process has finished.

  • Select [Qᴜɪᴛ] and confirm the reboot request.

Contribute Contributions Wanted

Any suggestions? Drop me an e-mail, create a document fork or

Author

Copyright © 2019 sidneys.

Licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.


Footnotes

  1. https://www.raspberrypi.org/blog/buster-the-new-version-of-raspbian/

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