Thanks for trying to help me fix this problem.
I have been having trouble with my external RAID, the error message that I got was that I have a partition table error. The RAID contains six 4 TB hard drive in a RAID 5 setup.
I used "testdisk" to try to fix the problem, but now all my data seems to be gone. Upon restarting my computer, I am asked to format the drive – which I have not done.
The RAID was formatted initially under GUID partition scheme.
I took screen shots of the original partition table. disk5 is my RAID setup.
I am asking for help in reverting the partition table to its original setup so I can access data.
MacOS – Partition table error in external ARECA RAID
disk-utilityfilesystemhard drivemacos
Best Answer
The TestDisk results for macOS formatted disks are/were often misleading or even wrong because the algorithm misinterprets special hidden volume content. AFAIK it tries to detect special empty blocks (2) followed by the occurrences of the strings H+ and/or HFSJ in the third block - which marks the beginning of a HFSJ volume. A similar sequence is used to detect the last blocks of a volume. Such 1536 Byte "blocks" are more frequent than TestDisk can handle.
I prefer a manual approach.
Preconditions:
Methodology:
Basics:
First get all available disks and the partition table of the broken disk (here disk5):
diskutil list
diskutil umountDisk disk5
sudo gpt -r show disk5
Device Block Size:
To determine the block size of the disk enter:
Depending on the Device Block Size (either 512 B or 4096 B) and the total size of the disk they either contain a 200 MiB or 300 MiB EFI partition as first partition after the partition table, then the main volume and finally some free space or a second partition and some free space. The last few blocks are occupied by the second ("backup") partition table.
The standard Apple GUID partition scheme of a 512 B disk looks like this:
The standard Apple GUID partition scheme of a 4096 B disk looks like this:
512 B disks may also have a 614400 blocks(512) EFI partition (partition 1) or 4096 B disks may have a 51200 blocks(4096) EFI partition - both can be found much less often than the other way round though. The size of the main partition is reduced or enlarged respectively.
An external RAID with a RAID-controller may contain a bunch of 4096 B disks but will still present the RAID-volume as 512 B device!
Volume Type:
To determine the volume type you have to hexdump the first blocks after the EFI partition.
This is done by piping data stream input in dd to hexdump:
To hexdump a 512 B disk (with a 200 MiB EFI) use the following command:
To hexdump a 4096 B disk (with a 300 MiB EFI) use the following command:
In both cases a normal HFS+ volume is indicated by its signature 0x482b (="H+") at 0x0000400 and/or by its lastMountedVersion 0x4846534a (="HFSJ") starting at 0x0000408
In both cases an APFS volume is indicated by 0x4e585342 (= APFS magic string) starting at 0x0000020:
Volume Header:
Both dumps also contain the Allocation Block Size and the Number of Allocation Blocks of the (first) volume or the APFS container. Both values determine the size of the (lost) volume/container. The allocation block size mustn't be confused with the device block size!
The allocation block size of an HFS+ volume can be found in the volume header. In the dump above the volume header starts at 0x0000400 and ends at 00005FF.
The allocation block size is an UInt32 starting at 0x0000428
The allocation block number is an UInt32 starting at 0x000042C
To convert hex to decimal use
echo "obase=10; ibase=16; (uppercase hex!)" | bc
So the allocation block size of the above example is
and the number of allocation blocks is
The total size of the example volume is 732506362 x 8192 Byte (= 6000692117504 Byte or 11720101792 blocks(512) or 1465012724 blocks(4096)).
The block size and the block number of an APFS container can be found in the container superblock which starts at 0x0000020.
The block size is an UInt32 (reversed) starting at 0x0000024
The block number is an UInt64 (reversed) starting at 0x0000028
To convert hex to decimal with
echo...
command you have to reverse the byte order:(00 10)⬄(00 00) > 00⬄00 00⬄10 > 00 00 10 00
and
(f6 37 b9 03)⬄(00 00 00 00) > (00 00)⬄(00 00) (f6 37)⬄(b9 03) > 00⬄00 00⬄00 b9⬄03 f6⬄37 > 00 00 00 00 03 b9 37 f6
So the block size of the above example is
and the number of blocks is
The total size of the example volume is 62470134 x 4096 Byte (= 255877668864 Byte or 499761072 blocks(512) or 62470134 blocks(4096)).
Recreating the lost volume:
Depending on your findings in the previous steps (512|4096)/(HFS+/AFPS)/(block size & block number) add the missing EFI and the main volume to the partition table.
Examples with the above example disks (and both missing EFI and main partition):
512 B disk, 200 MiB EFI & APFS container (499761072 blocks(512))
4096 B disk, 300 MiB EFI & HFS+ volume (1465012724 blocks(4096))
Verify the final volumes with
diskutil verifyVolume diskXsY
.If you're faced with a 512 B disk and a 300 MiB EFI (or a 4096 B disk and a 200 MiB EFI) which will result in hexdump gibberish, you have to slightly apply the
dd ... | hexdump
command.