Introduction: Restore DMG to SD Card - MAC OS X

Picture of 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:

Step 1: Step 1: Converting the DMG

Picture of 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

Picture of 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

Picture of 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)


jarts1 (author)2016-06-20

Because of the stupid way apple does this, I can not do this since the *.dmg I made is ~60gb and there is not enough hard disk space to do this. Does anyone has an idea for a workaround ?

rlenoil (author)jarts12017-01-16

Issue the following command to create a virtual disk in the system from the .dmg file, where path is the path to the file:

sudo hdiutil attach path -readonly -nomount -noverify

hdiutil will output the path of the virtual disk, something like:

/dev/disk4 Apple_partition_scheme

Then you can use the dd command as shown by other posters to perform the copy. When finished, remove the virtual disk with the following command, substituting the disk number returned by hdiutil attach for diskn:

sudo hdiutil detach diskn

blackjack75 (author)jarts12016-12-19

I have no solution if you have already done the backup using disk utility as hdiutil does not seem to appear to allow outputting to stdout, but if you use dd to both backup and restore you can use gzip in the process on both sizes and save a lot on disk space and possibly time.

To backup (assuming your device is in /dev/disk3 )

sudo dd if=/dev/rdisk3 bs=1m | gzip > mybackup.gz

To restore (after unmounting destination partitions but not ejecting device):

gzip -dc mybackup.gz | sudo dd of=/dev/rdisk3 bs=1m

Detailed explanation here:

blackjack75 (author)2016-12-19

Tips to speed up:

a) the ready-made script in the intro text does NOT pass the bs parameter. So it takes ages. I use bs=1M for high performance.

b) on OSX instead of /dev/disk3 you can use /dev/rdisk3 to get faster performance. Think of it when you you enter the destination device.

With both options (compared to dd without bs parameter to write a 64gb Lexus card) I changed the dd writing time from 16 hours 20 minutes

jmeyer15 (author)2016-12-01

You deserve a beer for this walkthrough, sir! I can't believe Disk Utility makes this so easy to image off an SD card, but not the other way.

Plugh (author)2016-02-15

Silly Apple. They make it easy to create a DMG from an SD, but have to go through hoops to go the other direction. Thanks for this how-to.

About This Instructable



Add instructable to: