<html>
<head>
<title>MBR Fix - Fix MBR problems</title>
</head>
<body>
<P align="center">MbrFix.exe
</P>
<P align="center">Copyright (C) 2004-2009 Systemintegrasjon AS
</P>
<P align="center"><A href="http://www.sysint.no">http://www.sysint.no</A></P>
<h3>Usage:</h3>
<PRE>
MbrFix /drive <num> {/partition <part>} <command> { /yes } { /byte }
</PRE>
<h3>Requirements:</h3>
<P>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.</P>
<P>You need administrative privileges to make it work!</P>
<H3>
Purpose:</H3>
<p>
Perform several Master Boot Record (MBR) tasks, like backing up, restoring, fixing
the boot code in the MBR, etc. The utility should <b>not</b> 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.</p>
<h3>
Commands:</h3>
<PRE> MbrFix /drive <num> driveinfo Display drive information
MbrFix /drive <num> drivesize Returns drive size in MB as return value
MbrFix /drive <num> listpartitions Display partition information
MbrFix /drive <num> savembr <file> Save MBR and partitions to file
MbrFix /drive <num> restorembr <file> Restore MBR and partitions from file
MbrFix /drive <num> fixmbr {/vista|/win7} Update MBR code to W2K/XP/2003, Vista or Win7
MbrFix /drive <num> clean Delete all partitions on the selected disk
MbrFix /drive <num> readsignature {/byte} Read disk signature from MBR
MbrFix /drive <num> writesignature <hex> Write disk signature to MBR
MbrFix /drive <num> generatesignature Generate disk signature in MBR
MbrFix /drive <num> readstate Read state from byte 0x1b2 in MBR
MbrFix /drive <num> writestate <state> Write state to byte 0x1b2 in MBR
MbrFix /drive <num> readdrive <startsector> <sectorcount> <file>
Save sectors from drive to file
MbrFix /drive <num> /partition <part> fixbootsector <os>
Update Boot code in boot sector
MbrFix /drive <num> /partition <part> getpartitiontype
Get partition type
MbrFix /drive <num> /partition <part> setpartitiontype <typenum>
Set partition type
MbrFix /drive <num> /partition <part> setactivepartition
Set active partition
MbrFix /drive <num> 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
</PRE>
<P></P>
<p>
Drive numbering <num> starts on 0.<br />
Partition numbering <part> starts on 1.</p>
<p>
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.</p>
<p>
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.</p>
<p>
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.</p>
<p>
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.<br />
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.</p>
<P>
<H3>Return codes:</H3>
<P>
The program reports an errorlevel as 0 for OK and other values for errors.<br>
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.
</P>
<h3>Why do I need this utility?</h3>
<P>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 <STRONG><EM>!</EM></STRONG>). 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).</P>
<pre>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
</pre>
<P>I then mounted a network drive to my physical computer and copied the boot.ini,
ntldr, ntdetect.com, windows folder, program files folder, etc. from the
Windows Embedded XP image directory. Everything to make it boot.</P>
<P>Well everything should be OK, so I rebooted the (virtual) computer and expected
it to boot up Windows Embedded XP.</P>
<P>But not so! It just sat there with a nice black screen. No error message at all.</P>
<P>Some investigation later on the Internet, I found this very informative page by
Daniel B. Sedory: <A href="http://thestarman.narod.ru/asm/mbr/index.html#MBR">
http://thestarman.narod.ru/asm/mbr/index.html</A>,
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.</P>
<P>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.&