invalid BS_jmpBoot in boot block: 000000

MediaFour‘s MacDrive (7.2.6) keeps screwing up the GPT on my external GPT-formatted drive. It has one HFS+ partition and one 200 MB EFI system partition, and when I boot my iMac into Windows (Vista SP1 x86), mount the drive, and then boot back into Mac OS X (10.5), I usually find that OS X won’t recognize the HFS+ volume any more. The characteristic error is an ignore/eject/format unrecognized dialog after OS X login, and “invalid BS_jmpBoot in boot block: 000000″ from Disk Utility when trying to repair it.

It seems that the GUID for the HFS+ volume is changed from {48465300-0000-11AA-AA11-00306543ECAC} (HFS+) to {EBD0A0A2-B9E5-4433-87C0-68B6B72699C7} (“Microsoft Basic Data”). Windows doesn’t have any trouble mounting it as long as MacDrive is installed, it’s OS X that has the problem. I was able to fix the GPT by changing the GUID back to what it should be, at which point the drive was recognized by OS X, and found that the actual HFS+ file system was unharmed. I wrote most of a GPT editor in the process, and if Mediafour doesn’t fix MacDrive soon, I may end up turning it into a one-click GPT fixer.

***

update:

Here’s the tool I used to fix my own disk: gpt_surgeon.py

It’ll need Python 2.5 or higher, and has only been tried in OS X on my own machine. Run it with no arguments or look at the code for a usage statement. The repair process goes like this:

First, list the partitions on your disk to figure out which one needs to be relabeled with the right filesystem type. If you don’t know what your disk device path is, go look in Disk Utility or System Profiler or run diskutil(8) with its list option. The path for my external disk is /dev/disk1.

$ ./gpt_surgeon.py list /dev/disk1

Read MBR and GPT from /dev/disk1.
partition 0:
     type: EFI System
     name: u'EFI System Partition'
    flags: 0x00000000
partition 1:
     type: Microsoft Basic Data
     name: u'Untitled'
    flags: 0x00000000

Note the partition that says “Microsoft Basic Data”. Assuming that you had a single non-system partition on the disk, and that the partition was HFS+ before MacDrive got to it, this is probably that partition. In my case, it’s partition 1. Remember the number; you’ll need it in the next step.

If you have multiple data partitions on the disk, especially if one of them is actually a Windows data partition, you should use something like disktype to check what filesystems are present in each partition, so that you don’t accidentally relabel the wrong one.

If you have any other partitions from this disk mounted, unmount them now.

You’ll need to run with sudo to get the privileges necessary to actually repair the GPT on disk.

$ sudo ./gpt_surgeon.py repair /dev/disk1 1

Read MBR and GPT from /dev/disk1.
Changing type of partition #1 on /dev/disk1 to HFS+...
    Opened /dev/disk1 for writing.
    Wrote MBR.
    Wrote GPT header.
    Wrote GPT entries.
    Closed /dev/disk1.
Done.

And this is what the disk’s GPT should look like afterwards. Your HFS+ partition should be mountable now.

$ ./gpt_surgeon.py list /dev/disk1

Read MBR and GPT from /dev/disk1.
partition 0:
     type: EFI System
     name: u'EFI System Partition'
    flags: 0x00000000
partition 1:
     type: Apple HFS+
     name: u'Untitled'
    flags: 0x00000000

***

second update: commenter James let me know that Christophe Grenier‘s TestDisk utility can also be used to fix this problem.

***

third update: here’s a video walkthrough of the process. For people who have Flash turned off for some reason, please see the QuickTime version of the walkthrough.

***

last update: gpt-surgeon is opening up! Thanks to all who submitted usage reports, suggestions, failure data, and proposed patches. I hope you’ll find future versions at least as useful. Comments have been turned off for this post; all questions, comments, suggestions, and support requests about gpt-surgeon must be submitted through the gpt-surgeon LaunchPad site and should be accompanied with disktype reports.

Tagged , ,

