Copy complete partition mapping

data-recoveryfilevaulthard drive

How do I copy the whole partition map for a drive 'cloned' with DD? Same size hard drive for input and output of DD. Device block size was 4096 Bytes on input disk, 512 Bytes on output disk. Filevault 2 partitions on source.

Best Answer

You mustn't clone the partition map of a 4096 Byte disk to a 512 Byte disk (and vice versa) directly. 4096 Byte/512 Bytes are the device block sizes here.

The major differences are the 1st block (block=0) and the GPT header (block=1):

While the MBR (PMBR) on a 512 disk only occupies 512 bytes (Block(512)=0), the MBR on a 4096-disk occupies the whole first block and the GUID starts at block(4096)=1 (which would translate to block(512)=8).

The first GPT header on a 512 disk occupies the second block (Block(512)=1), the first GPT header on a 4096-disk occupies the whole second block and the GUID partition table starts at block(4096)=2 (which would translate to block(512)=16).

Examples:

Device block size: 512

                0           1         PMBR
                1           1         Pri GPT header
                2          32         Pri GPT table
               34           6         
               40      409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
           409640 size-main-v      2  GPT part - 53746F72-6167-11AA-AA11-00306543ECAC
totalsize-1269576     1269536      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
     totalsize-40           7         
     totalsize-33          32         Sec GPT table
      totalsize-1           1         Sec GPT header

Device block size: 4096 (in parenthesis the "respective" 512 start block/block size)

               0 (0)           1     (8)        PMBR
               1 (8)           1     (8)        Pri GPT header
               2(16)           4    (32)        Pri GPT table
               6(48)       51200(409600)      1 GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
           76806(..) size-main-v              2 GPT part - 53746F72-6167-11AA-AA11-00306543ECAC
totalsize-158697(..)      158692(..)          3 GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC       
     totalsize-5(..)           4    (32)        Sec GPT table
     totalsize-1(..)           1     (8)        Sec GPT header

As a consequence don't clone the partition table but create it yourself:

sudo gpt create diskX #(with diskX the disk identifier of the target disk(512)

Then add the EFI, the main partition and the Recovery HD. Just start at block 40(512) on your disk(512) while multiplying the sizes of the disk(4096) partitions by 8:

sudo gpt add -b 40 -s (size-old-efi*8) -i 1 -t C12A7328-F81F-11D2-BA4B-00A0C93EC93B diskX
sudo gpt add -b 40+(size-old-efi*8) -s (size-old-main-vol*8) -i 2 -t 53746F72-6167-11AA-AA11-00306543ECAC diskX
sudo gpt add -b 40+(size-old-efi*8)+(size-old-main-vol*8) -s 1269536 -i 3 -t 426F6F74-0000-11AA-AA11-00306543ECAC diskX

Your source EFI partition probably has either 51200 blocks(4096) or 76800 blocks(4096).