How to Write Image Files to SD Card with dd from Command Line of Mac or Linux

Apr 18, 2018 - 9 Comments

Terminal in macOS

Need to write an image file to an SD card? The command line ‘dd’ tool can do that for you, writing a disk image .img file to an SD card with minimal effort. A nice perk to using ‘dd’ for writing image files to an SD card is that it works for Mac OS as well as linux right out of the box, since it comes preinstalled there are no additional downloads or third party apps necessary to burn an image this way.


Using dd from the command line to write an image to an SD card is considered advanced, so this is best for users who are comfortable with the command line. For example, you might use this for writing a boot image for a RaspberryPi or some other quick-boot linux setup. A simpler option for most users is to use a third party app like Etcher to write an image to an SD card. Nonetheless, dd works just fine as long as you have an understanding of the command line. Using dd this way to write an SD card image is similar to how you’d use dd to burn an ISO to a USB drive or another disk image, except of course the file format is different and so is the target.

How to Write Image .img to SD Card via Command Line with dd

To get started, launch Terminal app from the /Applications/Utilities/ folder. Have your .img file to write somewhere easily found as well, we’re assuming here that it will be in your current working directory.

You must have the disk identifier for the target SD card you wish to write the img file to, thus we’ll first run diskutil list:

diskutil list

Locate the SD card in the diskutil list output and make note of the rdiskNUMBER disk identifier associated with the SD card. You will be using that as the SD card target for writing, as well as the file name of the disk image to write to the target SD card.

Use the following command syntax to write the .img image file to the SD card:

sudo dd if=NameOfImageToWrite.img of=/dev/rdiskNUMBER bs=1m

Replacing NameOfImageToWrite.img to image and path, and rdiskNUMBER with the target SD card disk identifier as found through ‘diskutil list’ output.

Hit return and enter the admin password to start the writing process, it may take a while to complete depending on the size of the image file and the speed of the SD card.

For example, if your disk image name is “RaspberryPiCustom.img” and the disk identifier is “/dev/rdisk4” then the command would look as follows:

sudo dd if=RaspberryPiCustom.img of=/dev/rdisk4 bs=1m

This should be fairly simple and straight forward to users who are already familiar with the command line.

Straying away from SD cards for a moment, another option which may work for some users is to burn disc images directly from the Mac Finder in modern Mac OS releases, which works fine if you have a CDRW or DVD-RW and are working with common disk image file formats too. Older Mac OS X release can use Disk Utility to burn ISO and other images as well, but modern versions of Disk Utility have lost that capability. Fortunately, the dd tool can burn ISO images from the command line as well as write an image to a USB drive.

Do you know of another approach to writing image .img files to an SD card via the command line or otherwise? Share your tips or comments below!

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

9 Comments

» Comments RSS Feed

  1. ComicSans says:

    If the .img file is in your Downlads folder,you have to use “cd Downloads” before using the command above.

  2. @Emeel The capital “M” does not work for me in macOS High Sierra 10.13.6. Causes this error:
    “dd: bs: illegal numeric value”

    Lowercase “m” works perfectly.

  3. Emeel says:

    Correction: change 1m to 1M in the example above as shown below:

    sudo dd if=RaspberryPiCustom.img of=/dev/rdisk4 bs=1M

  4. Sunshine says:

    FYI, for safety, it is always good to execute the “sync” command after “dd: is done and before unplugging the SD card.

    from the man page:
    sync — force completion of pending disk writes (flush cache)

    • San says:

      how to pass sync command after dd command ?

      • Eli says:

        sudo dd if=RaspberryPiCustom.img of=/dev/rdisk4 bs=1m && sudo sync

        the ‘&&’ means “if the previous command completes successfully run the following command”

        often running longer commands / with options you will want () around the ‘sudo sync’ part (and after the ‘&&’)

    • Chris Wolf says:

      @Sunshine you don’t need to “sync” because that’s used for flushing the filesystem cache to disk, however “dd” writes raw bytes directly to disk, hence the “/dev/rdisk*” (character device) rather then “/dev/disk*” (block device). There is no filesystem involved, therefore no cache to flush.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site