December 31, 2011

OSX Hard Drive Recovery

Yesterday afternoon my data drive for OSX had it’s partition table destroyed by OWC’s Mercury Elite Pro hard drive enclosure. They did not mention that even if you decline the OSX initialize disk dialogue, you will still have your partition table over written. You see when you put your drive into this enclosure that hardware need to reformat your drive. You cannot just pop a drive in and enjoy. Thanks to the help of Testdisk, pDisk, and a wonderful tutorial from PerroHunter.com my hard drive was back up and running with about a half hour work of effort. I will outline the steps below, but if you are going to do this definitely check out PerroHunter.com‘s tutorial.

  1. Read through all of the directions below before starting the process. Plus I highly recommend checking out the more detailed tutorial from PerroHunter.com.
  2. Download Testdisk (Free software via Open Source GPL license)
  3. Connect the drive. I used a SATA to usb adapter.
  4. In OSX the dialogue that appears about initializing the drive, choose Ignore.
  5. Open Terminal and navigate to the location of where you downloaded Testdisk to.
  6. Run Testdisk as root. bash#sudo ./testdisk
  7. Choose [Create]. It creates a new log file.
  8. Select the disk you would like to operate on (up/down arrows). For me this was /dev/rdisk1. Press Enter to Proceed
  9. Select the disk partition table type. If you are on OSX, this should be “Mac”. Press Enter to Proceed.
  10. Choose Analyze to find partitions on the drive. Press Enter to continue.
    • An error will likely appear on the next screen saying “Bad MAC partition, invalid block0 signature read_part_mac: bad DPME signature. Do not worry about this.
  11. Press enter to perform a Quick Search.
    1. The following screen is going to tell you the relevant information on where the partition starts and stops. This will allow you to use pDisk to recreate the partition table. Testdisk cannot recreate the partition table as of the writing of this article. It will only allow you to find the information you need to fix the partition table.
    2. Here is an exanmple of the data the Quick Analysis should give you:
      Disk /dev/rdisk1 - 320 GB / 298 GiB - CHS 625142448 1 1
           Partition               Start        End    Size in sectors
      >P HFS                       409640  624880263  624470624
  12. Choose Quite to exit out of Testdisk.
  13. In a new Terminal window enter the command bash#sudo pdisk /dev/rdisk1
    • Replace ”/dev/rdisk1″ with the disk you choose on step 7.
    • You will likely be asked for you password once you hit enter.
  14. You should receive a warning about “No valid block  1 on ‘/dev/rdisk1/’ (or whatever disk you are performing this on)”, do not worry about this.
  15. Press “i” and Enter to confirm block size and some other information. As each line of information appears hit enter until you arrive back at “Command (? for help):”
  16. Hit “c” and Enter to start defining the new partition table. Note that the partition table will not be written until the end.
  17. Using the information from step 11, I am going to define the “First block” as “409640″ per the “Start” heading from the output of Testdisk. Hit Enter to continue.
    • Remember the value 409640 is specific to my device, use the values you receive from Testdisk for your device.
  18. For the “Length in blocks” I will use “624470624″ as defined in the “Size in sectors”  from Testdisk. Hit Enter to continue.
    • Remember the value 624470624 is specific to my device, use the values you receive from Testdisk for your device.
  19. Now enter a name for the partition. This is not reflected as the name of the drive in OSX. Because of this I chose the simple name “one”. Press Enter to continue.
  20. You should now be back at “Command (? for help):”.
  21. Press “w” and hit Enter to write the new partition table to the drive.  pDisk will ask you to confirm the operation before I writes the partition table.
  22. If all goes as planned, your drive will show up shortly either on your Desktop or in Disk Utility. A reboot may be necessary.

Congratulations, you have just repaired a hard rive without paying someone a ton of money or buying expensive tools. If you have any questions feel free to comment below.

~Nathan Hein