boot - How to write to both GPT and MBR manually?

27
2013-10
  • hanoijolly

    I have a big deal here. I have a MacBook with three partitions:

    1. HFS partition for Mac OS X 10.6
    2. NTFS partition for Windows 7 64-Bit
    3. NTFS partition for my documents

    It thus works with both GPT and MBR. I use rEFIt to switch the system at boot.

    Having had troubles with my Windows roaming increasing dramatically (what a pain), I had to increase the size of my second partition after reducing my third partition...

    My problem is that my partitioning tool did a mess with the GPT and the MBR (I am a beginner to these systems and I used EaseUS's tool to work on the partitions. It was a big mistake.)

    Now I have the following.

    In the GPT

    Partition  Start LBA     End LBA Type
    
    1                 40      409639 EFI System (FAT)     ⇐ The boot sector, I guess
                                                          ⇐ I miss my Mac OS partition (the entry was suppressed by Easeus)
    2          126240768   252067839 Basic Data           ⇐ My Windows partition
    3          278693928   976773165 Basic Data           ⇐ My Documents partition at the right place
    

    In the MBR

    Partition   Start LBA    End LBA Type
    
    1                   1     409639 EE               ⇐ The boot sector I guess
    2              409640  125976615 AF Mac OS X HFS+ ⇐ My Mac OS partition at the right place etc
    2           126240768  252067839 07 NTFS/HPFS     ⇐ my Windows partition
    3           252069888  976773165 07 NTFS/HPFS     ⇐ my Documents partition at the WRONG old place
    

    rEFIt offers me to automatically copy the content of my GPT to my MBR: It would give me back access to my "documents" partition, but I would lose my OS X partition.

    How do I manually write in those GPT and MBR to setup both sides? I heard it would be possible with UBCD …

  • Answers
  • hanoijolly

    Thank you for your advices.

    I followed them and got help from Rod Smith (creater of gdisk).

    The problem came from the fact that Easeus (the partition tool I used) was not aware of "hybrid MBR/GPT" systems. It did a mess thus.

    Here were the steps to be taken : 1) using gdisk I repaired the GPT : - added the missing Mac partition (command 'n' in gdisk stating the type AF and the begin and end position) - sorted the partitions for it to become the second one as expected (command 's' in gdisk) 2) I have recreated the hybrid MBR based on these data ('x' command and then 'h' command in gdisk).

    Of course, Gdisk allows also to create a backup of both partitions tables. That is a great tool and Rod's documentation on his website rodsbooks.com is great too (with examples and so on).

    If you have a dual boot Mac with Windows that is great to correct your messed up partitions.

  • harrymc

    You could use GParted.

    Its Live CD includes the package gdisk (GPT fdisk) which can repair GPT/MBR inconsistencies. It might be enough for your needs.

    I suggest that you first read very carefully the tutorial, and especially the section Repairing GPT Disks.


  • Related Question

    windows 7 - More than 4 primary partitions on MacBook with rEFIt (GPT/MBR syncing)?
  • fideli

    I currently have a triple-boot on my MacBook (OS X 10.6.5, Windows 7, Ubuntu 10.10) which works very well. I'd like to now make an ExFAT storage partition that would be shared amongst the three OS's, with the importance on sharing between Windows and OS X. This is what it looks like right now:

    $ diskutil list
    /dev/disk0
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *500.1 GB   disk0
       1:                        EFI                         209.7 MB   disk0s1
       2:                  Apple_HFS MacOSX                  400.0 GB   disk0s2
       3:       Microsoft Basic Data BOOTCAMP                74.5 GB    disk0s3
       4:       Microsoft Basic Data                         25.3 GB    disk0s4
    

    There are, it appears, 4 partitions on the drive already, since the EFI requires 200 MB in the beginning. I'm wondering if I were to add another partition whether that would mess up the GPT/MBR syncing that rEFIt does for me because there would be more than 4 primary partitions on the disk. I will likely use iPartition for this.

    EDIT
    To add to the complexity, for unrelated reasons I decided to switch from Ubuntu to Fedora on that last partition. During the install, my curiosity made me select the recommended two partition setup with /boot going on a 500 MB /dev/sda4 and / in an LVM on /dev/sda5. The drive now looks like this:

    $ diskutil list
    /dev/disk0
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *500.1 GB   disk0
       1:                        EFI                         209.7 MB   disk0s1
       2:                  Apple_HFS MacOSX                  400.0 GB   disk0s2
       3:       Microsoft Basic Data BOOTCAMP                74.5 GB    disk0s3
       4:                        EFI                         524.3 MB   disk0s4
       5:                  Linux LVM                         24.8 GB    disk0s5
    

    When I re-synced rEFIt, it suggested an MBR table that only had the first 4 partitions on it. Will try to get that info to add to this next time I reboot.

    EDIT
    Turns out that that you can't have more than 4 primary partitions with the GPT/MBR sync. In retrospect, it all makes sense now. I decided to just go ahead and test this so I created a 25 GB partition on the end of the drive. Looks like this now:

    /dev/disk0
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *500.1 GB   disk0
       1:                        EFI                         209.7 MB   disk0s1
       2:                  Apple_HFS MacOSX                  373.4 GB   disk0s2
       3:       Microsoft Basic Data BOOTCAMP                74.5 GB    disk0s3
       4:                        EFI                         524.3 MB   disk0s4
       5:                  Linux LVM                         24.8 GB    disk0s5
       6:       Microsoft Basic Data Transfer                26.6 GB    disk0s6
    

    Used OS X to format the last partition as exFAT (volume name Transfer). Used rEFIt to sync the GPT and MBR tables. Only showed up to 4 (which answers this question), which doesn't show up in Windows (which was expected). Next, I downloaded an OS X binary of the gptsync.efi program that rEFIt uses from the InsanelyMac forums and ran the following command to select the GPT partitions I wanted in the MBR table (1, 2, 3, and 6):

    sudo gptsync /dev/disk0 2+af 3-07 6-07
    

    thinking that the MBR type is 07 as listed on the exFAT WikiPedia page. When I rebooted into Windows again, the partition showed up in diskmgmt.msc, but as a RAW format. Upon accessing it in Explorer, I get the option to format it. I decided to try using a different MBR code and ran the following command again in OS X:

    sudo gptsync /dev/disk0 2+af 3-07 6-0c
    

    which did not resolve the problem. A cursory search suggests that exFAT is only meant to be used on external volumes, and that Windows would not load an internal partition formatted as exFAT. So, two things: (1) I either still have the MBR code wrong or (2) it just won't be read by Windows.


  • Related Answers
  • Everett

    I did exactly this (Win7 64, Ubuntu 10 64bit, OS X 64 bit, and an ExFAT part). When I found out that Customs could search a laptop at will without a court order in violation of the Constitution, I chose to move the ExFAT to a 128GB ExpressCard SSD (100 GB ExFAT set up for user space, 8 for each OS swap file, and the leftover space as RAM for Win7 to use).

    This way all three systems could use the ExFAT as user space, it wasn't physically on the computer (it's removable), and since I was using 2 drives (one for OS/Apps, the other for user space/swap space) I sped up my system (not a huge amount).

    If I had to worry about anyone wanting to see what was on my computer, I simply removed the user/swap space. I have licenses for all the Apps and the OS's on my Apps/OS drive. There are no applications that are unlawful for me to own/use to the best of my knowledge. I use Launchbar to search my user space (because the database for it is kept on the user space not on the OS/App space like Spotlight). I just wanted to give you food for thought.