34

What is the best way to clone a disk between two Macs? I ask this every couple years or so and every time I get the same answer. "Use Carbon Copy Cloner", they say. But the unfortunate fact is that CCC is a file-level copy between disks. When I migrate to my new Mac, sure all the files are there but there are quirks here and there (including file dates being different etc).

So, really now, once again: how do you clone the disk over byte-for-byte?

0

7 Answers 7

50

You can use the dd command to make a bit-perfect clone of a drive. It's a command line tool that ships with OS X. In order to make the clone perfect you'll need to ensure the source and the destination aren't actively in use.

To prepare for the clone I recommend creating a secondary boot disk that you can boot from. Your source for the clone should be an offline volume, not in use, when you're making the copy. Otherwise you risk copying things that are in incomplete states on disk.

With your machine booted to your secondary boot disk, log in and fire up a Terminal or iTerm window.

Run diskutil to get a list of your available drives. One of them will be your target drive you're trying to clone. The other will be your source drive. For example:

> diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *320.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            319.2 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3       
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS Backup                  499.8 GB   disk1s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk2
   1:                        EFI                         209.7 MB   disk2s1
   2:                  Apple_HFS Clone                   499.8 GB   disk2s2

Let's say that Macintosh HD (disk0) is the source and Clone (disk2) is the target for our dd operation. Start the clone with:

> sudo dd if=/dev/rdisk0 of=/dev/rdisk2 bs=1m conv=noerror,sync

When dd finishes you may see an error like this:

dd: /dev/rdisk2: short write on character device
dd: /dev/rdisk2: Input/output error
3726+1 records in
3726+1 records out
500107862016 bytes transferred in 14584.393113 secs (34290619 bytes/sec)

That last error message is actually okay. The last block written was a short block because there wasn't a full 1MB block to copy. No worries.

Now you've got a bit-wise perfect clone of your Macintosh HD drive. Reboot your system using the Macintosh HD drive and enjoy your clone! And when we say bit-wise perfect we mean it. The disk structure is copied block-by-block so this dd approach works to copy data from a disk that uses a partitioning scheme that macOS doesn't natively support.

18
  • 4
    rdisk# bypasses a 4KB OS buffer. More info. I'd advise that you chose a smaller bs, as going above 1m actually makes it slower. (At least over USB. I can't tell if it's an external USB drive or a direct SATA connection.)
    – Nick ODell
    Dec 27, 2012 at 22:18
  • 2
    It may be worth experimenting a bit with the bs setting. I got significant increases in throughput (almost double) by decreasing the size from bs=1m to bs=65536.
    – Jens Wegar
    Aug 9, 2014 at 14:20
  • 2
    @IanC. I read somewhere that the block size of the HDD could be used as an indicator of the ideal size to give dd. On the other hand another source said there is no bullet proof way of figuring out the optimal size. So can't give any real advice there. However, it didn't take too long to experiment. Probably the ideal value is a factor of 2, so I'd start with 4096, then 8192, 16384 and so on. You'll find the peak pretty quickly this way.
    – Jens Wegar
    Aug 11, 2014 at 15:53
  • 2
    @user3.1415927 you can use status=progress option of dd to see the progress and transfer rate. Then you can abort with CRTL+C and try with another value for bs
    – Wlad
    Aug 26, 2018 at 14:26
  • 3
    @DarwinOSX For Unix commands the manual pages can be accessed via man CMDNAME, in this case man dd. It explains the various options available, including the ones you ask about.
    – nohillside
    Aug 6, 2021 at 18:53
17

Apple's bespoke command line utility to do disk cloning is asr.

It is tailored to the specifics of OS X needs to perform file by file as well as block based imaging and deals with differences in partition sizes, allows network streaming (and even multicast streaming) as well as copying between disks that are locally connected. Unlike dd, it knows about Apple's latest Core Storage volume management and is the program that the graphical Disk Utility calls to move data from one partition or volume to another.

You can read more at the manual page for asr.

9
  • 2
    Note that asr is the same tool that Disk Utility's Restore tab uses (see my answer). The command-line interface has additional options that the GUI interface omits, such as converting between HFS+ (case insensitive) and HFSX (case sensitive) formats, and putting the copy in a Core Storage volume group. But it may be harder to use for people who aren't used to the command line. Jan 26, 2014 at 18:45
  • Bad link....... Sep 15, 2018 at 22:13
  • Not sure if archive.org or a new link is the way to go here. web.archive.org/web/20150923065146/https://developer.apple.com/… Thanks @TraderhutGames
    – bmike
    Sep 15, 2018 at 22:17
  • FYI: I was getting writes of 122 MB/sec using dd and a block size of 64K, I killed that to switch to asr, doing a --verbose restore --source /Volumes/X / -target /Volumes/Y --erase and I must say I'm impressed. --verbose showed me nothing in terms of stats (DD has a Ctrl/T option to show you progress) - maybe I needed to do the --verbose at the end... None the less, I'm impressed. I was getting 134 MB/sec read and Write using DD, and asr is kicking at 25MB/sec. So, instead of the copy taking 4 hours... I'm looking at 21 Hours! Yeah, I don't know if it has a higher chance of working, but Sep 15, 2018 at 22:33
  • but I'm can do a test with dd first, and then if it fails, let it take a day to copy 2TB from one disk to the other using asr... Sep 15, 2018 at 22:33
11

Verbose output from dd via pv

enter image description here

Copying even a small disk can take a long time and the silence can be frustrating. If you install pv (pipe viewer) you can use it to monitor the progress of any stream.

If you are using homebrew (and you should be) installing pv is as easy as:

brew install pv

Then decide which disks you want to copy.

diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage SSD                     250.1 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            SSD                    +249.8 GB   disk1
                                 Logical Volume on disk0s2
                                 2CFBB247-D59D-474F-8467-2B1BDB275524
                                 Unencrypted

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.6 GB    disk2
   1:             Windows_FAT_32 boot                    43.0 MB    disk2s1
   2:                      Linux                         15.5 GB    disk2s2

/dev/disk3 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.6 GB    disk3
   1:             Windows_FAT_32 NO NAME                 15.6 GB    disk3s1

In this case /dev/disk2 is an Micro SD card from my Raspberry Pi in the internal reader and /dev/disk3 is a new MicroSD in a USB dongle.

The command to copy it is going to be very similar to common dd commands except we are going to take advantage of the fact that of (output file) defaults to STDOUT and if (input file) defaults to STDIN. This allows you to use unix pipes in between. The dd function listens for control-t key and will update you on progress when it is asked to report while running.

# I'm going to define variables to make your copy-paste easier
SRC=/dev/rdisk2
DST=/dev/rdisk3

# This is the command you want
sudo dd bs=1m if=$SRC | pv | sudo dd bs=1m of=$DST

# Notice how similar this is to doing a simple
sudo dd bs=1m if=$SRC |      sudo dd bs=1m of=$DST

# ...which is functionally identical to
sudo dd bs=1m if=$SRC                      of=$DST

# (except 2 processes vs. 1)

The actual output looks like:

dd bs=1m if=/dev/zero count=16000 | pv | dd bs=1m of=/dev/null
16GiB 0:00:06 [2.46GiB/s] [       <=>                                          ]
1
  • 5
    Or, you can hit Ctrl-T while waiting for DD to complete, it will show you how much it has done, and how fast.. load: 2.25 cmd: dd 50443 running 1.50u 55.87s 899897+0 records in 899896+0 records out 58975584256 bytes transferred in 473.978101 secs (124426812 bytes/sec) Sep 15, 2018 at 22:39
10

Disk Utility can do volume-to-volume cloning with the Restore tab. Between two Mac OS Extended volumes, this'll do a block copy, i.e. it just copies the volume structures, so all the files come out identical (down to the file ID numbers). This is essentially the same thing dd does, except that Disk Utility can expand/contract the volume if the destination isn't exactly the same size as the source, and it's a lot faster (for some reason, dd is quite slow on OS X).

EDIT: After seeing @Ian's note about speed using /dev/rdiskN vs. /dev/diskN, I ran some quick&dirty benchmarks copying between two 4GB flash drives:

dd using /dev/diskN: 2737 seconds
dd using /dev/rdiskN: 907 seconds
Disk Util, full volume: 840 seconds to copy + 213 seconds to verify
Disk Util, empty volume: 4 seconds to copy + 1 second to verify

So it looks like the rdisk suggestion makes dd run about the same speed as Disk Utility; the real differences are that Disk Utility verifies its data (slower, but maybe safer) and skips blank space (faster if the disk isn't nearly full). That, and as I said above DU can resize as it copies.

1
3

Carbon copy cloner was good, but then on my Mac Pro it no longer made bootable clones, I tried it 3 times and every clone failed to boot unlike previously. So I switched to SuperDuper! and that clone booted fine

1
  • 1
    His answer included an explanation: Carbon Copy quit working, explained that is why he switched, what he switched to and that it worked. Nice and concise. Three thumbs up! I don't want to read a long book to get the 'try SuperDuper! - it works' - when that was all I needed. Sep 15, 2018 at 22:42
0

How about good ol' fashioned dd. It can make a bit-by-bit copy of your drive. There are lots of guides out there on how to do this such as this one or this one

1
  • 2
    Answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone.
    – nohillside
    Sep 30, 2013 at 12:41
-3

There are two types of cloning Mac drive. File level and block level based cloning. As we know carbon copy cloner can create file level based clone only and its one of the big competitor Superduper can create clone of volumes and partition only not the whole disk. So, I will suggest to go for a new emerging Mac cloning software that is Stellar Drive Clone capable to both file level and block level cloning.

It can create bit by bit exact copy of your entire drive and particular volumes on your any external drive, volume and network drive too. It can create clone of drive on folder and restore backups from the same in its free demo version feature. It can create clone of recovery HD and support window file formats, MBR, ExFAT, FAT32 etc on your Mac.

1
  • 1
    As written your answer isn't much more than a list of product features but without any explanation about how the mentioned tool can solve the problem the OP has. Can you please make your answer more useful by describing the necessary steps in more detail (and maybe also explaining which benefits this method has compared to the ones described in the other answers)?
    – nohillside
    Sep 30, 2013 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .