
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.thelinuxwiki.com/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=MBR_how_it_works</id>
		<title>MBR how it works - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=MBR_how_it_works"/>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=MBR_how_it_works&amp;action=history"/>
		<updated>2026-04-29T00:24:31Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.21.5</generator>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=MBR_how_it_works&amp;diff=185&amp;oldid=prev</id>
		<title>Nighthawk: Pushed from Themanclub.</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=MBR_how_it_works&amp;diff=185&amp;oldid=prev"/>
				<updated>2013-04-12T15:54:06Z</updated>
		
		<summary type="html">&lt;p&gt;Pushed from Themanclub.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;               How It Works -- Master Boot Record&lt;br /&gt;
&lt;br /&gt;
                           Version 1a&lt;br /&gt;
&lt;br /&gt;
             by Hale Landis (landis@sugs.tware.com)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
THE &amp;quot;HOW IT WORKS&amp;quot; SERIES&lt;br /&gt;
&lt;br /&gt;
This is one of several How It Works documents.  The series&lt;br /&gt;
currently includes the following:&lt;br /&gt;
&lt;br /&gt;
* How It Works -- CHS Translation&lt;br /&gt;
* How It Works -- Master Boot Record&lt;br /&gt;
* How It Works -- DOS Floppy Boot Sector&lt;br /&gt;
* How It Works -- OS2 Boot Sector&lt;br /&gt;
* How It Works -- Partition Tables&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
MASTER BOOT RECORD&lt;br /&gt;
&lt;br /&gt;
This article is a disassembly of a Master Boot Record (MBR).  The&lt;br /&gt;
MBR is the sector at cylinder 0, head 0, sector 1 of a hard disk.&lt;br /&gt;
An MBR is created by the FDISK program.  The FDISK program of all&lt;br /&gt;
operating systems must create a functionally similar MBR. The MBR&lt;br /&gt;
is first of what could be many partition sectors, each one&lt;br /&gt;
containing a four entry partition table.&lt;br /&gt;
&lt;br /&gt;
At the completion of your system's Power On Self Test (POST), INT&lt;br /&gt;
19 is called.  Usually INT 19 tries to read a boot sector from&lt;br /&gt;
the first floppy drive.  If a boot sector is found on the floppy&lt;br /&gt;
disk, the that boot sector is read into memory at location&lt;br /&gt;
0000:7C00 and INT 19 jumps to memory location 0000:7C00.&lt;br /&gt;
However, if no boot sector is found on the first floppy drive,&lt;br /&gt;
INT 19 tries to read the MBR from the first hard drive.  If an&lt;br /&gt;
MBR is found it is read into memory at location 0000:7c00 and INT&lt;br /&gt;
19 jumps to memory location 0000:7c00.  The small program in the&lt;br /&gt;
MBR will attempt to locate an active (bootable) partition in its&lt;br /&gt;
partition table.  If such a partition is found, the boot sector&lt;br /&gt;
of that partition is read into memory at location 0000:7C00 and&lt;br /&gt;
the MBR program jumps to memory location 0000:7C00.  Each&lt;br /&gt;
operating system has its own boot sector format.  The small&lt;br /&gt;
program in the boot sector must locate the first part of the&lt;br /&gt;
operating system's kernel loader program (or perhaps the kernel&lt;br /&gt;
itself or perhaps a &amp;quot;boot manager program&amp;quot;) and read that into&lt;br /&gt;
memory.&lt;br /&gt;
&lt;br /&gt;
INT 19 is also called when the CTRL-ALT-DEL keys are used.  On&lt;br /&gt;
most systems, CTRL-ALT-DEL causes an short version of the POST to&lt;br /&gt;
be executed before INT 19 is called.&lt;br /&gt;
&lt;br /&gt;
=====&lt;br /&gt;
&lt;br /&gt;
Where stuff is:&lt;br /&gt;
&lt;br /&gt;
   The MBR program code starts at offset 0000.&lt;br /&gt;
   The MBR messages start at offset 008b.&lt;br /&gt;
   The partition table starts at offset 00be.&lt;br /&gt;
   The signature is at offset 00fe.&lt;br /&gt;
