Bootcamp Partition Lost Repairing Mac Partitions

Today I changed my Macbook partition sizes and Windows Bootcamp would not show in the Boot menu. Here are the steps I used to fix it. I got these from an Apple forum post.

The 45 page long Apple forum post I used is here: https://discussions.apple.com/thread/4144252?start=0&tstart=0

Warning and disclaimer.  I am in no way responsible for you following these instructions and breaking anything.  Please read them carefully, if there is anything you do not understand or do not know then please STOP!  Although what we are doing is simple, a mistake can lead to big problems that I do not know how to fix.  Read the instructions carefully and consider your options.

How It Started – Macbook Resizing OS X Partition

I had a partition of Macbook OS X Mountain Lion and Windows 7 on Bootcamp.  I needed more space on the Windows side so I decided to use Disk utility on the Macbook to shrink the size of the Mac partition, and use the spare space to make a third partition in exfat format.  Bad idea! because modifying the core Mac partition modifies the MBR (Master boot record), and removes Bootcamp from the startup menu.

Bootcamp still exists in it’s own partition, it’s just that the boot process on the Mac does not know to look there for a bootable thing.

The solution is to fix the Master Boot Record and tell it that it should add the Windows 7 Bootcamp partition to the bootable drives list it has.

Warning 2 – this is simple, but scary.  We will be using terminal and reading things carefully.  If you can not do either of these two then find someone who can.  I will provide full instructions to allow me to repeat this process to fix the partition MBR if it ever happens for me again, so you know it should be good.

How to Fix the Broken Bootcamp Partition after Resizing Mac OS X Partition

First, we need to download some software to handle the partition fixing.  Get gptfdisk from here:

http://sourceforge.net/projects/gptfdisk/

Download the latest version (I used 0.8.6) and because you’re on a Mac you will need the .pkg version.

Once you have downloaded gptfdisk double click the file and install the .pkg file that downloaded.  That’s all the software we’ll be using.  Now it’s just you and terminal.

NOTICE – Now is a good time to plug your Macbook in to charge, you don’t want the power going out while changing the MBR.  Trust me.  Also a great time to BACKUP everything on your Mac and Windows Bootcamp partition.  I just backed up my Mac side because I like to live dangerously and my Windows Bootcamp partition is just for games and testing.

Now back to fixing.

Open terminal.  For a quick shortcut to open it press (CMD + spacebar) to open the spotlight quick search and type terminal.  That will open terminal.  It has >_ as it’s icon.

Let’s see what the state of your MBR is first.  Type these three things.  After each one press enter.  You will need your password for them because we use sudo.  None of the lines change anything on your computer and are used so you can get information about the state of your MBR and partitions.  Type carefully, and that is a vee vee not double you on line 1, and it is disk-numberzero not disk-oh.

  1. sudo gpt -r -vv show disk0
  2. sudo fdisk /dev/disk0
  3. diskutil list

One shows you disk status and partitions.  Two shows you types and three shows you your hard disk partition setup.  Three is the most important.

Output of line 3:

#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *250.1 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS SSD 125.0 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s5
4: Microsoft Basic Data exfat1 24.2 GB disk0s6
5: Microsoft Basic Data BOOTCAMP 100.0 GB disk0s4

IMPORTANT! note down the number on the left of BOOTCAMP when you do line three above!  For me this number was 5.  For you it might be 4.  This is what we will use to tell the MBR it’s a boot drive.

That’s the setup and preparation complete.  Now it’s time to go deep.  Open a new terminal window.  Anywhere that says <enter> means press enter.

Type the following line to start disk:

sudo gdisk /dev/disk0

r <enter>        go to the recovery & transformation menu

h <enter>        create a new hybrid MBR.

STOP! the next line is the most important.  Use whatever your bootcamp partition was above when we did line 3.  My Bootcamp partition on my Mac was 5.  Yours may be 4 or even 3.

5 <enter>        add partion 5 to the MBR.  Your’s may be different! Use what you got from line 3 above.

y <enter> if you are asked “Place EFI GPT (0xEE) partition first in MBR (good for GRUB)?”

<enter>          accept the default MBR hex code of 07

y <enter>        set the bootable flag

n <enter>        do not protect more partitions

o < enter>       print (display) the MBR.

You will see a message telling you it’s go time to actually write the partition.  It will say “Disk size is …” and list two MBR partitions it will make.   This is essentially a notification of what the new MBR will look like.  Look at it and if it looks acceptable then hit w <enter> to write out the table:

w <enter>     Recovery/transformation command (write partition table to disk)

y <enter>  Say yes to question: do you want to proceed.

It will recommend you reboot your Macbook.  Do it and when it’s booting up hold the left ALT/option key like you always do to boot up into Bootcamp.  It should work.

If it did work, great!  Don’t do it again :)  If it didn’t work…try the link at the top to the Apple forum post.  It’s 45 pages long right now so good luck with that but the guy seems very helpful.

Final disclaimer.  This post is for my personal use only and I accept no responsibility for anything you do with it or if anything bad or good happens because you followed the instructions above.  This fix worked for me once and will hopefully work next time I accidentally destroy my Bootcamp partition and stop Windows bootcamp from booting or showing in the startup choice menu when starting my Mac.


Leave a Reply

Your email address will not be published.


+ 4 = 5

Custom Search

25 Responses to Bootcamp Partition Lost Repairing Mac Partitions

  1. Hi,

    Thank you very much because it was helpful to me!
    I was afraid I had to reinstall Windows and all the games.

  2. Thank you so much, you all awesome!!!!!!!.

  3. It works like a charm, now how could we create a script to include all those command above and run it as one click, because I need to fix the MBR using that command line to more than 20 Mac?

    Any help really appreciated.

    • I’m not too good with Mac scripting, and you really do need to make sure you’re doing it right because a mistake is expensive. Manually is the way forward YS.

  4. This worked like a charm. I thought I need to repartition and reinstall Windows. This did the trick. Thank you.

  5. Wow thx! It was very helpful to me. Every time I update or reinstall os x, the bootcamp issue was alway followed. So I always reinstalled bootcamp again and again…
    anyway, thx so much.

  6. Thank you, your direction was perfect
    the problem was a result of creating new partition to use for data. Now i can reboot windows but can not see the new partition in (my computer) nor in the windows disk management, which still shows one MAC partition and one bootcamp partition. Can you help?
    Kind regards.

  7. It won’t boot with Parallels Desktop and Boot Camp partition is not found in System Pref>StartUp Disk.

  8. Thank you very much! You just saved my life. Although, Boot Camp Assistant not showing remove Windows option. Do you have any idea?.

  9. Boss!

    Thank you a LOT! It did work! Somehow the option to choose the damn Windows has vanished from boot selection. I’ve done exactly what you said and MBR was recovered. After I rebooted mac into windows there were a few BSODs with very important values of Stack Pointer and other Pentium Processor Registers :) and after few extra hiccups it was able to boot. So I guess something bad in windows gut has happened. Again, thank you
    \m/.

  10. Excellent, great, good for me, Windows back to work again. Thanks a lot.

  11. This is awesome :)
    Thanks for putting it together so readably.
    I want take note of 3 things though that some new readers may encounter:

    1) When I type the “o ” command as you describe above, the displayed MBR is *not* the same as in the preliminary Step 3. Mine only shows 2 things instead of 4 or 5, but your fix still worked fine for me.
    BUT, if like me, your MBR shows only two things, this will be a great time to close the Terminal, backup you WHOLE hard drive with Apple’s Time Machine utility or by using the first link I have at the of this post. Only continue with the restore *after* performing a full backup.

    2) After fixing you MBR, remember this an unofficial unsupported hack-like-thing, so be careful when making any other changes to your partitions *including* using Apple’s own Disk Utility app or the Boot Camp Assistant app. They WILL brake your bootcamp again.
    Ask me how I know: I just did it. And I had fixing my bootcamp, again. (I may post more details on this after I do some more testing.)

    3) SUPER IMPORTANT: If you Mac is or was encrypted, **BACK IT UP NOW**. If something bad happens, you WILL loose EVERYTHING, no joke. And when every you mess with the Master Boot Record (or the equivalent in you OS), bad things can happen very easily.
    Ask me how I know… Two weeks ago I did something really dumb, and my Windows (8.1) destroyed/annihilated the Master Boot Record. And because my hard drive was encrypted, I lost *all* of the data on my computer. To make matters worse, my backup was about 6 months old…

    So, word to the wise, back up your computer now.
    And if your hard drive is encrypted, I would recommend being VERY careful about any changes you make to MBR or the partitions.

    ~ ~ ~ ~ ~ ~ ~

    But what if the worst does happen?

    Well, if it does, the following links *may* save ‘some’ of your data.
    http://hints.Macworld.Com/article.Php?Story=20050302225659382
    http://www.Cgsecurity.Org/wiki/PhotoRec
    Each of the above options took my computer somewhere between 20-40 hours to complete, and I have a Solid State internal drive, so BE PATIENT.

    If you are using the dd command from link 1, you can check the progress by pressing either control+t or command+t while still in the Terminal.

    Also both of the programs in the above links will need an external hard drive of AT LEAST the same size as your internal disk, but preferably bigger. For example, my internal HD was ~500 GB, so we bought a 1.0 TB disk (USB3 for $80) to perform this backup.

    Before you spend $80 though, just be aware that most likely you will recover hundreds-of-gigabytes of junk (i.E. Damaged files) and only a handful of *usable* data. So don’t have you hopes up very high.

    If all else fails, below is one more link. Theoretically, the program on this link can do awesome things, but it looked pretty advanced, so I didn’t try it. I’m attaching it here just in case you want to use it. But try the other options first before this one, and make sure you read the documentation page “TestDisk Step by Step” before attempting to make your own repairs with it. Like I said it looked a little advanced for me so I didn’t try it (yet) ;).
    http://www.Cgsecurity.Org/wiki/TestDisk

    Best,
    Vlad.

    • I don’t know why but the links I posted got screwed up. Most of them still work, but here’s the one that doesn’t:

      Link 1 from my previous post
      And here it one more time as plain text:
      http://hints.Macworld.Com/article.Php?Story=20050302225659382

      Vlad :).

      • It still doesn’t work…
        Ok just copy and pate the link and manually change all of the capital letters to lowercase.
        For some reason it keeps capitalizing parts of my hyperlinks.
        Oh well,
        Vlad.

      • Copy and Google search that text link to view the dd article Vlad is covering here. It’s the auto comment system auto capitalising everything after a period that stops links working normally. Thanks Vlad! And yes, 100% backup everything, then test your backup to be sure, before changing anything in MBR.

        • Oh great idea! I just tried that googleing trick and it worked great :)

          PS. I just found out about a really serious issue that could happen when you’re using your 3rd partition along with Bootcamp, and I was hoping you could a warning about it to your main post so that other users won’t try to do what I just did.

          _____________
          If anyone wants to follow the instructions below, make sure you backup your whole computer before trying any of this. You’ve been warned….
          _ _ _ _ _ _ _

          What happened:
          Ummm… I guess the best way to put it is: I desynchronized my 3rd partition’s file system. In other words, when Windows looks at it, it actually sees different data than what Mac sees. :/

          Yes, it’s like having two different partitions writing to the same space in memory… aka a really bad situation.

          How it happened:
          I was using Windows in Bootcamp, and I needed to go back to my Mac. So I put Windows into hibernate, turned on my Mac, and put 30+ megabytes of stuff onto my 3rd partition (formatted as FAT by the way). Now after having those files there, I shutdown Mac and woke Windows from hibernate. But when I tried to access the third partition, none of the new files were there.

          I tried several different ways of finding the files: refreshing the folder, and command lining through a MinGW Unix terminal (using the ls -a command). None of them worked, and Windows still didn’t see the files.

          So affectively I created a fork in the file system. Great (extreme sarcasm)

          How I fixed it:
          I tried two way:

          Simple fix: I shutdown Windows completely, and when it turned on some of the missing files were there. But some were corrupted.

          Knowing that corrupted files are generally a bad sign, I didn’t want to risk damaging any of my computer’s other partitions. So I used a stronger fix.

          The thorough fix: Went back to Mac OSX, saved the files from the 3rd part ion to my desktop, then opened Disk Utility and did the following:

          1) Clicked on my third partition >> clicked Erase >>Erase…

          2) Clicked the third partition again >> Erase >> choose the “Mac OS Extended (Journaled, Encrypted) as the new format >> Erase…

          Having done the above now allows me to use the “Erase Free Space…” option. Doing this will ensure that nothing is left over from the Windows file system.

          3) Clicked the 3rd partition again >> Erase Free Space…

          In option 3, I used the lowest setting when erase the free space. You shouldn’t need anything more secure than that.

          4) Repeat step 2, but now use your preferred file system (I personally use MS-DOS FAT, but it’s up to you).

          5) Doing this through fix broke your Bootcamp again, so repeat the same procedures as detailed in the Nerdr’s original article (i.E. This whole webpage LOL).

          Good luck with fixing you systems folks.

          Final Recommendations:
          Do NOT use hibernate if you have Windows in Bootcamp, or if you have to, try not to make any changes to any files, but this is almost impossible to avoid since OSX does a lot of disk read/write operations in the background (i.E. Paging files, Spotlight, etc.).

          Best,
          Vlad

          ** Thanks Nerdr :).

  12. Thank you so much. I’m a software engineer and I had a lot of changes on my boot camp partition that I had yet to submit, and the project was due tomorrow. I spent hours reviewing forums , until I stumbled on this site which finally gave me clear step by step instructions to fix it. I can sleep well tonight instead of having to redo all my work.

  13. Worked perfect! Thank you so much! You saved me so much time and frustration!

    I would like other readers who are considering using a program like TechTool Pro 7 who have both windows 7 and osx installed to NOT DO IT!

    I’d used earlier versions and trusted them not to mess up the mac boot record but this one hosed it!

    Jeff.

  14. Are you a man perfect. Thank you very much.

  15. This was great, thank you. Totally worked.

  16. I got OS X and Win8, create another OS X partition and I lost win8 at startup.
    I decide to use your guide and voalá win8 again at startup.

    I appreciate very much your help.

    • Thank you Tonio. Visitors like to think these guides are made from magic, but the truth is someone works hard to make them and put them out for others to see.