Sunday, December 25, 2011

Fix your booting problems with MbrFix.exe


MbrFix /drive {/partition } { /yes } { /byte }


The program is made for Windows NT, Windows 2000, Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7 and Windows PE. Both 32-bit and 64-bit x64 editions are supported.

You need administrative privileges to make it work!


Perform several Master Boot Record (MBR) tasks, like backing up, restoring, fixing the boot code in the MBR, etc. The utility should not be used for GUID Partition Table (GPT) disks. The utility now, by popular demand, also come in a x64-version running unde x64-editions of Windows and PE.


MbrFix /drive driveinfo Display drive information

MbrFix /drive drivesize Returns drive size in MB as return value

MbrFix /drive listpartitions Display partition information

MbrFix /drive savembr Save MBR and partitions to file

MbrFix /drive restorembr Restore MBR and partitions from file

MbrFix /drive fixmbr {/vista
/win7} Update MBR code to W2K/XP/2003, Vista or Win7

MbrFix /drive clean Delete all partitions on the selected disk

MbrFix /drive readsignature {/byte} Read disk signature from MBR

MbrFix /drive writesignature Write disk signature to MBR

MbrFix /drive generatesignature Generate disk signature in MBR

MbrFix /drive readstate Read state from byte 0x1b2 in MBR

MbrFix /drive writestate Write state to byte 0x1b2 in MBR

MbrFix /drive readdrive

Save sectors from drive to file

MbrFix /drive /partition fixbootsector

Update Boot code in boot sector

MbrFix /drive /partition getpartitiontype

Get partition type

MbrFix /drive /partition setpartitiontype

Set partition type

MbrFix /drive /partition setactivepartition

Set active partition

MbrFix /drive getactivepartition Get active partition

MbrFix volumeinformation driveletter Get volume information for partition

MbrFix flush {driveletter(s)} Flush files to disk for partition

MbrFix listpartitiontypes List partition types

Drive numbering starts on 0.

Partition numbering starts on 1.

Commands restorembr, fixmbr, generatesignature, writestate, clean, setactivepartition and fixbootsector will ask for confirmation unless /yes is included. All these commands may lead to data loss if used incorrectly or without intention.

If the /byte option is given for the readsignature command, the signature is returned as a byte array instead of as a DWORD. Writesignature requires the new signature to be specified as 8 hex digits.

If /vista is used with the fixmbr command, a Windows Vista MBR is written, if /win7 is used, a Windows 7 MBR is written instead of the default Win2000/XP/2003 MBR. The Vista or Win7 MBR should work with the other OS'es.

When fixing boot sector of a chosen partition, the wanted OS version must be specified. For now, the only valid choices are WIN98, DOS5 and DOS6.

The purpose of the fixbootsector command is to insert boot code for loading DOS from a partition created and formatted as FAT using the Windows 2000/XP/2003 tools, since those tools inserts boot code for loading NTLDR.
Return codes:

The program reports an errorlevel as 0 for OK and other values for errors.

The exception to this is the ReadState, GetPartitonType and GetActivePartitions command which returns the state as a return code as well as printing to stdout. Any errors for this command are returned as negative values because of this. The DriveSize command returns the drive size in MB, and 0 in case of error.

Why do I need this utility?

Well, I was testing Windows Embedded XP using a virtual PC, and was booting Windows PE from a CD-ROM to partition a brand new harddisk (quite cheap, since it was virtual !). Using the diskpart.exe utility (found in Windows XP and Windows Server 2003, available as a download for Windows 2000), I created the partition, made it Active, assigned it a drive letter. I then used the format.exe utility to format it to NTFS (format C: /fs:ntfs).

DISKPART> detail part

Partition 1

Type: 07

Hidden: No

Active: Yes

Volume ### Letter Lable Fs Type Size Status Info.

---------- --- ----------- ----- ---------- ------- --------- --------

* Volume 1 C WinXP NTFS Partition 149 MB OK System

I then mounted a network drive to my physical computer and copied the boot.ini, ntldr,, windows folder, program files folder, etc. from the Windows Embedded XP image directory. Everything to make it boot.
Well everything should be OK, so I rebooted the (virtual) computer and expected it to boot up Windows Embedded XP.

But not so! It just sat there with a nice black screen. No error message at all.

Some investigation later on the Internet, I found this very informative page by Daniel B. Sedory:, containing a wealth of MBR info. The info on one of the pages states that the MBR code is installed on the drive when the Windows setup program runs and no MBR code exists already. Hmm.., seemed to be right on the mark.

I searched further on the Internet, but the only utilities I found which could install MBR code was for other operating systems, like FDISK.exe /MBR for DOS (but I wouldn't boot to DOS...) or the fixmbr command in the Windows 2000/XP/2003 Recovery Console. Didn't want that either. Wanted something to work on a Windows 32 bit platform, to be able to fix the problem in other cases when using Win PE and just plain copying in the operating system files. So, then I was left to make the utility myself!
Problem solved: After booting up Windows PE from CD again, the command MBRFix /drive 0 fixmbr /yes solved it all. Embedded XP booted like a charm.
C:\> MbrFix /drive 0 listpartitions
# Boot Size (MB) Type
1 Yes 151001 6 DOS 3.31+ 16-bit FAT (over 32M)
2 1623 12 WIN95 OSR2 32-bit FAT, LBA-mapped
3 0 0 None
4 0 0 None
C:\> MbrFix /drive 0 savembr Backup_MBR_0.bin
C:\> MbrFix /drive 0 restorembr Backup_MBR_0.bin
You are about to Restore MBR,
are you sure (Y/N)? Y
C:\> MbrFix /drive 0 fixmbr /yes
C:\> MbrFix /drive 0 fixmbr /vista /yes
C:\> MbrFix /drive 0 /partition 2 fixbootsector WIN98 /yes
C:\> MbrFix /drive 0 /partition 2 setpartitiontype 14 /yes
C:\> MbrFix flush (flush all drives)
C:\> MbrFix flush cde (flushes C:, D: and E:)
C:\> mbrfix readsignature
C:\> mbrfix writesignature 473d4f07

Readstate and Writestate:

The commands readstate and writestate use a byte at offset 0x1b2 to store state. This was changed from offset 0x1b0 used in earlier versions to be compatible with Windows Vista MBR. These commands are only useful in a scenario where you use Windows PE to roll out other MS operating systems, and you have no other place to store information about where you are in the installation process. This location in the MBR is unused as far as known, from the days of DOS 3.30 until Vista.


No comments:

Post a Comment