&lt;br /&gt;
Here is a summary of what this thing does:&lt;br /&gt;
&lt;br /&gt;
   If an active partition is found, that partition's boot record&lt;br /&gt;
   is read into 0000:7c00 and the MBR code jumps to 0000:7c00&lt;br /&gt;
   with SI pointing to the partition table entry that describes&lt;br /&gt;
   the partition being booted.  The boot record program uses this&lt;br /&gt;
   data to determine the drive being booted from and the location&lt;br /&gt;
   of the partition on the disk.&lt;br /&gt;
&lt;br /&gt;
   If no active partition table enty is found, ROM BASIC is&lt;br /&gt;
   entered via INT 18.  All other errors cause a system hang, see&lt;br /&gt;
   label HANG.&lt;br /&gt;
&lt;br /&gt;
NOTES (VERY IMPORTANT):&lt;br /&gt;
&lt;br /&gt;
   1) The first byte of an active partition table entry is 80.&lt;br /&gt;
   This byte is loaded into the DL register before INT 13 is&lt;br /&gt;
   called to read the boot sector.  When INT 13 is called, DL is&lt;br /&gt;
   the BIOS device number.  Because of this, the boot sector read&lt;br /&gt;
   by this MBR program can only be read from BIOS device number&lt;br /&gt;
   80 (the first hard disk).  This is one of the reasons why it&lt;br /&gt;
   is usually not possible to boot from any other hard disk.&lt;br /&gt;
&lt;br /&gt;
   2) The MBR program uses the CHS based INT 13H AH=02H call to&lt;br /&gt;
   read the boot sector of the active partition.  The location of&lt;br /&gt;
   the active partition's boot sector is in the partition table&lt;br /&gt;
   entry in CHS format.  If the drive is &amp;gt;528MB, this CHS must be&lt;br /&gt;
   a translated CHS (or L-CHS, see my BIOS TYPES document).&lt;br /&gt;
   No addresses in LBA form are used (another reason why LBA&lt;br /&gt;
   doesn't solve the &amp;gt;528MB problem).&lt;br /&gt;
&lt;br /&gt;
=====&lt;br /&gt;
&lt;br /&gt;
Here is the entire MBR record (hex dump and ascii).&lt;br /&gt;
&lt;br /&gt;
OFFSET 0 1 2 3  4 5 6 7  8 9 A B  C D E F  *0123456789ABCDEF*&lt;br /&gt;
000000 fa33c08e d0bc007c 8bf45007 501ffbfc *.3.....|..P.P...*&lt;br /&gt;
000010 bf0006b9 0001f2a5 ea1d0600 00bebe07 *................*&lt;br /&gt;
000020 b304803c 80740e80 3c00751c 83c610fe *...&amp;lt;.t..&amp;lt;.u.....*&lt;br /&gt;
000030 cb75efcd 188b148b 4c028bee 83c610fe *.u......L.......*&lt;br /&gt;
000040 cb741a80 3c0074f4 be8b06ac 3c00740b *.t..&amp;lt;.t.....&amp;lt;.t.*&lt;br /&gt;
000050 56bb0700 b40ecd10 5eebf0eb febf0500 *V.......^.......*&lt;br /&gt;
000060 bb007cb8 010257cd 135f730c 33c0cd13 *..|...W.._s.3...*&lt;br /&gt;
000070 4f75edbe a306ebd3 bec206bf fe7d813d *Ou...........}.=*&lt;br /&gt;
000080 55aa75c7 8bf5ea00 7c000049 6e76616c *U.u.....|..Inval*&lt;br /&gt;
000090 69642070 61727469 74696f6e 20746162 *id partition tab*&lt;br /&gt;
0000a0 6c650045 72726f72 206c6f61 64696e67 *le.Error loading*&lt;br /&gt;
0000b0 206f7065 72617469 6e672073 79737465 * operating syste*&lt;br /&gt;
0000c0 6d004d69 7373696e 67206f70 65726174 *m.Missing operat*&lt;br /&gt;
0000d0 696e6720 73797374 656d0000 00000000 *ing system......*&lt;br /&gt;
0000e0 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000f0 TO 0001af SAME AS ABOVE&lt;br /&gt;
0001b0 00000000 00000000 00000000 00008001 *................*&lt;br /&gt;
0001c0 0100060d fef83e00 00000678 0d000000 *......&amp;gt;....x....*&lt;br /&gt;
0001d0 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0001e0 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0001f0 00000000 00000000 00000000 000055aa *..............U.*&lt;br /&gt;
&lt;br /&gt;
=====&lt;br /&gt;
&lt;br /&gt;
Here is the disassembly of the MBR...&lt;br /&gt;
&lt;br /&gt;
This sector is initially loaded into memory at 0000:7c00 but&lt;br /&gt;
it immediately relocates itself to 0000:0600.&lt;br /&gt;
&lt;br /&gt;
                 BEGIN:                      NOW AT 0000:7C00, RELOCATE&lt;br /&gt;
