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 (macOS) Unix operating system with dd command?

You can use dd command on mac OS to:

  1. Create new disk images from USB or SD card
  2. Write images to disk or USB or SD card
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements macOS or older OS X
Est. reading time 2m
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.

WARNING: Please be careful when running the following commands, as you might destroy essential data or disk. Always keep verified backups for your Mac.

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

The procedure is as follows:

  1. Open the Terminal app
  2. Get disk list with the diskutil list
  3. To create the disk image: dd if=/dev/DISK of=image.dd bs=512
  4. To write the disk image: dd if=image.dd of=/dev/DISK

Let us see all commands in details.

1. Create disk image with dd command

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

How To Create Disk Image on Mac OS X With dd Command - 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
Here is what we see:

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 bs=512
$ sudo dd if=/dev/disk2 bs=1m
$ sudo dd if=/dev/disk2 bs=64k
It will take some time, and you won’t see any updates on the screen. You can press the ctrl+t (hold control key and press t) to see dd command progress on macOS:

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

  • dd : Command name
  • if=/dev/disk2 : Input disk name
  • : 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 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

Etcher app

Etcher is an SD card flasher app that is simple for end users, extensible for developers, and works on any platform including macOS. However, it is written in JS, HTML, node.js and Electron. So if you want to download external and fat app go here. Personally, I recommend and use the CLI or inbuilt apps.

Summing up

You leaned how create disk image on Mac OS using the dd command and GUI apps.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 15 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
15 comments… add one
  • Michael Barto Oct 27, 2015 @ 15:10

    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 Nov 25, 2015 @ 20:19

      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 Jan 27, 2016 @ 14:41

        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 Oct 8, 2016 @ 21:51

          Thanks for this tip! :D

  • Craig Lillard Feb 9, 2017 @ 6:00

    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?

    • Blake Mar 31, 2017 @ 22:58

      That’s correct, there is no progress indicator. If you really want you can quiz the process it runs in, in a seperate terminal but there really is no need.

      Just leave it go, it can take a while depending the same of the image you are moving.

  • John Apr 10, 2017 @ 17:04

    Is there a way to create the image to only use the “used” part of the disk you are copying? I have a 126 gig sd card that I want to flash to another card but the used area is very small. To restore the 126 gig image looks like it will take another 38 hours.

  • Tor Anders Johansen May 11, 2017 @ 21:56

    If you use the “dd” command with rdisk instead of disk, the cloning will be 20x faster.

    dd if=/dev/disk2 -> dd if=/dev/rdisk2
    dd of=/dev/disk2 -> dd of=/dev/rdisk2

  • Ram Jul 17, 2017 @ 1:18

    My External HDD restored from spindle problem, now shows larger volume. The actual size is 1.5Tb it is showing 4.1Tb. It doesn’t mount automatically, shows in disk utility. Can’t erase or repair or format using disk utility gives “Cannot allocate memory” or “Resource busy” error.
    Tried all of the above dd commands, gives “Resource busy” error when used the command with gzip, otherwise gives “/dev/destination drive/foo.img: Not a directory” error. The unmount using dd was successful.
    Most ‘free’ or open source disc recovery softwares have no luck recovering or properly scanning this disk.
    Does anyone got any idea what could be the problem?

  • Ram Jul 17, 2017 @ 2:53

    My bad, it is showing as 4.1Gb not 4.1Tb.

  • Subra Sep 4, 2017 @ 9:07

    $ sudo dd if=/dev/disk2 bs=64k
    I have always seen if=iso file and of=target disk. why in your example this is other way ? i’m confused. Have i missed something ?

  • Am Oct 17, 2020 @ 12:32

    Hi there,
    I didn’t get where to write the destination for the dd to be created ?

  • Marcel Kraan Jan 4, 2021 @ 10:44

    With a mac myou need to indentify and unmount the disk before you use dd
    use terminal on a mac
    sudo diskutil list

    /dev/disk2 (external, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:     FDisk_partition_scheme                        *32.0 GB    disk2
       1:             Windows_FAT_32 ⁨MINING_OS⁩               1.1 GB     disk2s1
       2:                      Linux ⁨⁩                        524.3 MB   disk2s2
                        (free space)                         30.4 GB    -

    Now unmount the disk
    sudo diskutil umountdisk /dev/disk2

    Then you can write the image the best is to an rdisk device:
    sudo dd if=raveos.img of=/dev/rdisk2

    3276800+0 records in
    3276800+0 records out

    After a while the USB disk in ready to use.

  • Patrick Mar 1, 2021 @ 13:12

    Thank you for this it worked well.
    was having trouble doing it on a Linux system
    Openbsd works Great but didn’t have it installed,
    so decided to try it on my Trusted Mac!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum