Raspberry Pi: Write SD Card Images using OS X Command Line

Goal: Copy a system image onto an SD card, without installing any extra software on your Mac.

Difficulty: Intermediate

Required Hardware:

  • OS X based computer
  • SD card reader (built in to your computer, or USB based)
  • SD card.

Required Software: Nothing extra!

If you prefer to use a nice graphic interface for putting images on SD cards, and don’t mind installing a small application, consider using the recipe Raspberry Pi: Write SD Card Images Using Etcher instead.

First - Find the SD card’s disk number

Before you insert your SD card… (If you already did, eject it in the Finder,
then physically remove it.)

Open terminal run:

diskutil list | grep ^/dev

You’ll see something like:

/dev/disk0 (internal, physical):
/dev/disk1 (synthesized):

These are the disk volumes on your computer. You may have more or just one.

Now, insert your SD card into a SD card reader, and into your computer. If your
computer asks you about formatting it, just choose “Ignore”.

Run the same command again:

diskutil list | grep ^/dev

You should see one more line:

/dev/disk0 (internal, physical):
/dev/disk1 (synthesized):
/dev/disk2 (internal, physical):

Note which is the new one. In this case /dev/disk2 is the new disk,
and represents the SD card. It’s disk number is 2. The disk number for your
SD Card may be different.

In the commands that follow, when you see disk# replace the # with the
disk number for the SD card.

Second - Copy the image to the SD card

Now run the following, making double sure you’re using the right number for # before you hit enter:

diskutil unmountDisk /dev/disk#

Double check you’ve nothing bad: Look in the Finder: See all your normal disks? Good! (Something missing? You’ve used the wrong #… Use Disk Utility app to remount it… or just reboot.)

cd ~/Downloads
unzip ~/Downloads/2018-04-18-raspbian-stretch-lite.zip
sudo dd bs=1m if=2018-04-18-raspbian-stretch-lite.img of=/dev/rdisk# conv=sync
rm ~/Downloads/2018-04-18-raspbian-stretch-lite.img

Your downloaded image file might be named differently. Also take careful note that
on the second line there is a sneaky r in front of disk#. Double check you’ve used the right number for # here, too.

This will take a bit of time. If you are worried, type CTRL-T and dd will
print some cryptic indication of it’s progress.

When it is done, OS X will automatically mount the newly imaged disk.

Do not eject the SD Card yet…

Third - Enable ssh

Actually, this is optional if you are going to put a display and keyboard on the Pi for your first boot. And it may not apply to other kinds of system images at all.

After the burning, the disk will be mounted at /Volumes/boot. Run this:

touch /Volumes/boot/ssh

Fourth - Eject!

Now eject the SD Card, either in the Finder, or from your terminal, like so:

diskutil eject /dev/disk#
1 Like