Friday, December 21, 2018

Repair Bootcamp partition boot entry missing after disk resize

Written by Pranshu Bajpai | LinkedIn

I recently installed the latest copy of Mac OS X and lost the Bootcamp Windows partition boot entry from the MBR (Master Boot Record). It took a series of steps to get the Bootcamp partition boot entry back into the MBR and so I decided to document the procedure. On an unrelated note, this write up also involved resetting the Windows 7 password since I realized that I forgot the Windows password.

The problem is that when the disk structure is modified, the Bootcamp boot entry is lost from the MBR. However, the partition still exists and the files within the Bootcamp partition are untouched. This can be verified by logging into the alternate OS (Mac OS X) and using Disk Utility to look at the partition structure. The Bootcamp partition should still be there. If it is, the file explorer can be used to verify that the files within the Bootcamp partition all still exist. We can now begin restoration of the Bootcamp boot entry.

Step 1. Obtain gptfdisk

 

Head over to sourceforge and obtain the latest copy of gptfdisk: https://sourceforge.net/projects/gptfdisk/

We will use this tool to derive some disk information. After installing this tool, bring up a Terminal window and execute:
sudo gpt -r -vv show disk0
sudo fdisk /dev/disk0
diskutil list


Locate the Bootcamp partition and notice the partition number assigned to it. In my case, it was 5. You can also verify this in Disk Utility where clicking info about the Bootcamp partition should show something like disk0s5,also note that the bootable flag is likely set to no at this time.



Now that we are equipped with the knowledge of what the disk number is for the Bootcamp partition, we can begin the procedure of restoring the Bootcamp entry in MBR.

Step 2. Restore Bootcamp entry in the MBR

 

Use the gdisk tool as follows to restore the partition entry:

sudo gdisk /dev/disk0
r
h
5
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? y
accept default code of 07
set bootable flag? y
do not protect more partitions? n
o
w
proceed? y
Exit the terminal at this point and restart Mac. Press and hold the ALT key at boot time and the Bootcamp boot entry should now appear in the MBR. We have fixed the problem.



Addendum

 

I forgot the Windows 7 password since I hadn't logged into for a while (I don't really use this Windows partition for another but to play some games and I couldn't even do that with the Bootcamp boot entry missing). So now I had to find a way to reset Windows 7 password. Turns out the old renaming sethc, copying command prompt executable and renaming it sethc.exe trick still works! Here's how it goes.

Step 1. Restart Windows and hard reset (long press the power button) as the Windows icon appears on the screen. Windows should now start in repair mode.





Step 2. Take advantage of the repair mode and wait for it to attempt the repair (this takes several minutes). Once done, click view report details and click on the link down below that ends in a .txt. This will open the report in text editor.





Step 3. Use the open feature of text editor to navigate to Windows/system32 directory and rename sethc to something random. Now make a copy of cmd.exe and rename this copy to sethc.





We have now renamed a copy of command prompt and associated it with the sticky keys functionality.

Step 4. We boot into Windows again and arrive at the login screen. At this point, we press sticky keys 5 times to active the sticky keys functionality, which will now fire up the command prompt.

Step 5. We now take advantage of the command prompt to execute the following commands to reset the password
net user
net user <USERNAME> *



We have now successfully changed the password and can now use this password to login.

1 comment:

  1. hi,
    after all of this steps i receive an error message:
    "unable to open disk0 to write"
    can you help me

    ReplyDelete