&lt;br /&gt;
0000:7C00 FA            CLI                     disable int's&lt;br /&gt;
0000:7C01 33C0          XOR     AX,AX           set stack seg to 0000&lt;br /&gt;
0000:7C03 8ED0          MOV     SS,AX&lt;br /&gt;
0000:7C05 BC007C        MOV     SP,7C00         set stack ptr to 7c00&lt;br /&gt;
0000:7C08 8BF4          MOV     SI,SP           SI now 7c00&lt;br /&gt;
0000:7C0A 50            PUSH    AX&lt;br /&gt;
0000:7C0B 07            POP     ES              ES now 0000:7c00&lt;br /&gt;
0000:7C0C 50            PUSH    AX&lt;br /&gt;
0000:7C0D 1F            POP     DS              DS now 0000:7c00&lt;br /&gt;
0000:7C0E FB            STI                     allow int's&lt;br /&gt;
0000:7C0F FC            CLD                     clear direction&lt;br /&gt;
0000:7C10 BF0006        MOV     DI,0600         DI now 0600&lt;br /&gt;
0000:7C13 B90001        MOV     CX,0100         move 256 words (512 bytes)&lt;br /&gt;
0000:7C16 F2            REPNZ                   move MBR from 0000:7c00&lt;br /&gt;
0000:7C17 A5            MOVSW                      to 0000:0600&lt;br /&gt;
0000:7C18 EA1D060000    JMP     0000:061D       jmp to NEW_LOCATION&lt;br /&gt;
&lt;br /&gt;
        NEW_LOCATION:                        NOW AT 0000:0600&lt;br /&gt;
&lt;br /&gt;
0000:061D BEBE07      MOV     SI,07BE           point to first table entry&lt;br /&gt;
0000:0620 B304        MOV     BL,04             there are 4 table entries&lt;br /&gt;
&lt;br /&gt;
        SEARCH_LOOP1:                        SEARCH FOR AN ACTIVE ENTRY&lt;br /&gt;
&lt;br /&gt;
0000:0622 803C80      CMP     BYTE PTR [SI],80  is this the active entry?&lt;br /&gt;
0000:0625 740E        JZ      FOUND_ACTIVE      yes&lt;br /&gt;
0000:0627 803C00      CMP     BYTE PTR [SI],00  is this an inactive entry?&lt;br /&gt;
0000:062A 751C        JNZ     NOT_ACTIVE        no&lt;br /&gt;
0000:062C 83C610      ADD     SI,+10            incr table ptr by 16&lt;br /&gt;
0000:062F FECB        DEC     BL                decr count&lt;br /&gt;
0000:0631 75EF        JNZ     SEARCH_LOOP1      jmp if not end of table&lt;br /&gt;
0000:0633 CD18        INT     18                GO TO ROM BASIC&lt;br /&gt;
&lt;br /&gt;
        FOUND_ACTIVE:                        FOUND THE ACTIVE ENTRY&lt;br /&gt;
&lt;br /&gt;
0000:0635 8B14        MOV     DX,[SI]           set DH/DL for INT 13 call&lt;br /&gt;
0000:0637 8B4C02      MOV     CX,[SI+02]        set CH/CL for INT 13 call&lt;br /&gt;
0000:063A 8BEE        MOV     BP,SI             save table ptr&lt;br /&gt;
&lt;br /&gt;
        SEARCH_LOOP2:                        MAKE SURE ONLY ONE ACTIVE ENTRY&lt;br /&gt;
&lt;br /&gt;
0000:063C 83C610      ADD     SI,+10            incr table ptr by 16&lt;br /&gt;
0000:063F FECB        DEC     BL                decr count&lt;br /&gt;
0000:0641 741A        JZ      READ_BOOT         jmp if end of table&lt;br /&gt;
0000:0643 803C00      CMP     BYTE PTR [SI],00  is this an inactive entry?&lt;br /&gt;
0000:0646 74F4        JZ      SEARCH_LOOP2      yes&lt;br /&gt;
&lt;br /&gt;
          NOT_ACTIVE:                        MORE THAN ONE ACTIVE ENTRY FOUND&lt;br /&gt;
&lt;br /&gt;
0000:0648 BE8B06      MOV     SI,068B           display &amp;quot;Invld prttn tbl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
         DISPLAY_MSG:                        DISPLAY MESSAGE LOOP&lt;br /&gt;
&lt;br /&gt;
0000:064B AC          LODSB                     get char of message&lt;br /&gt;
0000:064C 3C00        CMP     AL,00             end of message&lt;br /&gt;
0000:064E 740B        JZ      HANG              yes&lt;br /&gt;
0000:0650 56          PUSH    SI                save SI&lt;br /&gt;
0000:0651 BB0700      MOV     BX,0007           screen attributes&lt;br /&gt;
0000:0654 B40E        MOV     AH,0E             output 1 char of message&lt;br /&gt;
0000:0656 CD10        INT     10                   to the display&lt;br /&gt;
0000:0658 5E          POP     SI                restore SI&lt;br /&gt;
0000:0659 EBF0        JMP     DISPLAY_MSG       do it again&lt;br /&gt;
&lt;br /&gt;
                HANG:                        HANG THE SYSTEM LOOP&lt;br /&gt;
&lt;br /&gt;
0000:065B EBFE        JMP     HANG              sit and stay!&lt;br /&gt;
&lt;br /&gt;
           READ_BOOT:                        READ ACTIVE PARITION BOOT RECORD&lt;br /&gt;
&lt;br /&gt;
0000:065D BF0500      MOV     DI,0005           INT 13 retry count&lt;br /&gt;
&lt;br /&gt;
           INT13RTRY:                        INT 13 RETRY LOOP&lt;br /&gt;
&lt;br /&gt;
0000:0660 BB007C      MOV     BX,7C00&lt;br /&gt;
0000:0663 B80102      MOV     AX,0201           read 1 sector&lt;br /&gt;
0000:0666 57          PUSH    DI                save DI&lt;br /&gt;
0000:0667 CD13        INT     13                read sector into 0000:7c00&lt;br /&gt;
0000:0669 5F          POP     DI                restore DI&lt;br /&gt;
0000:066A 730C        JNB     INT13OK           jmp if no INT 13&lt;br /&gt;
0000:066C 33C0        XOR     AX,AX             call INT 13 and&lt;br /&gt;
0000:066E CD13        INT     13                   do disk reset&lt;br /&gt;
0000:0670 4F          DEC     DI                decr DI&lt;br /&gt;
0000:0671 75ED        JNZ     INT13RTRY         if not zero, try again&lt;br /&gt;
0000:0673 BEA306      MOV     SI,06A3           display &amp;quot;Errr ldng systm&amp;quot;&lt;br /&gt;
0000:0676 EBD3        JMP     DISPLAY_MSG       jmp to display loop&lt;br /&gt;
&lt;br /&gt;
             INT13OK:                        INT 13 ERROR&lt;br /&gt;
