Skip to content

Instantly share code, notes, and snippets.

@jordelver
Created July 18, 2012 22:29
Show Gist options
  • Star 90 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save jordelver/3139365 to your computer and use it in GitHub Desktop.
Save jordelver/3139365 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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
Copy link

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
Copy link

Well done, its much safer now. :)

@xuanyu-h
Copy link

thank you very much:smile:

@TechNickAI
Copy link

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

@spitfireinno
Copy link

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

@tthayer
Copy link

tthayer commented Jun 27, 2014

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

@jakesylvestre
Copy link

unmounting requires sudo privileges

@johanroug
Copy link

@alexserver
Copy link

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

@davidrhoden
Copy link

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

Copy link

ghost commented Dec 15, 2015

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

@gk-brown
Copy link

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

@phmullins
Copy link

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
Copy link

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

@bartvanderwal
Copy link

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
Copy link

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

@stevegoossens
Copy link

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
Copy link

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