Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to write an image file to an SD card under Mac OS X (for Raspberry Pi)

Find the SD card device

In this case, the SD card is /dev/disk4. DO NOT get this wrong or you may destroy all the data on the wrong disk/card/drive.

diskutil list

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *160.0 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            159.2 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *160.0 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS 160GB                   159.7 GB   disk1s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *320.1 GB   disk2
   1:                        EFI                         209.7 MB   disk2s1
   2:          Apple_CoreStorage                         319.6 GB   disk2s2
   3:                 Apple_Boot Boot OS X               134.2 MB   disk2s3
/dev/disk3
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Backup                 *319.3 GB   disk3
/dev/disk4
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *3.9 GB     disk4
   1:             Windows_FAT_32                         98.6 MB    disk4s1
   2:                      Linux                         1.9 GB     disk4s2

Umount the disk, NOT eject

diskutil unmountDisk /dev/disk4

Write the image to the SD card with dd

dd if=/path/to/image.img of=/dev/rdisk4 bs=1m
@zmilojko

This comment has been minimized.

Copy link

@zmilojko zmilojko commented Oct 4, 2013

I got the permission denied when doing the dd. Banged my head a bit until I googled out the following: SD card is probably write protected! Once I removed the pin, it worked like a charm. Playing with my Raspberry right now!

@5worx

This comment has been minimized.

Copy link

@5worx 5worx commented Jan 8, 2014

Thank you for this. It saves me time. It's the most comfortable way for me. :D Happy Hacking!

@Hansaplast

This comment has been minimized.

Copy link

@Hansaplast Hansaplast commented Jan 29, 2014

I created a free tool for MacOS X users: ApplePi-Baker.
Just takes a click or two and you're done.
http://www.tweaking4all.com/hardware/raspberry-pi/macosx-apple-pi-baker/

(my apologies if mentioning this here is inappropriate - though other Mac users might benefit from it as well)

@jeeyessos

This comment has been minimized.

Copy link

@jeeyessos jeeyessos commented Feb 10, 2014

Well done, its much safer now. :)

@xuanyu-h

This comment has been minimized.

Copy link

@xuanyu-h xuanyu-h commented Mar 18, 2014

thank you very much😄

@gorillamania

This comment has been minimized.

Copy link

@gorillamania gorillamania commented May 24, 2014

Thanks a bunch - worked for me! Have 1 coffee with @changetip

@spitfireinno

This comment has been minimized.

Copy link

@spitfireinno spitfireinno commented Jun 5, 2014

On OSX, the argument must be -1M not -1m. Otherwise fabulous -- thank you.

@tthayer

This comment has been minimized.

Copy link

@tthayer tthayer commented Jun 27, 2014

spitfireinno: Using -1M threw an error in OSX 10.9 whereas -1m worked fine.

@archivedaccount

This comment has been minimized.

Copy link

@archivedaccount archivedaccount commented Jul 1, 2014

unmounting requires sudo privileges

@johanroug

This comment has been minimized.

@alexserver

This comment has been minimized.

Copy link

@alexserver alexserver commented May 16, 2015

maybe sudo dd ? I got the error message 'permission denied' without sudo.

@davidrhoden

This comment has been minimized.

Copy link

@davidrhoden davidrhoden commented Aug 1, 2015

=1m, -1m, or -1M?

@CJEdgerton

This comment has been minimized.

Copy link

@CJEdgerton CJEdgerton commented Dec 15, 2015

Why no -v flag ... ¯\ (°_o) /¯

@gk-brown

This comment has been minimized.

Copy link

@gk-brown gk-brown commented Apr 19, 2016

@alexserver - I also had to use sudo with dd to get it to work.

@phmullins

This comment has been minimized.

Copy link

@phmullins phmullins commented May 4, 2016

How would you write to /dev/disk4/disk4s2 only? I have an image that someone made from the 1.9 GB Linux partition and I need to write it to the same partition on my SD card. Any suggestions?

@phmullins

This comment has been minimized.

Copy link

@phmullins phmullins commented May 4, 2016

Never mind. I finally figured it out. Writing to /dev/disk4s2 did the trick. :-)

@bartvanderwal

This comment has been minimized.

Copy link

@bartvanderwal bartvanderwal commented Feb 25, 2018

@Hansaplast With all due respect for your work and skills, but I would disadvise ANYBODY to download and use apps from the internet. They are not 'AppStore' approved. I tend to make exception when something looks trustworthy, but most certainly when the app requires you to provide it with the admin (sudo) password like you do this is a big nono. This is security lesson 1, first 5 minutes.

Also I can't find the source of your program on GitHub or anything. That way I could check the source and build it myself.
I understand why your program needs it, but is there no way around this? I'm sticking with using dd..

@ysennoun

This comment has been minimized.

Copy link

@ysennoun ysennoun commented May 12, 2018

Thank you very much, it was very helpful ;) !

@stevegoossens

This comment has been minimized.

Copy link

@stevegoossens stevegoossens commented Aug 26, 2018

Etcher: https://www.raspberrypi.org/documentation/installation/installing-images/README.md
OSX GUI / CLI: https://www.raspberrypi.org/documentation/installation/installing-images/mac.md

I ended up using CLI (my preference) and raw disk mode for speed:

diskutil list
# insert microSD in SD adapter, and then:
diskutil list
# see that the microSD is disk2, and:
diskutil unmountDisk /dev/disk2
xz -d kali-linux-2018.2-rpi3-nexmon.img.xz
sudo dd bs=1m if=kali-linux-2018.2-rpi3-nexmon.img of=/dev/rdisk2 conv=sync
@bradshawlupton

This comment has been minimized.

Copy link

@bradshawlupton bradshawlupton commented May 21, 2019

I like to add in a time cmp /dev/diskX ./image.img -n (size of image.img). at the end and be amazed at a perfect comparison. Also, if the comparison is NOT perfect, often, doing the dd a second third or fourth time, makes the bits finally correct..... sometimes not!

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