Hard Disk Master Boot Record (MBR) and Its Structure

Source: Internet
Author: User

 

The hard disk has 0 cylinders, 0 heads, and 1-sector names as the primary boot sector. The content written by the fdisk program to this sector is called the primary Boot Record (MBR ). This record occupies 512 bytes. It is used to give the system control to the user specified when the hard disk is started and to register an operating system zone in the partition table.

 

1. Read MBR

The hard disk Boot Record (MBR) does not belong to any operating system, nor can it be read using the disk operation commands provided by the operating system. But we can use the int13h 2 function provided in the ROM-BIOS to read the content of this sector, it can also be read by the software tool norton8.0 diskedit. EXE.

The call parameters for the int13h read disk sector function are as follows:

Entry parameter: Ah = 2 (function number specified)

Al = number of sectors to read

DL = disk number (0, 1-floppy disk; 80, 81-hard disk)

DH = head number

CL height 2-bit + CH = cylindrical number

CL 6-bit lower = fan ID

CS: BX = memory buffer address for storing read data

Export parameter: CS: BX = read data storage address

Error message: cf = 1 Ah = Error Code

You can use DEBUG to read data from the zero-cylinder, zero-head, and one-sector disks on the hard disk as follows:

A> debug

-A 100

XXXX: XXXX mov ax, 0201 (read 1 sector with function number 2)

XXXX: XXXX mov BX, 1000 (put read data into the buffer address Cs: 1000)

XXXX: XXXX mov CX, 0001 (read 0 cylindrical, 1 sector)

XXXX: XXXX mov dx, 0080 (specify the 0 head of the first physical disk)

XXXX: xxxx int 13

XXXX: xxxx int 3

XXXX: xxxx (Press ENTER)

-G = 100 (execute the above program segment)

-D 1000 11ff (display 512 bytes of MBR content)

 

2. MBR Composition

The Master Boot Record MBR of a single sector hard disk consists of four parts.

The primary Bootstrap program (offset h--0088h) is responsible for loading from the active partition and running the System Bootstrap program.

Error information data area. The offset address 0089h--00e1h indicates the error message, and 00e2h--01bdh indicates 0 bytes.

The partition table (DPT, disk partition table) contains four partition items, with an offset of 01beh--01fdh. Each partition table item is 16 bytes long, A total of 64 bytes are partition item 1, partition item 2, partition item 3, and partition item 4.

The end flag. The two byte values of the Offset 01fe--01ff are the end flag 55aa. If this flag is incorrect, the system cannot start it.

0000-0088

 

Master Boot Record

Main Bootstrap program

Master Guide

Program

0089-01bd

Error information data Zone

Data Zone

01be-01cd

Partition item 1 (16 bytes)

 

Partition Table

 

01ce-01dd

Partition Item 2 (16 bytes)

01de-01ed

Partition Item 3 (16 bytes)

01ee-01fd

Partition Item 4 (16 bytes)

01fe

55

End mark

01ff

AA

 

3. Partition Information Structure in MBR

In an MBR that occupies 512 bytes, the 64-byte offset of 01beh--01fdh is the content of 4 partition items (partition info table ). It is determined by the disk media type and when you use fdisk to define partitions. In practice, fdisk can divide a disk into less than four primary partitions, but not more than four. The project of each partition table is 16 bytes. Its content is described in the following table.

Storage byte

Content and meaning

1st bytes

Guide flag. If the value is 80 h, it indicates the active partition. If the value is H, it indicates the non-active partition.

2nd, 3, 4 bytes

The START head, Fan area, and Cylinder Number of the current partition. Where:

Head number-2nd bytes;

Fan area number-6-bit lower than 3rd bytes;

The cylinder number, which is 3rd bytes in height, 2 bits, and 8 bits in 4th bytes.

5th bytes

Partition type.

00 h -- indicates that the partition is not used (that is, it is not specified );

06h--fat16 basic partition;

0bh--fat32 basic partition;

05 h -- extended partition;

07h--ntfs partition;

0fh -- (LBA mode) extended partition (83h is LINUX partition, etc ).

6th, 7, 8 bytes

End head, Fan area, and Cylinder Number of the current partition. Where:

Head number-6th bytes;

Fan area number-6-bit lower than 7th bytes;

Cylinder Number-2-plus 7th bytes in height.

9th, 10, 11, 12 bytes

Number of slice used in the current partition.

13th, 14, 15, 16 bytes

The total number of sectors in the current partition.

 

4. Main Features and workflow of MBR

After the CPU is powered on, if it is started by the hard disk, the BIOS will read the Master Boot Record of the hard disk (in the 0 cylinder, 0 track, 1 Sector) into the 7c00 position, then, the control is handed over to the Master Guide code. Tasks of the main Bootstrap Code include:

Scan the partition table and find an active (bootable) partition;

Locate the start sector of the active partition;

Load the Boot Sector of the active partition to the memory at 7c00;

Give control to the Boot Sector Code;

 

If the Master Boot Code cannot complete the preceding task, it displays one of the following error messages:

No active partition.

Invalid partition table.

Error loading operating system.

Missing operating system.

 

After the machine is powered on or press the reset key, the system must be reset. After the reset, cs = ffffh, IP = 0000 h. Then, naturally, the command is executed from FFFF: 0000h, there is only one JMP command in this place to jump to the system self-check program. After the system self-check is completed, the first sector of the floppy disk (if started by a floppy disk) or the first sector of the hard disk, that is, the MBR sector (if started by the hard disk) is read to 0: 7c00h, and then the control is handed over and continues from 0: 7c00h.

 

The following is the MBR code analysis of the hard disk:

The Boot Sector refers to the first sector in the corresponding partition of the hard disk, which is related to the operating system. The operating system is guided by the operating system, while the MBR is not responsible, and the MBR is irrelevant to the operating system. The task of guiding a sector is to forward control to the operating system's Bootstrap program.

 

Procedure:

1. Move the program code from 0: 7c00h to 0: 0600 H (Note: BIOS places MBR at 0: 7c00h)

2. Search for bootable partitions, that is, the 80 h flag.

Success: goto 3

Failed: Jump to Rom basic

Invalid Partition Table: goto 5

3. Read Boot Sector

Failed: goto 5

Success: goto 4

4. Verify that the final Boot Sector is 55aah

Failed: goto 5

Success: goto 6

5 print errors into infinite Loops

6. Jump to 0: 7c00h to start the next step.

 

5. Partition Table chain structure of the hard drive logical drive

A hard disk consists of multiple 512-byte sectors, which are organized into "partitions ".

The partitioning rule for a hard disk is that all the sectors in a partition must be continuous, and the hard disk can have up to four physical partitions, these four physical partitions can be a primary partition or three primary partitions plus an extended partition. In extended partitions under DOS/Windows Management, logical partitions (logical disks) can and must be further divided ).

The extended partition information is located in the hard disk partition table (DPT), while the logic drive information is located in the starting sector of the extended partition, that is, the starting address (area/sector/track) of the partition) the corresponding sector. The difference between the information in this sector and the primary Boot Sector of the hard disk does not include MBR, while the 16-byte partition information indicates the start and end addresses of the logical drive.

The MBR (Master Boot Record) Master Boot Record contains two parts. The first 446 bytes are the startup code and data, and the first 446 (0x1be) is the partition table, A partition table consists of four partition items. Each partition item has 16 bytes of data and records the partition parameters required for startup.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.