3

I booted to a live Ubuntu USB, wanting to delete partitions on an SD card, and ended up deleting all my partitions on my MacBook Pro's internal HD.

I have already tried gpart (which gets stuck at "Begin scan...") and testdisk (which can't create partitions since "Function write_part_mac not implemented"!).

I did try cmd+ R at boot, but gave it up as it was taking a long time. I thought there would be an easier and faster alternative.

Is there a way to recover data with partitions on my hd?

Here's my testdisk output for the Mac HD:

     Partition               Start        End    Size in sectors
> P DOS_FAT_32                    40     409639     409600 [EFI]

> P HFS                       409640  489972567  489562928
Greenonline
  • 1,759
  • 7
  • 16
  • 21
user3490458
  • 207
  • 1
  • 7
  • 1
    Try using `gdisk` `x extra functionality (experts only)`, then within the expert menu `b use backup GPT header (rebuilding main)`. If you have a second metadata copy then you should be able to rebuild the partition table. – bsd Dec 31 '14 at 10:25

1 Answers1

1

Intel MacBook Pro's use GUID partition table for disk partitioning which one can edit with gdisk.

A copy of the partition table metadata is usually stored as backup of the primary. You can read more detail about it on the Arch Wiki here

You need first to know the device name, /dev/sda, /dev/sdb of your Mac disk.
You can use the blkid, lsblk or dmesg commands to determine the exact name if you do not know.

From your Ubuntu Live USB, use gdisk /dev/sdX (where X is your device name)

e.g. /dev/sdb (assuming the USB is given sda and the Mac is the only other disk)

$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): `r`

Recovery/transformation command (? for help): `b` 

Recovery/transformation command (? for help): `w`

And reboot

The b restores the backup GUID partition table and w writes it to disk

You way wish to also run the v verify after restoring the backup table and before writing it to the disk. gdisk is very sane about letting one create and modify the partition table, in memory, and nothing is written on disk until you write it with the w command. Be very sure you are happy with the recovery result before you write it to disk.

bsd
  • 10,916
  • 4
  • 30
  • 38
  • Thanks a lot! I did as you said. But I don't see any partitions when I run 'v'. I had tried apple's internet recovery some time back. Is it possible that the internet recovery messed up the partition table meta data backup? – user3490458 Dec 31 '14 at 12:52
  • 1
    `p` shows the partition table, `v` simply verifies the table and hopefully prints "No problems found." – bsd Dec 31 '14 at 13:08