Skip to content

Instantly share code, notes, and snippets.

@heitara
Last active May 10, 2024 13:13
Show Gist options
  • Save heitara/a41baa9e2da6738c0107b8216e9ef2a5 to your computer and use it in GitHub Desktop.
Save heitara/a41baa9e2da6738c0107b8216e9ef2a5 to your computer and use it in GitHub Desktop.
How to restor dmg (copy of FAT sdcard) to a new sdcard

How to restore an image (.dmg) to a sdcard?

The image you want to use when recovering should be crated earlier. The sdcard should be empty or the data on it will be lost.

First, the image should be converted to a pure image. This can be done with the following command:

hdiutil convert sdcard_image.dmg -format UDTO -o sdcard_pure_image.img

Usually the above process creates the following file sdcard_pure_image.img.cdr. Use the following command to change the extension (You can skip this step, but the rest of the commands should be adjusted.)

mv sdcard_pure_image.img.cdr sdcard_pure_image.img

Then you have to find the correct device id. This can be done using the Disk Utility app. Select the mounted card and check what's written next to Device label. It should be something like diskX, where X is a number.

! Create a backup of the sdcard information. Don't forget to unmount the sdcard (don't eject it).

Use the following command to start the cloning process:

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

Once the process finishes, the sdcard should contian the image. Keep in mind that the size of the image and the card should match or the card size should be larger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment