I think I severely ruined my partition table.
I had a BOOTCAMP partition, a macOS APFS partition, and an exFAT partition. I believe I also had 17GB of unallocated space.
I tried to shrink the BOOTCAMP partition, and I think that ruined the partition table. The BOOTCAMP partition errored on startup, and the macOS partition wasn't detected. From Internet Recovery, I reinstalled El Capitan from a USB drive onto another partition, while deleting the BOOTCAMP partition(I had a fairly recent backup). I'm currently using that, updated to High Sierra. It still does not see the older macOS partition, or the ~50GB of unallocated space(although I feel like most of that might be the missing macOS partition).
Furthermore, the Windows entry still shows when pressing alt/option on boot, although it errors like before. It doesn't show in startup disk or anywhere else.
I assume my BOOTCAMP partition is unrecoverable, which I'm mostly fine with. However, if possible, how can I recover my older macOS partition?
And mainly, how do I simply fix the partition table? Esp. the supposed Windows/BOOTCAMP partition that is there(although I'm sure it isn't) and the missing ~50GB
This is what Disk Utility says I have right now. Extra and Common are just empty partitions for now.
Below is the output from the command sudo gpt -r show disk0
.
Best Answer
The partition table of disk0 is not ruined at all - all changes made are rather unintended.
All partitions and volumes (EFI, Common, macOS and Extra) are properly marked and a
diskutil verifyVolume disk0sY
will probably exit with no error.A ruined partition table would miss the secondary partition header and table, or the primary and secondary header/table are different, or the CRC-32 checksums of the header and partition table entries are invalid.
Your partition table looks like this:
The first partition with a size of 209.7 MB - the standard EFI partition - is followed by unallocated disk space with a size of 46.94 GB.
The second partition is a standard HFS+ partition with a size of 86.37 GB followed by unallocated disk space with a (standard) size of 134.2 MB.
The third is a APFS container partition with a size of 90.87 GB. The fourth partition is another standard HFS+ partition with a size of 26.35 GB.
A default SSD partition layout would probably look like this after installing High Sierra (APFS) and a BOOTCAMP partition though:
The second unallocated disk space (262144 blocks) may be smaller or larger.
Consequently it depends on the size of your old macOS partition if parts of it were overwritten or not.
If the first block of your vanished APFS container (including your old macOS APFS system volume) wasn't overwritten you can detect its former size:
Open Terminal and get the usual disk related details (below I assume the internal SSD has the disk identifier disk0):
Unmount the SSD
dd/hexdump block 409640:
which will yield something like this (example only!):
the third line is the important one:
4e 58 53 42
: magic string of an APFS container00 10 00 00
: APFS block size: 409629 ea 22 01 00 00 00 00
APFS container size in APFS blocks: 19065385 (=152523080 512-blocks)After re-arranging the Bytes
29 ea 22 01 00 00 00 00
>00 00 00 00 29 ea 22 01
>00 00 00 00 01 22 ea 29
, you can get the decimal value here:The size of the old APFS container in 512(blocks) is then APFS block size x container size in APFS blocks. In the example this is 4096/512 * 19065385 = 152523080 blocks.
depending of the former size remove the 2th partition:
restore the old partition (here with the size of the example: 152523080 blocks(512) - don't use this one accidentally!):
check the APFS container
check the APFS system volume
If you have problems analyzing the hexdump or other results and error messages please leave a comment!