≡ Menu

How To Create Disk Image on Mac OS X With dd Command

How do I create or write to images to disk on Apple Mac OS X Unix operating system with dd command?

You can use dd command to:

  1. Create new disk images from USB or SD card
  2. Write images to disk or USB or SD card

You also need to use diskutil command manipulates the structure of local disks including listing and unmouting disks before you create or write images to disk. Please be careful when running the following commands, as you might destroy important data or disk.

1. Create disk image with dd command

Open the Terminal application and type the following command to list disks:
$ diskutil list
Sample outputs:

Fig.01: Insert in your SD card, or USB pen/HDD, and see  /dev/diskN name

Fig.01: Insert in your SD card, or USB pen/HDD, and see /dev/diskN name


In this example my SD card size is 4GB and located at /dev/disk2.

2. Unmount the disk

Unmount the disk called /dev/disk2:
$ diskutil unmountDisk /dev/disk2
Sample outputs:

Unmount of all volumes on disk2 was successful

3. Create the disk image with dd

Finally create the disk image of the entire disk /dev/disk2:
$ sudo dd if=/dev/disk2 of=backup.my.sdcard-18-oct-2015.img.dd bs=512
OR
$ sudo dd if=/dev/disk2 of=backup.my.sdcard-18-oct-2015.img.dd bs=1m
OR
$ sudo dd if=/dev/disk2 of=foo.bar.img.dd bs=64k
Sample outputs:

Password:
60504+0 records in
60504+0 records out
3965190144 bytes transferred in 839.664927 secs (4722348 bytes/sec)

You can create compressed disk image as follows:
$ sudo dd if=/dev/disk2 bs=64K | gzip -c > backup.disk.img.dd.gz
Where,

  • dd : Command name
  • if=/dev/disk2 : Input disk name
  • of=backup.my.sdcard-18-oct-2015.img.dd : Output image name
  • bs=64k or bs=1m or bs=512 : Set both input and output block size to n bytes.
  • gzip -c > backup.disk.img.dd.gz : Create compressed disk image using gzip

You can verify your disk with file command:
$ file disk-name-here.img.dd

disk-name-here.img.dd: x86 boot sector; partition 1: ID=0xc, starthead 130, startsector 8192, 114688 sectors; partition 2: ID=0x83, starthead 165, startsector 122880, 6277120 sectors, code offset 0xb8

How do I write dd images to disk again?

The syntax is as follows:
$ diskutil list
$ diskutil unmountDisk /dev/disk2
$ sudo dd if=backup.my.sdcard-18-oct-2015.img.dd of=/dev/disk2
### Restores compressed image and write /dev/disk2 ###
$ sudo sh -c 'gunzip -c backup.disk.img.dd.gz | dd of=/dev/disk2'

See dd command man page for more info.

Not a fan of command line?

You can use ‘Disk Utility’ GUI tool to create and restore images. First ‘Open Disk Utility’ by visiting the Applications > Utilities folder:

Fig. 02: Disk utility in action

Fig. 02: Disk utility in action

Choose File > New > Image from “Untitled”. Next, enter a name for the disk image, then choose where to save it:

Fig.03: Saving SD card image

Fig.03: Saving SD card image

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 5 comments… add one }
  • Michael Barto October 27, 2015, 3:10 pm

    This is great. But in you GUI example, you left out how to write the image to say a flash drive. My problem is simple. How do I copy a Bootable MaxOSX flash drive to another MacOSX flash drive and it remain bootable. Can that be done in the GUI?

    • Don Baldwin November 25, 2015, 8:19 pm

      Exactly, I need to copy a Mac Disk Image on a hard drive to a flash drive. With the “restore disk image” function completely omitted or hidden in the new and (ahem) “improved” disk utility, I am completely dead in the water with a Mac I am unable to resurrect. I found this article unhelpful and incomplete. Does ANYBODY out there know how to fashion a quick tutorial to accomplish this and be both thorough and comprehensive UNLIKE this article? Please? Anyone?

      • Jan vda January 27, 2016, 2:41 pm

        Try out ApplePi-Baker
        Its a simple GUI based tool to create / flash images of disks and works with pretty much all file systems etc and its so easy to use!

        • Mario October 8, 2016, 9:51 pm

          Thanks for this tip! :D

  • Craig Lillard February 9, 2017, 6:00 am

    Howdy. I just ran this command: sudo dd if=/dev/disk5 of=/dev/disk1 bs=131072

    It asked me for my password and I entered it and then the cursor moved down to the next line and stayed there.

    Does that sound right? Is it frozen or just working? Is there no progress indicator?
    Thanks!
    C

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: