Posted: 2011-06-26
Category: How to's
At the time of writing this post I must say that I feel like a hero! That feeling is wonderful you know, when someone has a problem with their computer and not a simple but a HUGE one and you are able to repair em you turn to be that people hero.
Today my friend Avaco12 made a little mistake while installing bootcamp on her iMac, she left her external (200GB) disk connected, and when Windows asked her where to put the new Partition she accidentally selected her preciousus external drive, when she realized it was already too late, windows had already destroyed the partition table on her disk. She had 1 HFS parition and 1 FAT. She was crying because she said she had her entire life on that disk, so she asked me for help and I started researching what could I possibly do to repair the disk or at least retrieve her data.
There are plenty of solutions out there, some of them are really expensive, and people on the forums are not very happy with them so I wanted to look at little more into the issue and I came across this solution called TestDisk which is an Open-Source Multi-platform solution for repairing disk partitions. I gave it a try and awesomely I managed to fix the disk using TestDisk and the pdisk utility.
When I called Avaco12 to tell her that I fixed her data she was so happy she couldn't stop smiling she told me I was her Hero and so that's how I felt, the process wasn't easy specially because noone talks about how pdisk works on Mac OS X.
Here's how I did it , hope it works for you.
1.- I downloaded TestDisk from their official site :http://www.cgsecurity.org/wiki/TestDisk
2.- I opened the terminal and surfed to where I downloaded and unziped TestDisk
3.- I issued the command 'sudo ./testdisk' it indetially promped me to make my terminal bigger =P, after doing so It displayed me a simple disclaimer and then a notice telling me that TestDisk could Log all the activity if I wanted to. I selected Yes and continued.
4.- On the screen it will display you all the Disk it detects connected to your Mac select the one that got damaged partition tables and press Enter. Take note of which drive you selected, in my case I chosed /dev/rdisk1 (rather than /dev/disk1)
5.- Next screen select the menu Analize, it will probbly display you and error telling you the block 0 couldn't be read, just hit enter on the 'Quick Analize' option
6.- ATTENTION: TestDisk will quickly search for partitions on the disk and display you information about it on your disk. Take note of the information it will display you, since you'll need it to repair the disk later on with pdisk.
Here's a screenshot of what I got:

Note: if you try to repair your partition table with TestDisk it will fail since that function is not yet implemented.
7.- you can now exit TestDisk. The next steps are what distinguish a child from a Men
8.- Issue the command 'sudo pdisk /dev/rdisk1' (where /dev/rdisk1 should be the same name you chosed on step 4). If you type the command 'c' and hit enter it will tell you the following:

9.- That's completely normal. Now type 'i' and it will display you some affirmations about block sizes and such, just hit enter:

10.- Now we are going to need the info from Step 6. type the command 'c' and press enter, it will ask you to type down where your first partition starts, how long it is and how you want to name it. repeat this step for every partition you have.

11. Now if you are completely sure you wrote down everything correctly (like I did) just type down 'w' and hit Enter, It will prompt you to confirm just say yes (y)
12. type 'q' to quit the application and go see for yourself if your disk appears now in Finder. If it does, go to Step 13. else try disconnecting your external hard disk and reconnecting it. After Mac OS X 10.6.7 it is suggested that you restart your machine and reconnect the disk. If this fails try again from step one. Don't worry about rewriting the partition table it doesn't harm your data.
13. You are a hero, no matter if it's your own disk, you just saved your data!
Congratulations, and I hope this information is usefull to you !
You can buy me a drink if you'd like to share your joy :)
Feel free to contact me with any problems you get at : perro.hunter@gmail.com
cheers !
TweetComments
-
2011-06-26
Worked like a charm thanks man !
-
2011-06-26
This is the sort of advice that should be on late night television- but wait there is MORE! Retrieve ALL of your data NOW- no File Carving- no rebuilding Indexes, no FSCK, simply put- its PDISK and its on a mac near you! :D (Sorry- complete and absolute file recovery can cause extreme excitement and euphoria)
-
2011-06-26
Hi dog hunter!
I would kiss you if I can! I've just recovered a partition that Partition Magic (from a boot cd) dreaded up! It "fixed" an error, and the driver never worked again. I found that the problem was a wrong Partition Table, and your explanation was quite helpfull. Althouth, I was able to do everything from TestDisk! Yeah, its true. After a QuickSearch, I have set the right Partition Types (which the program have correctly detected) and selected the program to write the partition table. The program told me to reboot, and voila! (using a disk formated as GUID with a unique partition as HFS+)
Long live the hunt! -
2011-06-26
Holy god, you are my hero right now! Bootcamp snuffed my partition table, but the world has been made right again!!! THANK YOU!!!!!!
-
2011-06-26
I manually fucked up my 500gb backup drive when attempting to make Windows 7 read NFS+ drives, and I thought I had lost it all when OS X didn't seem to read it.
Thanks to you, and TestDisk, I got my data back! I have never been this happy in a long time!
Thank you! -
2011-06-26
thanks, this worked great. Windows 7 hosed my HSF partition cause it initiated the disk. I tried various tools nothing worked. Followed your step and everything worked, the only thing that i needed to do was scan for my partition a bit it didnt show up in the first quick scan
-
2011-06-26
You are da man! My 1T external became unreadable and unrepairable after an app crashed while copying files. Your procedure worked like a charm.
-
2011-06-26
Thanks for your help. That was excellent. I accidently overwrote my partition table when I connected my osx exernal drive to a XP system and lost all my data. Now it is back .... thanks goodness. Cheers
-
2011-06-26
Does anyone know how do fix the Mac partition from the Windows partition? I already have the log from TestDisk.
-
2011-06-26
Hey Randy ! you could try to use your OS X Installation disc, just insert it, when you get the the main menu, on the apple menu go to Utilities> terminal, and from there use pdisk :D ! plz tell me if this worked :) cheers
-
2011-06-30
Great info, thanks. I was wondering if it could be done for HFS+.
One thing though, your first screen shot, 36.png, just takes me to the main blog page when I click on it or try to open it in a new tab.
Thanks again for the great tutorial though. -
2011-06-30
@jim: hey Jim, I've fixed that broken link :) sorry I'm transitioning the blog to a new platform.
Cheers -
2011-06-30
Hi!
Thanks for the tutorial, it really helped me... but unfortunately, I couldn't retrieve my partition :(
All the steps until pdisk worked like a charm. But pdisk, after hitting command "i" tells me the disk is busy and cannot access it. Any ideas how solve this ??
Config: Mac intel dual core (2007) / external HFS+ HD (WD)
Thanks for you help!
Alex -
2011-07-04
So happy to find this post- gives me hope that I may recover from my hasty mistake (plugging Mac/HFS drive into Windows 7)...
I got Testdisk working, and I was able to "Analyse" my rdisk1. Then when my options are "Quick Search" or "Backup", either option causes the program to freeze. The log file shows "read err: Resource busy" (preceded by buffer addresses) a ton of times until I quit Testdisk. (I let it run for a few hours last night; no difference)
I was able, however, to view the partition map scheme from Testdisk, so I tried your method in Pdisk.
upon starting pdisk, I get:
"pdisk: Can't read block 2 from partition 3
pdisk: Can't read block 2 from partition 5
Edit /dev/rdisk1-"
... and then I can go through the commands. But my results diverge from above:
command 'i' --> "map already exists. do you want to reinit?"
command 'c' --> when I do the big partitions, I get the "Can't read block x..." errors again.
Any wisdom?
THANKS. happy 4th.
-
2011-07-07
I've had to have TestDisk run a deep search and now I have way too many choices for deleted partitions. Great. We'll see how this turns out. Good to hear that people out there are getting their data back.
@Mrsupersirk
The issue you are facing is most likely the need to unmount the drive in question before you can perform low-level operations on it. You can open up DiskUtility and click on the drive you are working with and then click the 'unmount' button on the tool bar. You could also run the command 'diskutil diskX unmount' if you are already in the terminal. -
2011-07-15
Hi, thanks for the advice. Disk utility took it upon itself to destroy the partition map for my external Hd, I'm currently trying this method as nothing else I was able to find seems to have any suggestions for the issue - hopefully this will work. I was just wondering how long it ought to take pdisk to perform the remapping? (I have a 2TB drive - process is still working and I'll leave well enough alone for awhile). I'm just looking for a ballpark figure so that I may know whether to assume that it has failed or not.
-
2011-07-28
AMAZING!!!! IT WORKED!!! THANKS FOR THIS, YOURE AWESOME :)
-
2011-08-04
hi, i did it but now the disk is not readable by my mac!
help!!!!!!!!!!! -
2011-08-27
THANK YOU VERY MUCH!!! I could fix my partition table. It was damaged because I used windows to create a new volume. Will never do it again. ;) Thank you! without your helpful instruction I would not have been able to fix it and rescue my movies and games. ;)
-
2011-08-30
Perro,
I tried to access pdisk from the terminal under the Snow Leopard disc and it said it was an unknown command.
Any thoughts?
Thanks
Mosi -
2011-09-05
Most of the replies I send are through email :P please leave your real email address :)
-
2011-09-09
Hello Perro, i send an email with screenshots to your gmail. can you let me know whether you received my email?
kind regards,
Arjan -
2011-09-13
Thank you for sharing with us your knowledge. you are the best :)
-
2011-09-14
thank you very much! It perfectly worked... I recovered a partition with 250 GB of data which disappeared due to a corrupted partition table!
-
2011-09-19
I had upgraded my macbook with a bigger harddisk, with a little help from clonezilla. Bit when I tried to resize the partition with Disk Utility I got an error: "mediakit reports partition (map) too small"
I tried to follow this:
http://info.michael-simons.eu/2010/11/19/migrate-os-x-to-a-bigger-hard-disk/
but I wrote something wrong, and puff! Gone partiotion table ! Hello completely wrong partition table !
Then I downloaded the latest version of testdisk to a usb drive, restarted my macbook with an ubuntu live disk and ran the testdisk in a terminal.
I mounted the usb (mount /dev/sdb1 /media/usb), ran the testdisk utility from the usb stick (in my case testdisk_static), followed your instructions untill step 6.
Then for some awesomeness ! The latest version of testdisk now supports the option to write the partition table for you, based on what it finds analysing the drive ! So I simply choose the "write" option, rebooted and everything worked again !
Thank you so much :)
-
2011-09-27
Hi Perro,
I have same problem as your friend facing, after follow your instruction i have facing some problem on the Pdisk command after i run the testDisk, I am using Mac OS X Lion. Is it anyway to retreive back my files in my external hardisk? Thanks. -
2011-09-29
it's worked for me !!! Thank you very very much!!!!!!!
@差点要哭出来了... 不小心删除一个mac分区... 找了几个mac数据恢复软件.. 都木有成功恢复, 有的恢复了文件但不能打开...折腾2天了....
今无意中搜索到这篇文章.... 然后又根据这篇文章提供的信息找到英文原版(有图片).
然后... 冒着生命危险参考着原版完成了生平第一次分区表恢复... 更重要的是.. 好几十G的数据终于又失而复得... 真的太感动鸟~ 特意登录来拜谢~ -
2011-10-11
Thanks so much for your tutorial, you are very kind and a gentleman through and through :-)
Restored my sisters macbook external drive. -
2011-10-23
Thanks to the author of this guide, he just saved my 2TB external drive, of which yesterday I wipe out its partition map.
I wanted to erase a USB key with Disk Utility, but I was so stupid to select the wrong drive… a couple of second after I realized the error and detached the cable, but the partition map was gone...
Interestlyng, I had to follow a slightly different procedure, because my external drive is formatted with an EFI-GPT map, and not APM.
I followed this guide, but when I tried to create an Apple Partition Map with pdisk it always failed with the error “the map is not bight enough”.
Since APM max size is 2TB, it looks like that my drive is slightly bigger, at least to make pdisk and APM fail.
If someone is interested in make some calculation, this was the output of testdisk:
Disk /dev/rdisk1 - 1999 GB / 1862 GiB - CHS 3905656832 1 1
Partition Start End Size in sectors
P Mac HFS 409640 3905394647 3904985008
Because of this, I had to use the ‘gpt’ command to create a new GTP partition map:
sudo gpt create /dev/rdisk1
sudo gpt add -b 409640 -s 3904985008 -t hfs /dev/rdisk1
As you can see it’s very similar to pdisk, and you need the same information: first block and length in blocks.
After this, I have reconnected the drive to my mac and it worked again. Thanks again to the author, I wouldn’t have find this solution without this guide!
One final notice, now even if the Finder and Disk Utility both can see the 2TB HFS partition, Disk Utility is unable to repair the GPT map because it can’t find any partition.
It looks like that I haven’t perfectly recreated the GPT, but it’s good enough to copy all the files on another drive. -
2011-10-25
BIG THANKS !!!!! it worked perfectly for me too :-)
-
2011-11-06
VirtualBox destroyed my 2TB external HD along with my 18,000+ family photos... My wife and I were devastated. The HD would come back with an error "Unable to read/ Unknown partition" and "initialize/reformat/ignore messages. Data recovery service quoted me $3000.00 to retrieve my data. After hours trying to use TestDisk I came across your article. With pdisk, I was getting an error about map size... I ran TestDisk again, this time choosing "WINDOWS/VISTA option"... TestDisk told me I needed to set my headers to 32... which I did.. I then was able to "Write" the new partition using "WINDOWS/VISTA" format even though my HD was formatted for mac. A reboot was required but... YEEEEEHAAA my HD is BACK FROM THE DEAD!!! Thank you so much for your article. Without it, I wouldn't have found out the issues... Thanks from a very relieved novice mac user... using terminal for the first time... and pdisk...
-
2011-11-09
Ahhh! Thank you! ¡Muchas gracias! ¡Eres asombroso!
-
2011-11-10
hey man, got in to trouble!
i have a 500 gb HDD from a lacie EDmini HFS partition on which i fried the usb so i had to access the data your way.
I plugged the HDD in a G4 mac and use the terminal.
everything completed like a charm but the disk did not initialize after restart
:(
i had 5 partitions but none could be accessed.
help... -
2011-11-10
Hi!
i've been trying to use your method but it doesn't do any good for me. here's what i did to screw my life up: completely in a hurry and without any kind of attention i used an "erase" command on disk utility that apparently did not erase the partition, only ALL of the data in it. when i try to recover the partition using your method it only shows me an empty partition...
what am i doing wrong?
thanks a lot man.
running lion.
best!
-
2011-11-11
@Andre, you erased the disk my friend. That is not a partition problem, you just wiped it.
Try data recovery progs, but really, it's gone. -
2011-11-13
Hi there,
i tried to re-partition one of existing partition on external hard drive through Disk Utility
after that, some error message appeared and then i restart the mac, and found that my partitions all gone
now i'm trying to use TestDisk, but after i select my error hard drive, the TestDisk just froze and do nothing. i tried to wait, but nothing seems to be happening.
can you help, please ?
my entire data is on that hard drive :(
Thanks a Lot..
Aldy -
2011-11-16
THANKS A MILLION !
worked like a charm! -
2011-11-19
I am a hero!
And so are you. Un millón de gracias!
Btw: I love you transparent terminal windows that allow us to see through ;-) -
2011-11-22
YOU SAVED MY LIFE! THANK YOU THANK YOU and THANK YOU!!
I bought you a beer :) -
2011-11-25
Hey i try this but i have partition which is HFS n NTFS on my 1TB external HD. but its only choose HFS in the first choice. How i can use it for my HFS n NTFS in the same time when quick analyze...or i must do this twice.....1st HFS n after i repeat again for NTFS???
-
2011-12-07
Hi,
I am a hero as well, looks like the dragon I fight is too tough for me though :)
At step 10. when I write the numbers on every of 4 partitions, it says "the map is not big enough" each time.
And when I try to write it down (with 'w') it says: "The map has not been changed."
Any clues on that one guys?
-
2011-12-11
I have a 500 GB disk that only had one partition on it, the "Macintosh HD". It's a clean install of Mac OSX Snow Leopard, so I don't know whether the EFI stuff is on an extra partition. Anyway, when I analyze it with testdisc (version 6.13), it can't find any partition to repair (is it correct to select "Mac"?
It says:
Bad MAC partition, invalid block0 signature
read_part_mac: bad DPME signature
When I select Analyze, it slowly counts up the cylinders and after half an hour, I'm still stuck at 00%, but it can find some stuff:
Disk /dev/rdisk1 - 500 GB / 465 GiB - CHS 976773168 1 1
Analyse cylinder 7208960/976773167: 00%
HFS 4121592 980222935 976101344
HFS 4122752 980224095 976101344
HFS 4123776 980225119 976101344
HFS 4126584 980227927 976101344
HFS 4128264 980229607 976101344
HFS 4130200 980231543 976101344
HFS 4132592 980233935 976101344
HFS 4137616 980238959 976101344
HFS 4142720 980244063 976101344
HFS 4146816 980248159 976101344
HFS 4151464 980252807 976101344
HFS 4158352 980259695 976101344
HFS 4164920 980266263 976101344
HFS 4172128 980273471 976101344
All I need is the info from Step 6 so I can enter it into pdisk. Is there any way to get it without scanning the hard drive for weeks? -
2011-12-13
@FAM, I found the solution to your problem. I too was experiencing the error, “the map is not big enough” and couldn't rebuild my partition map.
I found this site: http://forums.macrumors.com/archive/index.php/index.../t-1140673.html and followed his instructions to a T. (the critical instructions are in the next 2 paragraphs)
"First, you'll need to figure out the disk number of the hard drive. If you're booted from the machine (rather than a different machine, using the drive as an external), it's going to be /dev/disk0. The following will rewrite the partition table to near-default (possibly a little bigger primary volume):
sudo dd if=/dev/zero of=/dev/disk0 bs=512 count=10 conv=sync,noerror
sudo gpt destroy /dev/disk0
sudo gpt create /dev/disk0
sudo gpt add -i1 -b40 -s409600 -tC12A7328-F81F-11D2-BA4B-00A0C93EC93B /dev/disk0
sudo gpt add -i2 -b409640 -t48465300-0000-11AA-AA11-00306543ECAC /dev/disk0
(I typed in the commands EXACTLY as he specifies - just be sure you know the correct name of your disk. Mine was just like he shows /dev/disk0 My disk was connected externally to my working MBP)
Once I finished entering the last command in Terminal, the disk immediately mounted on my desktop.
Next, I tried to use Disk Utility to repair it like he mentions, but it failed. I then used DiskWarrior and THAT finished up the repair just as he said.
My disk works fine!! It mounts no problem. No data lost. -
2011-12-15
Amazing!!! Thanks for such great advice. A true Hero :)
-
2011-12-15
Hi,
I have some trouble with my Macintosh HD... can't boot any more
I used test disk as discribed bellow... but wenn I run
pdisk /dev/disk0 (or /dev/rdisk0) I get the following message:
pdisk: can't open file '/dev/disk0' for writing (Resource busy)
I started my Macbook Air (first gen) from USB-Stick with Snow Leopoard on it and run test disk via terminal an disk as well -
2012-01-08
I need a help. I'm trying to expand my boot camp windows partition, but I converted my disk to a dynamic disk accidentally. Now my entire disk in my iMac is a dynamic disk, and I'm not able to boot to OS X. How can I revert the process without the loss of data? I'm able to boot Windows 7 but I don't know how to resolve this problem without losing all my data in mac partition. I tried use TestDisk but I don't understand how to use it especially when choosing which drive/partition and partition type. I'm not sure of it.
Thanks for your help -
2012-01-14
Clear, simple instructions let me recover after disk utility on PPC wiped the partition map when I tried to manipulate a drive with multiple partitions with different filesystems on them.
Thanks for posting this. Saved me 630Gb of data. -
2012-01-15
Hi, Please help me, my 1TB drive can not read, I have on it from Time Machine backups,
I used a test drive and wrote me this: Bad MAC partition, invalid signature block0
read_part_mac: bad signature DPME
thanks for any help -
2012-01-17
Just a remdinder I answer most of the comments via email :) so you should use your real email on the comments hehe
cheers -
2012-01-25
After step 9. there is "can't open file '/dev/rdisk0' for writing (Resource busy) similar to @Mrsupersirk. I've tried also 'gpt'. Nothing. Please help......
-
2012-02-06
Im having the same problem as Jakob at the part where it scans the drive but shows 16% after nearly a day. Is there any hope left or could i just map the whole drive as one partition? It only had one when the data was lost.
-
2012-02-07
this is great! but i have a problem. i am trying to repair a g-tech g-speed q and it is setup as a RAID array. it has four drives and they all show up when i analyze. i did just pick one of them and tried to follow the instructions to completion but then i run into the "the map is not big enough" error.
so, does it matter what drive i pick of the four? i saw the instructions from @drew )http://forums.macrumors.com/archive/index.php/index.../t-1140673.html) but before i do that i want to be sure i know which disk to select of the four that are showing up.
thanks!! -
2012-02-10
Hello and thank you so much for your help!
I have an issue though - when I get to step 9, my command terminal says: "can't open file ... for writing (permission denied)
It seams even using the sudo command that I can't write restored partition to the drive? I have been searching for over a day now trying to recover this drive and I don't know what to do... if you have any insights that could help I would appreciate it insanely... thank you again! -
2012-02-14
I'm having the same problem as some, where it's taking a ridiculous amount of time to scan the disk. I opened the Console and it shows hundreds of read errors per second. I just left testdisk running overnight and it was still at 00%
If my partition used to be GUID, it's considered Intel, correct? -
2012-02-17
I have this problem, but there's not a response in any comments:
pdisk: can't open file '/dev/disk0' for writing (Resource busy)
please help! -
2012-02-17
I respond most of the comments via email :)
-
2012-02-19
HOLY MOTHER OF GOD THIS WORKED!!!!! I cannot believe it! I had tried different softwares at $100 each all claiming to be able to restore lost partitions (and sure they would DETECT the lost partitions but there was no hope of actually been able to RESTORE them!) but none of them did anything like this! Literally when I finished all the above steps my entire hard drive (1 Tb Lacie) was restored with everything EXACTLY the way it was before the hard drive crashed!
I cannot thank you enough - seriously you are a life saver and just made my week!
Keep up the good work!
Cheers :-) ! :-) ! -
2012-02-20
Hi,
i think bootcamp windoz has blew up my partition scheme, so i tried your steps, but now i'm getting the same error as some people described. The "pdisk: can't open file '/dev/disk0' for writing (Resource busy)"
plz, help... -
2012-02-20
You guys shouldn't be using /dev/disk0 as that's probably the main disk in which your OS X is running, you should be using something different such as disk1, disk2 and so on...
cheers

