How can I make my Mac partition bootable again?

Solution 1:

Your iMac contains a 2 TB non-4k disk (I suppose it's an HDD) and macOS High Sierra is (was) installed.

2542739416 blocks of your disk starting at block 409640 are not allocated to partitions.

Your lost partition(s) can be expected to be found & restored in the unallocated disk space.

The default Apple partition layout for an HDD is 1. EFI 2. main system and 3. Recovery HD (and 4. additional partitions created by the user e.g. Boot Camp). EFI and Recovery HD have a default size on 512-disks:

  • EFI: 409600 blocks(512)
  • Recovery HD: 1269536 blocks(512)

The eligible partition types for an HDD are either standard HFS+ or CoreStorage (usually if the main system volume was encrypted or the Mac contains a Fusion Drive). APFS is also possible but not recommended by Apple. Re-formatting an HDD to APFS would have been done by the user.

On an SSD the default partition type would be APFS with no recovery partition.


To detect the former partition type boot to Internet Recovery Mode:

  • Get the partition details (below I assume the internal disk has the device identifier disk0):

    diskutil list
    gpt -r show disk0
    
  • Unmount disk0 with diskutil umountDisk disk0
  • vis the first 3 blocks starting with block409640 of disk0:

    dd if=/dev/disk0 skip=409640 count=3 | vis -c
    

    If you had a standard partition previously the first 1024 Bytes only contain non-printable (zeros): \0\0\0\0\0\0... After ~Byte 1030 you will see the following sequence: \0HFSJ\0

    If you had a CoreStorage partition some non-zeros in the first 512 Bytes and the string CS (...\0CS\^A...) are shown:

    \^U\^D\^A\M-s\M^?\M^?\M^?\M^?\^A\0\^P\0\0\0\M-W\^A\a\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\^B\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\M^Pu\M-\7\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0CS\^A\0\0\0\^D\0\0\^P\0\0\0\0@\0X\M-7}\^C\0\0\0\0X\M-;}\^C\0\0\0\0X\M-?}\^C\0\0\0\0X\M-C}\^C\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\^P\0\0\0\^B\0\0\0006j v\^R\M-+\^U\M^[\f\M^CdG\M-y\^]...
    

    If you had a APFS partition the string NXSB (...\0NXSB\0\^P...) is shown in the first few bytes:

    ??[?\M^T\M^VD\^A\0\0\0\0\0\0\0\^X\f\0\0\0\0\0\0\^A\0\0\M^@\0\0\0\0NXSB\0\^P\0\0?7?\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\^B\0\0\0\0\0\0\0\^Q?^@1\^PL ?GSf~\M^KBչ?\0\0\0\0\0\0\^Y\f\0\0\0\0\0\0\^X\^A\0\0\^Xl\0\0\^A\0\0\0\0\0\0\0\^Y\^A\0\0\0\0\0\0!\0\0\0\M^@Z\0\0\^_\0\0\0\^B\0\0\0zZ\0\0\^F\0\0\0\0\^D\0\0\0\0\0\0007?\^C\0\0\0\0\0\^A\^D\0\0\0\0\0\0\0\0\0\0d\0\0\0\^B\^D\0\0\0\0\0\0\^F\^D\0\0\0\0\0\0\b\^D\0\0\0\0\0\0f?\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
    

If you have a second full-fledged macOS boot drive you can use hexdump instead:

  • Unmount disk0 with diskutil umountDisk disk0
  • hexdump the first 3 blocks starting with block409640 of disk0:

    sudo dd if=/dev/disk0 skip=409640 count=3 | hexdump
    

    The following result identfies it as a normal OS X partition:

    0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000400 48 2b 00 04 80 00 21 00 48 46 53 4a 00 00 01 ff
    0000410 d3 8c 77 d3 d4 33 3c b0 00 00 00 00 d3 8c 5b b3
    0000420 00 00 02 a8 00 00 00 25 00 00 10 00 00 fe b7 f6
    0000430 00 fe 1e fa 00 ed 80 00 00 01 00 00 00 01 00 00
    0000440 00 00 10 f2 00 00 5a 9d 00 00 00 00 00 00 00 01
    0000450 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    0000460 00 00 00 00 00 00 00 00 7d 9d b0 3a 02 31 62 f0
    0000470 00 00 00 00 00 1f e0 00 00 1f e0 00 00 00 01 fe
    0000480 00 00 00 01 00 00 01 fe 00 00 00 00 00 00 00 00
    0000490 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    00004c0 00 00 00 00 00 60 00 00 00 60 00 00 00 00 06 00
    00004d0 00 00 0a 00 00 00 06 00 00 00 00 00 00 00 00 00
    00004e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000510 00 00 00 00 03 10 00 00 03 10 00 00 00 00 31 00
    0000520 00 03 ac 00 00 00 31 00 00 00 00 00 00 00 00 00
    0000530 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000560 00 00 00 00 05 40 00 00 05 40 00 00 00 00 54 00
    0000570 00 00 10 00 00 00 54 00 00 00 00 00 00 00 00 00
    0000580 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000600
    

    The first number is the byte count in hex: 0000000: 0; 0000600: 1536. The * denotes identical lines. This means: the first two blocks (0x000-0x3ff) are all zeros.

    A CoreStorage partition shows some non-zeros in the first block (0x000-0x1ff):

    0000000 0c 73 a1 a9 ff ff ff ff 01 00 10 00 07 14 d7 01
    0000010 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    0000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    0000030 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    0000040 00 20 c1 cc 0f 00 00 00 00 00 00 00 00 00 00 00
    0000050 00 00 00 00 00 00 00 00 43 53 01 00 00 00 04 00
    0000060 00 10 00 00 00 00 40 00 11 bc fc 00 00 00 00 00
    0000070 11 c0 fc 00 00 00 00 00 11 c4 fc 00 00 00 00 00
    0000080 11 c8 fc 00 00 00 00 00 00 00 00 00 00 00 00 00
    0000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00000a0 00 00 00 00 00 00 00 00 10 00 00 00 02 00 00 00
    00000b0 62 02 98 59 ee a9 ab 51 9b 49 23 90 2e f8 8b 43
    00000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000130 e4 6e f8 f2 63 99 45 c1 b2 13 86 28 a5 18 46 6d
    0000140 c4 51 c0 f6 32 f9 43 ab 8e 59 42 d2 1a ef f6 50
    0000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000400 48 2b 00 04 80 00 21 00 48 46 53 4a 00 00 01 ff
    0000410 d1 98 a4 93 d4 33 8b d5 00 00 00 00 d1 98 88 73
    0000420 00 06 07 53 00 01 82 39 00 00 10 00 00 fb 6a 00
    0000430 00 c5 1c 55 00 25 73 c7 00 01 00 00 00 01 00 00
    0000440 00 0d e2 65 00 3e a2 fb 00 00 00 00 02 20 00 fb
    0000450 00 00 00 31 00 06 b9 ef 00 00 00 00 00 00 00 00
    0000460 00 00 00 00 00 00 00 31 fb 48 1e a0 6c 47 a2 9f
    0000470 00 00 00 00 00 1f e0 00 00 1f e0 00 00 00 01 fe
    0000480 00 00 00 01 00 00 01 fe 00 00 00 00 00 00 00 00
    0000490 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    00004c0 00 00 00 00 00 60 00 00 00 60 00 00 00 00 06 00
    00004d0 00 00 0a 00 00 00 06 00 00 00 00 00 00 00 00 00
    00004e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000510 00 00 00 00 0e 40 00 00 01 30 00 00 00 00 e4 00
    0000520 00 00 10 00 00 00 e4 00 00 00 00 00 00 00 00 00
    0000530 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000560 00 00 00 00 11 d0 00 00 01 30 00 00 00 01 1d 00
    0000570 00 02 80 00 00 00 72 00 00 13 30 97 00 00 13 00
    0000580 00 15 c5 aa 00 00 13 00 00 18 2d 23 00 00 13 00
    0000590 00 19 d8 fb 00 00 13 00 00 1b 76 cb 00 00 13 00
    00005a0 00 1c 34 70 00 00 13 00 00 1d 0e 4d 00 00 13 00
    00005b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    0000600
    

    The line starting with byte 0x130 shows the UUID of the Physical Volume, the line starting with byte 0x140 shows the UUID of the Logical Volume Group.

    The string 48 46 53 4a (= "HFSJ") in the first 16 bytes of the third blocks identifies a Journaled HFS+ volume on both partition types.

    An APFS container looks like this:

    0000000 e7 ec ab 5b a2 94 96 44 01 00 00 00 00 00 00 00
    0000010 18 0c 00 00 00 00 00 00 01 00 00 80 00 00 00 00
    0000020 4e 58 53 42 00 10 00 00 f6 37 ff 00 00 00 00 00
    0000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    0000040 02 00 00 00 00 00 00 00 11 f1 5e 40 31 10 4c 20
    0000050 bb 47 53 66 7e 8b 42 d5 b9 c4 00 00 00 00 00 00
    0000060 19 0c 00 00 00 00 00 00 18 01 00 00 18 6c 00 00
    0000070 01 00 00 00 00 00 00 00 19 01 00 00 00 00 00 00
    0000080 21 00 00 00 80 5a 00 00 1f 00 00 00 02 00 00 00
    0000090 7a 5a 00 00 06 00 00 00 00 04 00 00 00 00 00 00
    00000a0 37 fd 03 00 00 00 00 00 01 04 00 00 00 00 00 00
    00000b0 00 00 00 00 64 00 00 00 02 04 00 00 00 00 00 00
    00000c0 06 04 00 00 00 00 00 00 08 04 00 00 00 00 00 00
    00000d0 66 a4 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    00003d0 00 00 00 00 00 00 00 00 16 21 06 00 00 00 00 00
    00003e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    *
    00004f0 00 00 00 00 00 00 00 00 91 3d 0f 00 00 00 00 00
    0000500 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    0000510 78 f4 09 00 00 00 00 00 01 00 00 00 00 00 00 00
    0000520 01 00 04 00 08 00 00 00 00 00 00 00 00 00 00 00
    0000530 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    

    The string 4e 58 53 42 (= "NXSB") starting with byte 0x020 in the first block is the magic string of an APFS container superblock and identifies it as APFS container. The UUID of the container starts at 0x48 (here: 11 f1 5e 40 ...)


If you have found a standard partition (which usually is accompanied by a Recovery HD), you can add them with the following commands:

diskutil umountDisk disk0
gpt add -i 5 -b 2541879520 -s 1269536 -t 426F6F74-0000-11AA-AA11-00306543ECAC disk0
diskutil umountDisk disk0
gpt add -i 4 -b 409640 -s 2541469880 -t 48465300-0000-11AA-AA11-00306543ECAC disk0

If you have found a CoreStorage partition (which usually is accompanied by a Recovery HD), you can add them with the following commands:

diskutil umountDisk disk0
gpt add -i 5 -b 2541879520 -s 1269536 -t 426F6F74-0000-11AA-AA11-00306543ECAC disk0
diskutil umountDisk disk0
gpt add -i 4 -b 409640 -s 2541469880 -t 53746F72-6167-11AA-AA11-00306543ECAC disk0

If you have found an APFS partition (no Recovery HD - it's included in the APFS container!), you can add it with the following commands:

diskutil umountDisk disk0
gpt add -i 4 -b 409640 -s 2542739416 -t 7C3457EF-0000-11AA-AA11-00306543ECAC disk0

Booted to a normal system you have to prepend sudoto the gpt ... commands. Under certain circumstances you have to disable SIP.


Finally check the partitions/volumes:

diskutil verifyDisk disk0
diskutil verifyVolume disk0s2
diskutil verifyVolume disk0s3

Your previous partition layout may have contained a gap between the "former" Recovery HD and the Microsoft Reserved partition (size: 32768 blocks type: E3C9E316-0B5C-ADB8-817D-F92DF00215AE). Then the verifyVolume commands will fail and bigger guns have to be brought up. Don't try to repair or initialize anything if asked!


If you run into unexpected problems, add a comment!