Thursday, July 5, 2012

Repairing the MBR in Vista/7

I have found that more and more often, I have to perform a repair on the MBR when removing some of the new bootkits from x64 platforms. It is a pretty straight-forward process, which Microsoft has documented well. I feel that putting it all in one place will help people out, so here it is:

The first step towards repairing the MBR is to get into the "Advanced Boot Options" screen by repeatedly pressing the "f8" key on the keyboard just after powering the system on. That will take you here:


Select "Repair Your Computer", wait for everything to load, select your keyboard layout and login. Once you login, you will see this screen:


You want to select "Command Prompt". Now that you have command prompt open, you can start fixing the MBR. Please follow the commands below in order:

bootrec /fixboot
bootrec /fixmbr
bootrec /rebuildbcd

If all worked correctly, your screen will look like this:


If you run into an error with "bootrec /fixboot" or "bootrec /rebuildbcd" that states "element not found", it means that the OS partition is not set as active and you need to do that before running the fixes. For this example, I will be using diskpart to fix this error and set the correct partition to the active state. Here is a list of the commands and a short breakdown of what they do:

diskpart - launches the diskpart utility
list disk - lists the hard disks that are available, you need the OS disk (usually the c:\ drive)
select disk x - once you find the disk you want to select, replace x with the correct disk number
list partition - lists the partitions that are available, you need the OS partition (usually the biggest one)
select partition x - once you find the OS partition, replace x with the correct partition number
active - sets the currently selected partition to active
exit - exit diskpart back to recovery console


Once you have the correct partition set as active, you can retry the bootrec commands and they should succeed this time. That is all there is to it!

No comments:

Post a Comment