I have an external hard drive formatted with 3 HFS+ partitions. To cut a long story short I had it connected to a Windows PC and accidentally started formatting the drive to NTFS. As soon as I realised what was happening I disconnected the drive, but the partition table is corrupted. I used TestDisk to gather info about the partitions, and tried to use pDisk to rebuild the partition table, but when I try to do that, I get the message that the partition table is not writable, the device is busy. Anyone know how I can rewrite the partition table?
Update:
The TestDisk results are like this (for settings on Apple Partition Map – I don't know if this is the correct settings, but it's the only one which gives 3 distinct partitions):
Start: 262208 End: 419692607 Size: 419430400
Start: 419954752 End: 1258815551 Size: 838860800
Start: 1259077696 End: 1953525151 Size: 694447456
Does that look OK?
Best Answer
OS X uses three different types of valid partition tables. Only one of those is written to a particular disk:
The default partition table on OS X is the GUID partition table.
Depending on the previously used partition table on your disk you have to use different tools to create/change/write it:
After additional informations given by the OP (testdisk results) and checking it in a virtual machine it's highly probable that the disk was formatted with an Apple Partition Map. Consequently use pdisk to rebuild the partition map.
pdisk:
A typical disk formatted with an Apple Partition Table looks like this:
To recreate the partition map do the following:
diskutil list
to get the DiskIdentifier (in the step below I assume your DiskIdentifier is disk1diskutil unmountDisk /dev/disk1
enter
sudo pdisk /dev/rdisk1
You will get the following output:Now enter
c
then enter the start block, the size of the first partition and the name. You have to hit the enter key after every input. Repeat this for the next two partitions. At the end it should look like this:At the last prompt enter
w
theny
to write the changes to disk and finallyq
to quit pdisk:The missing volumes should mount automatically. Otherwise enter
diskutil mountDisk /dev/disk1
. Enterq
at the last prompt to quit pdisk, then quit Terminal, open Disk Utility and check the recovered volumes for errors.gpt:
In the example below I assume the DiskIdentifier of your external disk is disk1 (check this with
diskutil list
)First you have to unmount the external disk:
Remove the current MBR and create a GPT with gpt:
First rebuild the EFI entry with:
The EFI partition is a fixed sized partition near the beginning of every GUID partitioned disk (using OS X partitioning tools)
Then add the JHFS+ partition entries with the TestDisk findings:
Example for the first OS X partition:
After adding a partition with gpt you may have to unmount disk1 with
diskutil umountDisk disk1
again if your get a "resource is busy" error adding additional partitions.Increase the index number by 1 for every new partition.
Listed below are answers to similar questions (partly covering other file systems like ExFAT)
If you run into problems, leave a comment to the answer with @klanomath.