4

Can you clone a Mac OS X boot volume (specifically a "Mac OS Extended, Journaled" a.k.a. JHFS+ volume) directly to another, larger volume using ddrescue or even dd, and have the target volume end up as a perfectly working, bootable volume?

In the past, I've used ddrescue to make a raw .dmg backup of a Mac OS X boot volume of a dying hard drive, and then "restored" that .dmg to another volume via Disk Utility, but in this case I don't have the spare hard drive space to store the intermediate .dmg file, so I'll need to invoke ddrescue to directly clone the dying volume to a new volume. But I'm nervous that using ddrescue to do this directly, rather than using Disk Utility for the restore portion, won't leave things set up correctly so the resulting volume won't be bootable.

I have to use ddrescue because I'm dealing with a failing hard drive again. SMART Utility says it has only a single pending bad sector out of a 500GB drive, so I feel like my odds of not having any critical data on that bad sector are pretty good. The part I'm worried about is whether a raw block-by-block clone of one volume to a slightly larger volume might not leave the target volume set up correctly somehow.

Has anyone done this before on Mac OS X and can vouch that it works?

Update: Had to post my own Answer ("No", or "Not in the way I tried"), but I'd be happy to Accept a different answer if someone else can provide instructions for successfully doing this.

2 Answers 2

2

So the answer appears to be either "No", or at least "Not in the way I tried". The resulting volume mounted once, but Disk Utility's "Repair Disk" said the filesystem structures had errors (incorrect b-tree sizes, perhaps?) that Disk Utility couldn't repair. I didn't have the ability to see if Disk Warrior or another tool could have fixed it. The failing source drive did not have these problems, so it was probably something about my ddrescue-based copying procedure that messed it up.

A friend of mine said he successfully cloned a whole drive (including partition table and everything) on a Mac using dd, so it may be possible to clone a whole device this way, just not individual JHFS+ volumes.

Another thing that may have contributed to the failure is that I did not take the time to make the target partition exactly the same number of sectors/blocks as the source partition (the target was larger of course).

0

resurrecting this to provide the current solution.

Modern MacOS on both Intel and Silicon can use the Apple "ASR" utility to clone their drive completely. See: https://discussions.apple.com/docs/DOC-250005828

The trick to it is making sure you properly select the correct APFS volumes for the command depending on what you want to do.

To fully clone your boot drive over to a freshly formatted APFS external drive:

  1. Identify and mount your internal "Macintosh HD" APFS volume on the virtual disk within your APFS container scheme synthesized from your internal physical disk. Sometimes it helps to list your disks filtered separately by physical or virtual with the commands: diskutil list physical && diskutil list virtual

  2. Mount the "Macintosh HD" volume from the internal virtual disk using it's disk identifier (e.g. disk1s5) with the command: diskutil mount disk1s5

  3. find the GUID of the system disk snapshot using the disk identifier you just mounted with the command: diskutil apfs listsnapshots disk1s5; The GUID you want is the one on the line that starts with +--

  4. Find the disk identifier (e.g. disk2s2) for the APFS Container disk on your external physical drive volume with the command: diskutil list external physical | grep Container;

  5. Execute the ASR command with appropriate restore parameters, including the source and target volumes, and the snapshot GUID. This will restore your system onto the external drive APFS container.

Once this is completed, it is best to rename your cloned volumes so they can be easily distinguished from your internal drive's volume names. The new system volume must also be "blessed" in order for it to be bootable. We can do both of these things together.

If on Apple Silicon, there may be other steps required. Consult the article linked above.

    $ diskutil list
/dev/disk0 (internal, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *1.0 TB     disk0
       1:                        EFI ⁨EFI⁩                     209.7 MB   disk0s1
       2:                 Apple_APFS ⁨Container disk1⁩         873.0 GB   disk0s2
       3:       Microsoft Basic Data ⁨BOOTCAMP⁩                127.3 GB   disk0s3
    
    /dev/disk1 (synthesized):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      APFS Container Scheme -                      +873.0 GB   disk1
                                     Physical Store disk0s2
       1:                APFS Volume ⁨Macintosh HD - Data⁩     373.6 GB   disk1s1
       2:                APFS Volume ⁨Preboot⁩                 675.8 MB   disk1s2
       3:                APFS Volume ⁨Recovery⁩                2.2 GB     disk1s3
       4:                APFS Volume ⁨VM⁩                      1.1 MB     disk1s4
       5:                APFS Volume ⁨Macintosh HD⁩            15.4 GB    disk1s5
       6:              APFS Snapshot ⁨com.apple.os.update-...⁩ 15.4 GB    disk1s5s1
    
    /dev/disk2 (external, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *960.2 GB   disk2
       1:                        EFI ⁨EFI⁩                     209.7 MB   disk2s1
       2:                 Apple_APFS ⁨Container disk3⁩         960.0 GB   disk2s2
    
    /dev/disk3 (synthesized):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      APFS Container Scheme -                      +960.0 GB   disk3
                                     Physical Store disk2s2
       1:                APFS Volume ⁨Clone MacOS - Data⁩      367.6 GB   disk3s1
       2:                APFS Volume ⁨Clone MacOS⁩             15.4 GB    disk3s2
       3:                APFS Volume ⁨Preboot⁩                 629.0 MB   disk3s3
       4:                APFS Volume ⁨Recovery⁩                1.1 GB     disk3s4

$ diskutil mount disk1s5
$ diskutil apfs listsnapshots disk1s5
Snapshot for disk1s5 (1 found)
|
+-- 173CBA59-B437-43E0-9904-B28B2F714F0B
    Name:        com.apple.os.update-CB12C14C05552C076D856AD12B102E53CCB8AB4E163547432B0577BE3AE6B5E9
    XID:         21541437 (Will root to (boot from) this snapshot)
    Purgeable:   No


$ time sudo asr restore --no-personalization --erase \
                 --source /dev/disk1s5        \
                 --target /dev/disk2s2        \
                 --toSnapshot 173CBA59-B437-43E0-9904-B28B2F714F0B 


    Validating target...done
    Validating source...done
    Erase contents of /dev/disk3 ()? [ny]: y
    Replicating ....10....20....30....40....50....60....70....80....90....100
    Replicating ....10....20....30....40....50....60....70....80....90....100
    Restored target device is /dev/disk3s2.
Restore completed successfully.

$ diskutil list virtual
/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +873.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume ⁨Macintosh HD - Data⁩     371.0 GB   disk1s1
   2:                APFS Volume ⁨Preboot⁩                 675.8 MB   disk1s2
   3:                APFS Volume ⁨Recovery⁩                2.2 GB     disk1s3
   4:                APFS Volume ⁨VM⁩                      1.1 MB     disk1s4
   5:                APFS Volume ⁨Macintosh HD⁩            15.4 GB    disk1s5
   6:              APFS Snapshot ⁨com.apple.os.update-...⁩ 15.4 GB    disk1s5s1

/dev/disk3 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +4.0 TB     disk3
                                 Physical Store disk2s2
   1:                APFS Volume ⁨Macintosh HD - Data⁩     367.5 GB   disk3s1
   2:                APFS Volume ⁨Macintosh HD⁩            15.4 GB    disk3s2
   3:                APFS Volume ⁨Preboot⁩                 629.0 MB   disk3s3
   4:                APFS Volume ⁨Recovery⁩                1.1 GB     disk3s4
$ diskutil mount disk3s1
$ diskutil renameVolume disk3s1 "Clone MacOS - Data"
$ diskutil mount disk3s2
$ diskutil renameVolume disk3s2 "Clone MacOS"
$ sudo bless -mount "/Volumes/Clone MacOS" -setBoot
$ diskutil eject /dev/disk3
$ diskutil list external
/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *960.2 GB   disk2
   1:                        EFI ⁨EFI⁩                     209.7 MB   disk2s1
   2:                 Apple_APFS ⁨Container disk3⁩         960.0 GB   disk2s2

/dev/disk3 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +960.0 GB   disk3
                                 Physical Store disk2s2
   1:                APFS Volume ⁨Clone MacOS - Data⁩      367.6 GB   disk3s1
   2:                APFS Volume ⁨Clone MacOS⁩             15.4 GB    disk3s2
   3:                APFS Volume ⁨Preboot⁩                 629.0 MB   disk3s3
   4:                APFS Volume ⁨Recovery⁩                1.1 GB     disk3s4

Once this is done, reboot with the correct key combination (usually OPTION) to select a boot drive, and choose the clone.

Once booted, log-in and wait for the system to fully start all of your desktop services, etc... Some control panel preferences may not work yet.

Once you're fully logged in and everything is started, reboot again. After that, everything should be working. Test your clone well before archiving it. This also works great for replacing your internal drive on older macs that allow such nonsense. :-)

If you want to refresh your clone without fully overwriting it each time, the ASR command target needs to change a bit. Instead of choosing the target to be the APFS container partition on the physical external disk volume, choose the disk identifier for the "Clone MacOS" partition on the synthesized virtual external disk. e.g. disk3s2 in my example.

The one thing I haven't figured out yet is how to also clone an existing BootCamp partition to the clone'd external drive's physical disk.

This might require booting the clone and repeating the bootcamp setup with precisely the same size disk volume settings, and THEN using dd to overwrite the new partition - or restoring a Windows backup... not sure and haven't found a good reference for this yet.

1
  • This might be a fine process for cloning a volume from a stable disk, and I think it deserves to be documented somewhere so feel free to leave it up here, but my Question was specific to ddrescue because I had a dying disk with bad sectors and I needed ddrescue's ability to treat bad sectors with special care. asr doesn't have those features, so it's not an option for the scenario I was dealing with.
    – Spiff
    Commented Oct 5, 2023 at 16:00

You must log in to answer this question.

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