Also at Deasil Works · txn2 · Plexara
Profiles GitHub · X · LinkedIn
Theme Light · Auto · Dark
Professional notes by Craig Johnston
long-form, short-form, working drafts · since 2008
VOL. XIX · MMXXVI
82 NOTES IN PRINT
FOLIO VIII 01 APR 2018 · 3 MIN · SHORT-FORM

Burn SD Images on MacOs

Use the command line to burn SD cards, easy and fast.

Diagram · folio viii
sequenceDiagram
    autonumber
    actor U as User
    participant T as Terminal
    participant DU as diskutil
    participant DD as dd
    participant SD as SD card

    U->>T: diskutil list
    T-->>U: device list
    U->>T: diskutil unmountDisk disk2
    T->>DU: unmount
    DU->>SD: eject volumes
    DU-->>T: ok

    U->>T: sudo dd if=image.iso of=rdisk2 bs=4m
    T->>DD: dd raw write
    DD->>SD: write blocks
    SD-->>DD: bytes written
    DD-->>T: records out

    U->>T: diskutil eject disk2
    T->>DU: eject
    DU-->>T: ok

Use your terminal to burn images fast and easy with dd. I do a lot of professional and hobby development for projects using devices such as Raspberry Pi, Orange Pi, Libre Computer, Tinker Board, etc. I run across a lot of tutorials with people downloading and using big GUI apps with clunky drag and drop interfaces to burn images.

It’s one command in your terminal. Technically, it’s three, but I don’t count listing and unmounting as the final act of burning.

§1 - List Disks

Insert your SD card and from the command line use diskUtil to lists all your drives.

diskUtil list

You are going to want to stay away from disk0 and disk1. You don’t want to kill your hard drive. Also, watch out for other attached storage. I can see my 32g mounted as /dev/disk3.

§2 - Unmount Disks

Unmount the SD card. In my case, it’s /dev/disk3. If you have additional attached storage, your SD card might be disk 4, 5, or higher.

diskUtil unmounDisk /dev/disk3

§3 - Burn Image

The last step is the fantastic little utility dd. dd copies any file to almost anywhere. We can use dd to stream the raw bytes from the image directed to our unmounted disk. On a Mac, the raw disk is accessed with an r in front of the device name. Raw access to my /dev/disk3 is /dev/rdisk3. Give three arguments.

ArgDescription / Value
if=In file: Specify the path to the file you want to send
of=Out file: Specify the path to the file to be written. Yes, the device is a file. Remember in Unil/Linux/Max everything is a file. So /dev/rdisk99 is a file (it’s a device, but we operate on it as a file)
bs=Block size: dd streams the data it reads from if= in chunks. Depending on the capabilities of the device writing larger chunks will speed up the write.

Example dd command to burn images:

sudo dd if=Armbian.img of=/dev/rdisk3 bs=5m

I find that a block size of 5m is the sweet spot for my card reader and the SD cards I use (SanDisk Ultra 32G).

You need to use sudo as only a privileged user can write directly to a device in this manner, which is good since you can easily overwrite your hard drive on disk 0 or 1.

Wait for dd to finish or hit Control-T from time-to-time for some status.

An 8GB image takes about 10-15 minutes on my workstation depending on the quality of the SD card. Cheap or damaged cards will take a very long time to write.

I have tried a few of the full GUI apps for burning but don’t seem to get the speed and control of just typing a few commands.

§Resources

← back to all notes