Introduction: Restore DMG to SD Card - MAC OS X

After making a backup of a SD Card, and trying to restore it using 'Disk Utility' you may have some issues during the process like:

Error: Could not validate source - Invalid argument

To solve this, there is this 3 step process that you can perform in the terminal.

If you do not want to run this steps you can just run a script I made:

https://github.com/magamig/dmgtosd

Step 1: Step 1: Converting the DMG

First you need to convert the .dmg image to a raw image:

hdiutil convert foo.dmg -format UDTO -o bar.img

(Note: change directories to the one with the dmg file (if in Desktop do first: 'cd Desktop'), and change 'foo' and 'bar' with the filename)

Step 2: Step 2: .CDR (raw Image) to .IMG

In the last step we created a file with .cdr extension but it is a raw image. So you can change the file extension to .img, by easily renaming the file name:

mv bar.img.cdr bar.img

Step 3: Step 3: Copy IMG to SD Card

Before this step unmount all the partitions of the SD Card, or you will get this error:

dd: /dev/diskX: Resource busy

Finally you can copy the image to your SD card using dd:

sudo dd bs=2048 if=bar.img  of=/dev/diskX

(Substitute X with the disk num, you can find this under: Disk Utility -> Select the SD Card on the right -> Info (top button), and in the window you can see the disk number)

And patiently wait for it to end, if it takes more than 2 hours, just check if it is complete by removing the SD Card and reinserting it, if not try this command in the terminal again. But you really need to wait... like a lot... not kiddin (depends on the SD Card size)