&lt;br /&gt;
0000:0678 BEC206      MOV     SI,06C2              &amp;quot;missing op sys&amp;quot;&lt;br /&gt;
0000:067B BFFE7D      MOV     DI,7DFE              point to signature&lt;br /&gt;
0000:067E 813D55AA    CMP     WORD PTR [DI],AA55   is signature correct?&lt;br /&gt;
0000:0682 75C7        JNZ     DISPLAY_MSG          no&lt;br /&gt;
0000:0684 8BF5        MOV     SI,BP                set SI&lt;br /&gt;
0000:0686 EA007C0000  JMP     0000:7C00            JUMP TO THE BOOT SECTOR&lt;br /&gt;
                                                      WITH SI POINTING TO&lt;br /&gt;
                                                      PART TABLE ENTRY&lt;br /&gt;
&lt;br /&gt;
Messages here.&lt;br /&gt;
&lt;br /&gt;
0000:0680 ........ ........ ......49 6e76616c *           Inval*&lt;br /&gt;
0000:0690 69642070 61727469 74696f6e 20746162 *id partition tab*&lt;br /&gt;
0000:06a0 6c650045 72726f72 206c6f61 64696e67 *le.Error loading*&lt;br /&gt;
0000:06b0 206f7065 72617469 6e672073 79737465 * operating syste*&lt;br /&gt;
0000:06c0 6d004d69 7373696e 67206f70 65726174 *m.Missing operat*&lt;br /&gt;
0000:06d0 696e6720 73797374 656d00.. ........ *ing system.     *&lt;br /&gt;
&lt;br /&gt;
Data not used.&lt;br /&gt;
&lt;br /&gt;
0000:06d0 ........ ........ ......00 00000000 *           .....*&lt;br /&gt;
0000:06e0 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:06f0 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0700 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0710 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0720 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0730 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0740 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0750 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0760 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0770 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0780 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:0790 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:07a0 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:07b0 00000000 00000000 00000000 0000.... *............    *&lt;br /&gt;
&lt;br /&gt;
The partition table starts at 0000:07be.  Each partition table&lt;br /&gt;
entry is 16 bytes.  This table defines a single primary partition&lt;br /&gt;
which is also an active (bootable) partition.&lt;br /&gt;
&lt;br /&gt;
0000:07b0 ........ ........ ........ ....8001 *            ....*&lt;br /&gt;
0000:07c0 0100060d fef83e00 00000678 0d000000 *......&amp;gt;....x....*&lt;br /&gt;
0000:07d0 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:07e0 00000000 00000000 00000000 00000000 *................*&lt;br /&gt;
0000:07f0 00000000 00000000 00000000 0000.... *............    *&lt;br /&gt;
&lt;br /&gt;
The last two bytes contain a 55AAH signature.&lt;br /&gt;
&lt;br /&gt;
0000:07f0 ........ ........ ........ ....55aa *..............U.*&lt;br /&gt;
&lt;br /&gt;
/end/&lt;br /&gt;
-- &lt;br /&gt;
\\===============\\=======================\\&lt;br /&gt;
 \\  Hale Landis  \\      303-548-0567     \\&lt;br /&gt;
 // Niwot, CO USA // landis@sugs.tware.com //&lt;br /&gt;
//===============//=======================//&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[category:mbr]]&lt;/div&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	</feed>