74 thoughts on “invalid BS_jmpBoot in boot block: 000000

  1. James says:

    I have just come across the same problem with MacDrive ruining my external HFS+ drive.

    any tips for fixing it up?

  2. Jeremy says:

    James,
    I’ve updated my post with a repair tool and instructions. Please let me know if it works for you.

  3. Michel says:

    Hi!

    I have exactly the same problem and cause.

    I installed Python however I can’t or don’t know how to get your instructions to work.

    Tried all in the terminal that opened but the “best” message I get is that I have no permission….

    • Jeremy says:

      Michel:

      I’ll need the exact error message if I’m to figure out what’s going wrong for you. Please try again, and when you reach an error, save your Terminal session to a text file (Terminal > Shell menu > Export Text As…) Then post the contents here, or email the text file to me, and I’ll take a look.

      Meanwhile, I’ve posted a video walkthrough of the process.

  4. lenny says:

    Hi,

    I downloaded the python script gpt_surgeon.py and did the chmod 755 (or +x) on it and then fixed the “#!/usr/bin/env python” to read “#!/usr/bin/python” as there is no “env” under /bin. But there is a link for python in /usr/bin. I can enter “python” on the command line in terminal.app and it runs the python environment. But when I try to execute the command as instructed I get an error in an assert declaration or statement with the efiSignature (I’m not a python programmer, but I do know some UNIX and perl). Here is a pasting of the output I get…

    john-dilaos-computer:FIXJDDISC johndilao$ ls -alF
    total 32
    drwxr-xr-x 4 johndilao johndilao 136 Jun 23 21:59 ./
    drwx——+ 14 johndilao johndilao 476 Jun 23 21:45 ../
    -rw-r–r–@ 1 johndilao johndilao 6148 Jun 23 21:07 .DS_Store
    -rwxr-xr-x@ 1 johndilao johndilao 7796 Jun 23 21:59 gpt_surgeon.py*
    john-dilaos-computer:FIXJDDISC johndilao$ ./gpt_surgeon.py list /dev/disk6

    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 217, in
    main()
    File “./gpt_surgeon.py”, line 203, in main
    listGPT(diskDevice)
    File “./gpt_surgeon.py”, line 141, in listGPT
    _, gpt = readMBRAndGPT(diskDevice)
    File “./gpt_surgeon.py”, line 135, in readMBRAndGPT
    gpt = EFIPartitionTable(disk)
    File “./gpt_surgeon.py”, line 51, in __init__
    assert sig == efiSignature
    AssertionError

    john-dilaos-computer:FIXJDDISC johndilao$

    Any help you can provide would be great. We can see that the partition was set to DOS-FAT16 as it was hooked up to an old Windows system. So we just need to change that back to HFS+ and it appears that your python script would do this. Also, I am running the standard python that came loaded on this iMac (Intel) and it is version 2.5.1 as shown below (build info shown as well):

    john-dilaos-computer:FIXJDDISC johndilao$ python
    Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
    [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> quit()
    john-dilaos-computer:FIXJDDISC johndilao$

    Thank you!

    • Jeremy says:

      An assertion failure there means that it’s not finding the EFI partition table. It may have been corrupted or overwritten. We can check this in two ways:

      1. add the line

      print “sig = %r” % sig

      right before the line with the assert statement (leading white space is significant in Python, so make sure it’s indented the same way as the assert line). Then the script will print out what it is reading the EFI partition table signature as. A normal EFI partition table should say “EFI PART”. Since the assertion is failing, the signature is not correct, but it might be useful to know what the one on your disk is.

      2. install disktype (disktype.sourceforge.net, or from MacPorts) and run it on your disk. disktype is very good at detecting what file systems are actually present, regardless of what the partition scheme claims.

      Please send me the output from these and I’ll try to figure out exactly why the script is failing.

      If memory serves, there’s a backup copy of the partition table at the end of the disk. Old operating systems that corrupt the GPT info at the beginning of the disk might not corrupt the backup, so it may be possible to restore your disk even if the GPT has been overwritten. However, I’ll need to modify the script a bit to do that.

      • Having the same problem with a USB osx volume.

        The PRINT:

        MacLappy:~ nick$ ./gpt_surgeon.py list /dev/disk2

        sig = ‘\x00\x00\x00\x00\x00\x00\x00\x00′
        Traceback (most recent call last):
        File “./gpt_surgeon.py”, line 217, in
        main()
        File “./gpt_surgeon.py”, line 203, in main
        listGPT(diskDevice)
        File “./gpt_surgeon.py”, line 141, in listGPT
        _, gpt = readMBRAndGPT(diskDevice)
        File “./gpt_surgeon.py”, line 135, in readMBRAndGPT
        gpt = EFIPartitionTable(disk)
        File “./gpt_surgeon.py”, line 51, in __init__
        assert sig == efiSignature
        AssertionError

        From DISKTYPE:

        MacLappy:~ nick$ disktype /dev/disk2

        — /dev/disk2
        Block device, size 14.96 GiB (16059990016 bytes)
        DOS/MBR partition map
        Partition 1: 14.96 GiB (16059939840 bytes, 31367070 sectors from 63)
        Type 0×06 (FAT16)
        HFS Plus file system
        Volume size 14.96 GiB (16059936768 bytes, 3920883 blocks of 4 KiB)
        Volume name “Mac OS X Install DVD”

        It’s HFS+. Thoughts? Can I modify the script myself to simply ignore the sig check and assume HFS+?

        tx, Nick

      • Thanks in advance if you do have time to respond to this.

        The source of the volume is a dvd. The destination USB partition is 16gb, larger than the dvd.

        Should I do something like this: http://wiki.awkwardtv.org/wiki/Prepare_a_Hard_Drive#Acquiring_the_necessary_images …to get an EFI header from the source, then write it to the Usb volume?

      • Never mind.

        I smoked the partition on the USB stick – will try it another way.

        Thx anyhow.

  5. gouwron says:

    Thank You!!! I’m running a raid backup and archive and was really frustrated and a litte scared by this.

    The script worked like a charm!

    gouwron

  6. lenny says:

    My goodness, I can never get anything to compile or work right as there are too many versions, variations and variables… The makefile for disktype would not run without errors. I ended up just running the gcc on the thing myself and copying/pasting the object files and library info and other arguments on the command line. So now there’s no clean up – oh well…

    So here’s the latest output (thanks for all your help, BTW…). What originally happened is my friend John plugged this drive into an old windows machine (yuk!) and he assigned it a drive letter. It apparently wrote out the DOS FAT 16 file system type to the header and corrupted it. I’m thinking that it’s just so old of a format that his iMac (Mac OSX 10.5.x) doesn’t see it anymore.

    The first pasted text shows what the added line you suggested shows in the print statement added to gpt_surgeon.py (print “sig = %r” % sig). It printed “sig = ‘PM\x00\x00\x00\x00\x00\x0b’”…

    The next pasted output shows what the command “diskutil list” shows, then the disktype output from “./disktype /dev/disk5″ shows.

    Thanks again for your help… Output is below:

    john-dilaos-computer:disktype-9 johndilao$
    john-dilaos-computer:disktype-9 johndilao$ cd ..
    john-dilaos-computer:FIXJDDISC johndilao$ pwd
    /Users/johndilao/Desktop/FIXJDDISC
    john-dilaos-computer:FIXJDDISC johndilao$ ls -alF
    total 624
    drwxr-xr-x 9 johndilao johndilao 306 Jun 28 20:10 ./
    drwx——+ 15 johndilao johndilao 510 Jun 24 00:18 ../
    -rw-r–r–@ 1 johndilao johndilao 6148 Jun 28 19:47 .DS_Store
    -rw-r–r–@ 1 johndilao johndilao 78098 Jun 28 20:10 about_xcode_tools_3.1.3.pdf
    drwxr-xr-x@ 54 johndilao johndilao 1836 Jun 28 22:53 disktype-9/
    -rw-r–r–@ 1 johndilao johndilao 204800 Jun 28 19:27 disktype-9.tar
    -rwxr-xr-x@ 1 johndilao johndilao 7796 Jun 23 21:59 gpt_surgeon-ORIGINAL.py*
    -rwxr-xr-x@ 1 johndilao johndilao 7827 Jun 28 18:49 gpt_surgeon.py*
    -rw-r–r–@ 1 johndilao johndilao 0 Jun 23 23:24 john-dilaos-computer-~ johnd.txt
    john-dilaos-computer:FIXJDDISC johndilao$ ./gpt_surgeon.py list /dev/disk5

    sig = ‘PM\x00\x00\x00\x00\x00\x0b’
    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 218, in
    main()
    File “./gpt_surgeon.py”, line 204, in main
    listGPT(diskDevice)
    File “./gpt_surgeon.py”, line 142, in listGPT
    _, gpt = readMBRAndGPT(diskDevice)
    File “./gpt_surgeon.py”, line 136, in readMBRAndGPT
    gpt = EFIPartitionTable(disk)
    File “./gpt_surgeon.py”, line 52, in __init__
    assert sig == efiSignature
    AssertionError
    john-dilaos-computer:FIXJDDISC johndilao$
    john-dilaos-computer:FIXJDDISC johndilao$
    john-dilaos-computer:FIXJDDISC johndilao$

    john-dilaos-computer:disktype-9 johndilao$ diskutil list
    /dev/disk0
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *298.1 Gi disk0
    1: EFI 200.0 Mi disk0s1
    2: Apple_HFS Macintosh HD 297.8 Gi disk0s2
    /dev/disk1
    #: TYPE NAME SIZE IDENTIFIER
    0: CD_partition_scheme *141.3 Mi disk1
    1: CD_ROM_Mode_1 CD PART 122.0 Mi disk1s0
    /dev/disk2
    #: TYPE NAME SIZE IDENTIFIER
    0: CD_partition_scheme *141.3 Mi disk2
    1: CD_ROM_Mode_1 CD PART 122.0 Mi disk2s0
    /dev/disk3
    #: TYPE NAME SIZE IDENTIFIER
    0: FDisk_partition_scheme *232.8 Gi disk3
    1: Windows_FAT_32 HD PART 232.7 Gi disk3s1
    /dev/disk4
    #: TYPE NAME SIZE IDENTIFIER
    0: FDisk_partition_scheme *232.8 Gi disk4
    1: Windows_FAT_32 HD PART 232.7 Gi disk4s1
    /dev/disk5
    #: TYPE NAME SIZE IDENTIFIER
    0: FDisk_partition_scheme *931.5 Gi disk5
    1: DOS_FAT_16 931.5 Gi disk5s1
    /dev/disk6
    #: TYPE NAME SIZE IDENTIFIER
    0: Apple_partition_scheme *10.0 Gi disk6
    1: Apple_HFSX gr8tfil4it 10.0 Gi disk6s2
    /dev/disk7
    #: TYPE NAME SIZE IDENTIFIER
    0: Apple_partition_scheme *1002.2 Mi disk7
    1: Apple_partition_map 30.0 Ki disk7s1
    2: Apple_Driver_ATAPI 2.0 Ki disk7s2
    3: Apple_HFS Xcode Tools 1002.2 Mi disk7s3
    john-dilaos-computer:disktype-9 johndilao$
    john-dilaos-computer:disktype-9 johndilao$
    john-dilaos-computer:disktype-9 johndilao$ ./disktype /dev/disk5

    — /dev/disk5
    Block device, size 931.5 GiB (1000215674880 bytes)
    Apple partition map, 11 entries
    Partition 1: 31.50 KiB (32256 bytes, 63 sectors from 1)
    Type “Apple_partition_map”
    Partition 2: 28 KiB (28672 bytes, 56 sectors from 64)
    Type “Apple_Driver43″
    Partition 3: 28 KiB (28672 bytes, 56 sectors from 120)
    Type “Apple_Driver43″
    Partition 4: 28 KiB (28672 bytes, 56 sectors from 176)
    Type “Apple_Driver_ATA”
    Partition 5: 28 KiB (28672 bytes, 56 sectors from 232)
    Type “Apple_Driver_ATA”
    Partition 6: 256 KiB (262144 bytes, 512 sectors from 288)
    Type “Apple_FWDriver”
    Blank disk/medium
    Partition 7: 256 KiB (262144 bytes, 512 sectors from 800)
    Type “Apple_Driver_IOKit”
    Blank disk/medium
    Partition 8: 256 KiB (262144 bytes, 512 sectors from 1312)
    Type “Apple_Patches”
    Partition 9: 128 MiB (134217728 bytes, 262144 sectors from 1824)
    Type “Apple_Free”
    Blank disk/medium
    Partition 10: 931.4 GiB (1000080515072 bytes, 1953282256 sectors from 263968)
    Type “Apple_HFS”
    HFS Plus file system
    Volume size 931.4 GiB (1000080515072 bytes, 244160282 blocks of 4 KiB)
    Volume name “Maxtor One Touch III”
    Partition 11: 8 KiB (8192 bytes, 16 sectors from 1953546224)
    Type “Apple_Free”
    Blank disk/medium
    DOS/MBR partition map
    Partition 1: 931.5 GiB (1000213577728 bytes, 1953542144 sectors from 2048, bootable)
    Type 0×06 (FAT16)
    Blank disk/medium

    john-dilaos-computer:disktype-9 johndilao$
    john-dilaos-computer:disktype-9 johndilao$
    john-dilaos-computer:disktype-9 johndilao$

    • Jeremy says:

      From the disktype readout, it doesn’t look like this disk was ever partitioned using the GPT scheme. What you’ve got here is a mishmash of Apple Partition Map (used on all Macs with hard drives up until the last of the PowerPC Macs) and MBR partitioning (used by BIOS-based PCs). My utility isn’t a general partition table repair utility: it was written to fix one specific thing that can happen to GPT headers, and doesn’t understand APM or MBR at all, so it’s not going to be of any use in your case.

      However, given that disktype was still able to read the APM info, it’s likely that Windows only modified the very first sector on the disk, which is where the MBR lives. Unfortunately, it’s also where the APM Block 0 Driver Descriptor Record lives, so now you don’t have one of those any more. The actual partition map is after that, in the first partition in that list, but it seems likely that without the Driver Descriptor Record, Mac OS X doesn’t know that it’s dealing with an APM-partitioned disk. In your case, it’s interpreting the MBR that was written by Windows. So your data’s probably still there, but unless you can replace the Driver Descriptor Record somehow, OS X won’t understand how to find it.

      This is outside the scope of my own experience; I don’t know if there are any tools, commercial or otherwise, that can repair a trashed DDR. If the contents of this disk are important, I recommend contacting a data recovery company, ideally one that knows how to deal with old Macs. If not, keep reading, I’ve got a few ideas.

      If you have a terabyte free somewhere, you could dump out the HFS+ partition with a command like
      # dd if=/dev/disk5s10 of=dump.hfv skip=263968 count=1953282256
      and mount it as a disk image with
      # hdiutil attach -imagekey diskimage-class=CRawDiskImage dump.hfv
      If hdiutil doesn’t work, HFSExplorer might.

      If you happen to have an identically formatted disk sitting around, you could just copy the first sector from that one. In theory, you could synthesize a new DDR, but the documentation for the APM format is ancient and written assuming the user knows Pascal. I remember hearing something about how OS X doesn’t actually use on-disk driver information any more, so you might be able to get away with just the signature and the fields related to disk size, but you’ll probably have to experiment before you get a DDR that satisfies OS X.

      Good luck…

  7. Andrew says:

    YOU SAVED MY LIFE THANK YOU!!!

  8. Lonnie says:

    in your video tutorial you click on the gpt_surgeon.py link and it takes you to a bat country page, you then click on download file and a download box appears. when i click on the same download file link, it just opens to a new page full of code.

    i downloaded python 2.6, but it doesn’t recognize the gpt_surgeon command in terminal.

    i located the bad partition and everything, just can’t seem to get gpt_surgeon.py to be recognized as a command.

    • George says:

      I had the same issue and downloaded the file from my friends PC and then transferred it to my Mac via jumpdrive. Should help you out

    • Jeremy says:

      If the code is opening in your browser, right-click the download link and select Save Link As… Make sure the file name ends in .py and not .txt or something like that.

  9. [...] to get back to Snow Leopard, but are greeted by "boot0: error" then…you're in luck, here's the fix. You will probably need a spare OSX install to do it though. Filed under: Uncategorized Leave a [...]

  10. George says:

    I’ve have tried all the steps you have listed and everything works fine until the end. When I do the sudo command I get a resource busy error….here is the exact error

    Read MBR and GPT from /dev/disk0.
    Changing type of partition #0 on /dev/disk0 to HFS+…
    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 216, in
    main()
    File “./gpt_surgeon.py”, line 211, in main
    fixGPTPartitionType(diskDevice, selectedPartition)
    File “./gpt_surgeon.py”, line 153, in fixGPTPartitionType
    disk = open(diskDevice, ‘wb’)
    IOError: [Errno 16] Resource busy: ‘/dev/disk0′

    Any ideas of what I can do to get around this? Thanks

    • Jeremy says:

      Usually that means you have to unmount that disk before proceeding. However, /dev/disk0 is usually the boot disk, and if that’s in a state where you’d want to run gpt_surgeon on it, how did you boot?

      • George says:

        Not sure that I understand your question, “how did you boot.” However I know the disk is not mounted. That would be the end of my issues if that were the case. What i do know is that in disk utility the disk name is “disk2s1″ and so when i enter ./gpt_surgeon.py list /dev/disk2 in terminal it shows partition0 as Apple HFS+ format and partition1 also as Apple HFS+ , which seems correct, however the disk still won’t mount.

      • Adam says:

        Same error for me.

        OError: [Errno 16] Resource busy: ‘/dev/disk0′ MacBook-Pro:/ root# ./gpt_surgeon.py list /dev/disk0

        Read MBR and GPT from /dev/disk0.
        partition 0:
        type: EFI System
        name: u’EFI System Partition’
        flags: 0×00000000
        partition 1:
        type: Apple HFS+
        name: u’HD’
        flags: 0×00000000
        partition 2:
        type: Microsoft Basic Data
        name: u’UNTITLED 2′
        flags: 0×00000000

        Then I run:
        OError: [Errno 16] Resource busy: ‘/dev/disk0′
        Adams-Macbook-Pro:/ root# ./gpt_surgeon.py list /dev/disk0

        Read MBR and GPT from /dev/disk0.
        partition 0:
        type: EFI System
        name: u’EFI System Partition’
        flags: 0×00000000
        partition 1:
        type: Apple HFS+
        name: u’HD’
        flags: 0×00000000
        partition 2:
        type: Microsoft Basic Data
        name: u’UNTITLED 2′
        flags: 0×00000000

        I’m booted from the drive (Apple partition).

        Says resource busy.

  11. [...] found the script from this guy who has detailed the problem and fix in his [...]

  12. Yann says:

    Thank you very much :)

  13. Daniel says:

    Wow, thank you so much! I followed your video tutorial and everything worked like a charm (on Snow Leopard as well). May I ask, however, what the leading period is for when executing your script? (./gpt_surgeon.py). As far as I understand, it means current directory but why is that needed? I know this doesn’t directly relate just to your script but probably to execution of any script (although for Shell scripts i usually just do sh script.sh), but just curious. Until I watched your video tutorial, I couldn’t get the script to execute since I didn’t add the leading period :)

    For anyone interested, I screwed up 2 HFS+ discs by assigning them a drive letter in Windows Server 2003 (since it doesn’t mount disks unless explicitly told to). Why this would cause Windows to rewrite the GUID I have no idea as Windows XP assigns drive letters to these same discs fine and without causing any problems.

    Interestingly enough, I found this post by Googling “boot camp 3.0 vs macdrive” trying to figure out whether the HFS reading support added in Boot Camp 3.0 is better than MacDrive. Has anyone experienced or heard of Boot Camp’s HFS drivers doing similar mischief?

    Thanks again!

  14. Vortex566 says:

    I am unable to download the file. Is it still possible to get a copy?

  15. adrian says:

    Help!
    when i run below command I get…what should i do?

    adrian:~/Desktop adrian$ sudo ./gpt_surgeon.py repair /dev/disk1s1

    ./gpt_surgeon.py:35: FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up
    return binascii.crc32(bytes) & 0xffffffff
    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 4, in ?
    import sys, os, struct, binascii, uuid
    ImportError: No module named uuid

    • Jeremy says:

      Since you’re getting a FutureWarning for Python 2.4 and up, and you don’t have the uuid module, which was added in 2.5, my guess is that you’re running a very old version of Python, maybe 2.3. Run python -V and see what version you have. If it’s less than 2.5, you need to upgrade to a newer version of Python for gpt_surgeon.py to work.

  16. Marc says:

    This is something for the pros:

    I got a Mac Pro with 4 2 TB hard disks. After I installed bootcamp on a second partition on my first hard disk and changed the drive letters in Windows 7 to a correct order, half of the drives were gone in OS X. Fortunately, I found this great solution here, which helped me a lot with my HFS+ drives.

    No, here is my specific problem:
    While my HFS+ formatted disks are back in OS X thanks to the tip from this site, I have a big issue with my NTFS formatted boot camp drive (which is on disk 0, partition 2). It couldn’t repair it, coz the tip from this site assumes, I want to save a HFS+ partition. Rigth? But in my case it’s a NTFS hard disk and It needs to be changed back to type: NTFS; right now it’s: Microsoft Basic Data. I need the bootcamp hard disk in OS X, because I want to use Parallels Desktop in OS X. Is there a possibility or a program that changes my bootcamp partition back to NTFS so OS X can mount the hard disk again?

    • Jeremy says:

      Microsoft Basic Data is the GPT type used for FAT16, FAT32, and NTFS. I’m not sure why they overloaded it, but Basic Data is the correct GPT type for any NTFS partition on a GPT drive.

      However, Boot Camp is weird. Normally, a GPT starts with an old-style MBR known as the “protective MBR” which consists of one partition of type 0xEE covering the disk area containing the GPT and the GPT partitions. Boot Camp changes the GPT protective MBR to be an MBR containing the same partitions as the GPT! I don’t know whether OS X believes the MBR entries or the GPT entries when it’s reading drives that have been partitioned by Boot Camp, but my guess would be that it’s reading the MBR. This is just a guess. What I’d do is find something that will display your MBR and see if it’s missing any NTFS partitions. Download disktype (or get it from MacPorts) and see what it thinks is there. If your MBR is screwed up, there’s a utility called gptsync(8) that comes with rEFIt, which does basically the same thing as the Boot Camp installer and synthesizes an MBR that mirrors your GPT.

  17. Marc says:

    Hi Jeremy, thanks for your quick reply. I tried disktype, but am totaly confused by the way it should work – the webpage gives information woth 5 hours of reading! And I don’t really want to mess around with a c compiler. How exactely should I use rEFIt/gptsync to mount my bootcamp ntfs partition back into os x? Thanks for your kind help.

    • Jeremy says:

      There’s not a lot of messing around to do, Marc. Unpack disktype, open a Terminal window, cd into the disktype-9 folder, and type make. Done. The disktype binary will then be in that folder, and you can run ./disktype /dev/disk0. As I said, you could also install MacPorts and then type sudo port install disktype to get disktype. Now, you won’t be able to do either manual compilation or installing from MacPorts if you don’t have Xcode and Apple’s other developer tools installed, so if you don’t have those, go get them. I forget whether they still ship with Apple’s install discs, but http://developer.apple.com/ should have Xcode somewhere.

      Let’s do this in steps. I have to head off to work soon, so you try to build disktype and post a comment reply with the output of the disk you’re having problems with. If you have problems compiling, I’ll see if I can find a prebuilt disktype somewhere, but it may have to wait until tomorrow.

      • Troy says:

        HI Jeremy – not sure if you have closed this issue, but I am having the same issue as Mark.

        I was unable to make disktype with normal params, so I had to use make NOSYS=1 – which allowed it to compile perfectly.

        Once I run ./disktype, I get the following output:

        — /dev/disk0
        Block device, unknown size
        DOS/MBR partition map
        Partition 1: 200.0 MiB (209735168 bytes, 409639 sectors from 1)
        Type 0xEE (EFI GPT protective)
        Partition 2: 109.9 GiB (117977382912 bytes, 230424576 sectors from 409640)
        Type 0xAF (Mac OS X)
        HFS Plus file system
        Volume size 109.9 GiB (117977382912 bytes, 28803072 blocks of 4 KiB)
        Volume name “MacBookPro”
        Partition 3: 100 MiB (104857600 bytes, 204800 sectors from 230836224, bootable)
        Type 0×07 (HPFS/NTFS)
        NTFS file system
        Volume size 100.0 MiB (104857088 bytes, 204799 sectors)
        Partition 4: 355.6 GiB (381812736000 bytes, 745728000 sectors from 231041024)
        Type 0×07 (HPFS/NTFS)
        NTFS file system
        Volume size 355.6 GiB (381812735488 bytes, 745727999 sectors)
        GPT partition map, 128 entries
        Disk size 465.8 GiB (500107862016 bytes, 976773168 sectors)
        Disk GUID 0CA7211B-11B9-214F-8971-220B337E16CA
        Partition 1: 200 MiB (209715200 bytes, 409600 sectors from 40)
        Type EFI System (FAT) (GUID 28732AC1-1FF8-D211-BA4B-00A0C93EC93B)
        Partition Name “EFI System Partition”
        Partition GUID 3AF177CC-757B-834A-BED6-51A78AA8168D
        FAT32 file system (hints score 5 of 5)
        Volume size 196.9 MiB (206472192 bytes, 403266 clusters of 512 bytes)
        Volume name “EFI”
        Partition 2: 109.9 GiB (117977382912 bytes, 230424576 sectors from 409640)
        Type Mac HFS+ (GUID 00534648-0000-AA11-AA11-00306543ECAC)
        Partition Name “Untitled”
        Partition GUID 8DA6D871-58A3-D642-A313-9F875B8557F5
        HFS Plus file system
        Volume size 109.9 GiB (117977382912 bytes, 28803072 blocks of 4 KiB)
        Volume name “MacBookPro”
        Partition 3: 355.6 GiB (381785473024 bytes, 745674752 sectors from 231098368)
        Type Basic Data (GUID A2A0D0EB-E5B9-3344-87C0-68B6B72699C7)
        Partition Name “BOOTCAMP”
        Partition GUID 2FFE3BC0-913A-BE41-A2D7-5F4ABF480DB4
        Partition 4: unused

        This is a “stock” MacBook Pro running Snow Leopard. The Partition that I am having problems with is Win 7 Pro 64 bit. I can boot into bootcamp no problem, but cannot mount from inside os x. I am trying to mount the bootacamp volume in Parallels.

        Thanks.

  18. Jeremy!

    Your gpt_surgeon.py worked like a charm!
    Thanks a million!

    Here’s the a copy and paste from my terminal:

    Alum:Downloads def$ ./gpt_surgeon.py list /dev/disk1

    Read MBR and GPT from /dev/disk1.
    partition 0:
    type: EFI System
    name: u’EFI System Partition’
    flags: 0×00000000
    partition 1:
    type: Microsoft Basic Data
    name: u’Untitled’
    flags: 0×00000000
    Alum:Downloads def$ ./gpt_surgeon.py repair /dev/disk1 1

    Read MBR and GPT from /dev/disk1.
    Changing type of partition #1 on /dev/disk1 to HFS+…
    Opened /dev/disk1 for writing.
    Wrote MBR.
    Wrote GPT header.
    Wrote GPT entries.
    Closed /dev/disk1.
    Done.
    Alum:Downloads def$ diskutil list
    /dev/disk0
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *298.1 Gi disk0
    1: EFI 200.0 Mi disk0s1
    2: Apple_HFS Untitled 297.8 Gi disk0s2
    /dev/disk1
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *298.1 Gi disk1
    1: EFI 200.0 Mi disk1s1
    2: Apple_HFS M6-320 297.8 Gi disk1s2

  19. Blue Buzzard says:

    Hello,

    Upon upgrade to latest version of MacDrive on my Win 7 volume my bootable mac Leopard volume was not recognized by MacDrive. I assigned a letter to the Leopard volume and it was seen by MacDrive. When I tried to boot the Leopard volume booting failed. It seems when I changed the drive letter I also lost the active partition for Leopard. I tried disk utility and got message “invalid BS_jmpboot in boot block: fa31c0″. I found a program that let me get my Leopard partition active and bootable. it’s called Ext2Fsd.

    What’s Ext2Fsd
    ==================================

    The Ext2Fsd project is an ext2 file system driver for WinNT/2000/XP.
    It’s a free software and everyone can distribute and modify it under
    the terms of GNU GPL.

    ==================================
    Author & Homepage
    ==================================

    Matt
    http://ext2.yeah.net

  20. Lance says:

    hey there,

    when I type “$ ./gpt_surgeon.py list dev/disk1s1″ I get

    ./gpt_surgeon.py: line 5: syntax error near unexpected token `newline’
    ./gpt_surgeon.py: line 5: `’

    Has anyone ever had that proble before?

    Thanks so much

  21. Jason says:

    You saved my life too!!! THANKS. I had no clue how I was going to be able to get my Snow Leopard disk to boot.

  22. Alex says:

    I have mistakes running the script

    ./gpt_surgeon.py list /dev/disk2s2

    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 216, in
    main()
    File “./gpt_surgeon.py”, line 202, in main
    listGPT(diskDevice)
    File “./gpt_surgeon.py”, line 140, in listGPT
    _, gpt = readMBRAndGPT(diskDevice)
    File “./gpt_surgeon.py”, line 134, in readMBRAndGPT
    gpt = EFIPartitionTable(disk)
    File “./gpt_surgeon.py”, line 50, in __init__
    assert sig == efiSignature

    • Jeremy says:

      You probably have a different kind of disk corruption from that which gpt_surgeon.py was designed to fix. Look at Lenny’s comment; he had a similar problem. Try to get me some disktype output if you can.

      It’s long past time to replace the debug asserts with real error messages… but my day job at Microsoft has been keeping me pretty busy, and my only Intel Mac got integrated into the home theater somehow. It’s hard to grab time on it at the moment.

  23. Jonathan says:

    Hey Jeremy,

    Thank you so much for figuring this out and posting the help online. The video, the script, the tutorial, everything. You helped me, and I’m sure a ton of other people so much.

    I noticed you don’t have a paypal donation button or an amazon wishlist. You should put one up.

  24. Owen says:

    Thanks!

    I ended using Disk Management in Windows 7 to reformat one partition of a new drive (with some other files backed up on the HFS+ portion).

    Long story short: This python script was exactly what I needed.

    Glad that you titled the page after the error or I might never have found it.
    Thanks,
    Owen

  25. Foobard says:

    Thank you sooo much for this. I spent quite a bit of time trying different things, and then I googled the error message I was getting, and I found this page. Your script fixed both my time machine partition and my cloned partition on my external drive. I was fooling around with Windows 7 partitioning on my external drive, and hosed my mac partitions.

    This totally worked. And the video helped a lot!

    one bit of advice to your readers, if you hosed 2 partitions, once you recover the first one, you need to unmount or “eject” the partition you just recovered, before the script will be able to recover the second one.

    Thanks!

  26. John says:

    Thanks – great little utility. I’ll keep it tucked away just in case…
    Managed to trash my Mac boot partition in Windows 7 trying to hide the Mac disk away from Windows.
    Disk utility said it couldn’t repair the partition and suggested I reformat and reinstall – no way!
    Installed Mac OS X to external USB drive, booted up, downloaded this utility and was fixed the internal disk drive partition in 5 mins!

    • Nayla says:

      How you did it? with my disk is not working.
      I have a Mac OS X 10.4.11 Prozessor 2.16 GHz Intel core 2 Duo

  27. Andrew says:

    I have just encountered the joy of this error myself on 3 drives which contain all of my video editing work over the last year and backups!

    I don’t have MacDrive installed – the plan was to upgrade my licence from version 7 to 8 which supports Windows 7.

    I have just installed a dual boot on my macbook pro with Snow Leopard / Windows 7. The problems started after I changed the drive letters in Windows of the mac HFS+ formatted drives. Windows can see and read the discs fine but Snow Leopard complains about the invalid BS_jmpboot etc.

    I can’t take the chance that this will not work so I have to wait for 2 new 2TB drives to arrive so I can copy across all my data in Windows before trying to repair things.

    What a joy!

    • Andrew says:

      5 days later and I have almost recovered everything. The testdisk program worked a treat on most drives except for one which was setup as raid. Tried to recover the boot sector on that one but I didn’t understand how to use testdisk for that situation!

      I bought Tuxera NTFS so that I would be able to read and write to NTFS drives from osx and windows but something happened with it and one drive got corrupted. Had to use diskcheck on windows to get it back which worked, but it took hours so it seems I can’t rely on Tuxera. Think I will just upgrade MacDrive as I have not had any problems with it before.

      A cross platform file system wound be nice for those of us who have to work with large files on both osx and windows!

  28. Nayla says:

    hello, i tried to do everything like you say but it not working. i really need to fix my external Disk, i have my life on it. this is like apear when i tried.

    Last login: Tue Feb 23 11:57:44 on ttyp1
    Welcome to Darwin!
    macintosh-3:~ Nay$ cd Desktop/
    macintosh-3:~/Desktop Nay$ chmod+x gpt_surgeon.py
    -bash: chmod+x: command not found
    macintosh-3:~/Desktop Nay$ chmod +x gpt_surgeon.py
    macintosh-3:~/Desktop Nay$ ./gpt_surgeon.py list /dev/disk1s1
    ./gpt_surgeon.py:35: FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up
    return binascii.crc32(bytes) & 0xffffffff
    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 4, in ?
    import sys, os, struct, binascii, uuid
    ImportError: No module named uuid
    macintosh-3:~/Desktop Nay$ ./gpt_surgeon.py list /dev/disk1
    ./gpt_surgeon.py:35: FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up
    return binascii.crc32(bytes) & 0xffffffff
    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 4, in ?
    import sys, os, struct, binascii, uuid
    ImportError: No module named uuid
    macintosh-3:~/Desktop Nay$
    could you please help me.
    sorry my english ist not very good but i can understand must of all.
    Thanks a lot.
    Nayla

  29. Dafa Chen says:

    hello, Jeremy.
    I have mistakes running the script, too.

    dafa-chens-mac-pro:Desktop DFC$ ./gpt_surgeon.py list /dev/disk1s1

    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 216, in
    main()
    File “./gpt_surgeon.py”, line 202, in main
    listGPT(diskDevice)
    File “./gpt_surgeon.py”, line 140, in listGPT
    _, gpt = readMBRAndGPT(diskDevice)
    File “./gpt_surgeon.py”, line 132, in readMBRAndGPT
    disk = open(diskDevice, ‘rb’)
    IOError: [Errno 13] Permission denied: ‘/dev/disk1s1′

    Could you help me? Thanks!

    • deviceisbusy says:

      run as root:
      dafa-chens-mac-pro:Desktop DFC$ sudo ./gpt_surgeon.py list /dev/disk1s1

  30. deviceisbusy says:

    It is actually a very handy and useful script. But i have alot of trouble to make it executable, like fixing indentations .
    Now i have the working .py version, May be it is better to put this on a sharing web site like mediafire, etc as alot of people got this problem. But i am not the script owner…

    My problem is IOError: [Errno 16] Resource busy: ‘/dev/disk2′
    Anyone know how to solve this? thxinadv.

    • Jeremy says:

      That usually means you have a mounted volume on that disk. Try sudo diskutil unmountDisk /dev/disk2.

      About the indentation problem, did you use the Download File link in the SVN browser? Perhaps I should clarify that in the main post. It’s in the video walkthroughs.

      • deviceisbusy says:

        Thanks for the reply.
        But i still can’t get it repair with that either.
        May be because i’m using another mac os on the same disk?

        Sorry about the download link, i missed that on my safari.

  31. Craig says:

    Thank you so much for gpt_surgeon.py.

    My external disk had been corrupted by boot camp 3 + Windows Vista, when I unassigned Disk letters for my external Mac PGT/HFS+ partitions.

    This was a life saver.

  32. raphael says:

    i got the busy-error too:

    IOError: [Errno 16] Resource busy: ‘/dev/disk1′

    i m using a macbook and, i guess the disk is busy because i m working on it.
    i have booted from an external drive which is connected with the macbook on which there is one partition, which i want to repair.
    has anyone suggestion please?

  33. raphael says:

    appendix:

    according to disk utility, the disk is NOT mounted…but nevertheless it is apparently busy…

  34. Antoine Meyer says:

    Thank you so so much
    I spent all afternoon searching for a solution and your solution in this webpage works perfectly and is great !

    Thank you again
    Antoine

  35. Ian Bowell says:

    Superb solution.
    This issue affected a Mac Book Pro that had had Win7 64 bit boot camp installed and then removed in favour of Parallels.
    Following a couple of reboots and working operation the laptop suddenly stopped booting and the Mac OS install disk couldnt repair the disk (surprising for such a simple issue). Of course, as you have stated it simply thought the primary disk was a microsoft disk and not HFS.
    Spent some time with Tech ToolPro (and Data Rescue3) to no avail but on putting the laptop into target disk mode (Hold T while booting) we were able to connect it to another laptop via Firewire and install python on the second laptop and run your script on the firewire mounted disk.
    Et Voila!!!
    Your tool marked the problem disk as HFS+.
    You beauty – the hosed laptop rebooted as if nothing had happened.

    Thanks soo much.

    No amount of searching on Apple’s website or trying to speak to supposed geniuses at the world’s largest Apple store could help (before the appointment a week later!)

  36. Ash says:

    Thank you! Worked perfectly the first time I tried it!

  37. robert says:

    Ok, here is the error I get. I am running Python 2.7, by the way on Mac OSX 10.5.8

    robert-macbook-pro:~ robertcluesman$ cd Desktop/
    robert-macbook-pro:Desktop robertcluesman$ chmod +x gpt_surgeon.py
    robert-macbook-pro:Desktop robertcluesman$ gpt_surgeon.py list /dev/disk1s1
    -bash: gpt_surgeon.py: command not found

    please help.

    ps, i am a newbie at this.

    • robert says:

      i also get this error

      robert-macbook-pro:Desktop robert$ ./gpt_surgeon.py list /dev/disk1s1
      ./gpt_surgeon.py: line 5: syntax error near unexpected token `newline’
      ./gpt_surgeon.py: line 5: `’
      robert-macbook-pro:Desktop robert$

      • robert says:

        Sorry to keep this up but I am trying a few different things. I tried to run the script directly from python and I get this error…

        Last login: Tue Aug 3 15:27:13 on ttys000
        robert-cluesmans-macbook-pro:~ robertcluesman$ cd ‘/Users/robertcluesman/Desktop/’ && ‘/usr/bin/pythonw’ ‘/Users/robertcluesman/Desktop/gpt_surgeon.py’ && echo Exit status: $? && exit 1
        File “/Users/robertcluesman/Desktop/gpt_surgeon.py”, line 5

        ^
        SyntaxError: invalid syntax
        robert-cluesmans-macbook-pro:Desktop robertcluesman$

  38. Spoolio says:

    Dude–you just saved me two computers worth of backups. I let windows reformat a partition on the drive with two TM parts–bad move. Good code.

  39. [...] macdrive, python, snow leopard, windows | 1 Comment  Assuming all goes well with the import, gpt-surgeon will have a new home on Launchpad! Look for it at [...]

  40. Séb says:

    hello

    Can’t use it with disk0:

    iMac-de-Sebastien-Dominguez:Desktop Sebastien$ ./gpt_surgeon.py list /dev/disk0

    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 216, in
    main()
    File “./gpt_surgeon.py”, line 202, in main
    listGPT(diskDevice)
    File “./gpt_surgeon.py”, line 140, in listGPT
    _, gpt = readMBRAndGPT(diskDevice)
    File “./gpt_surgeon.py”, line 132, in readMBRAndGPT
    disk = open(diskDevice, ‘rb’)
    IOError: [Errno 13] Permission denied: ‘/dev/disk0′

    • Jeremy says:

      You can’t edit the disk you’re booted from. If you’re not booted from disk0, then something probably has it open and you need to unmount it. Try running diskutil unmountDisk /dev/disk0.

  41. robert says:

    Here’s the latest error. Can anyone PLEASE help?

    robert-cluesmans-macbook-pro:Desktop robertcluesman$ chmod +x gpt_surgeon.pyrobert-cluesmans-macbook-pro:Desktop robertcluesman$ ./gpt_surgeon.py list /dev/disk1

    Traceback (most recent call last):
    File “./gpt_surgeon.py”, line 216, in
    main()
    File “./gpt_surgeon.py”, line 202, in main
    listGPT(diskDevice)
    File “./gpt_surgeon.py”, line 140, in listGPT
    _, gpt = readMBRAndGPT(diskDevice)
    File “./gpt_surgeon.py”, line 134, in readMBRAndGPT
    gpt = EFIPartitionTable(disk)
    File “./gpt_surgeon.py”, line 50, in __init__
    assert sig == efiSignature
    AssertionError
    robert-cluesmans-macbook-pro:Desktop robertcluesman$

  42. [...] no, hay solución. Está aquí. Otro geek de la más alta alcurnia se ha encontrado con el mismo problema y ha creado una [...]

Comments are closed.

Follow

Get every new post delivered to your Inbox.

Join 1,150 other followers

%d bloggers like this: