How to Write Image Files to SD Card with dd from Command Line of Mac or Linux
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:
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!