Linux Kernel 2.6.37 启动过程笔记 :MBR

http://blog.chinaunix.net/uid-1701789-id-125510.html

PC加电的过程就是将cs:ip指向 0xFFFF0,这里是BIOS的内容。BIOS接下来就接管系统启动,负责检查并初始化硬件设备,初始化实模式下中断向量表。然后i386系统就会将硬盘的第一个扇区(0扇区)加载到内存 0x7c00处---这就是MBR。
最简单的MBR的结构如下:
tructure of a master boot record
Address Description Size in bytes
Hex Oct Dec
0000 0000 0 code area 440
(max. 446)
01B8 0670 440 disk signature (optional) 4
01BC 0674 444 Usually nulls; 0x0000 2
01BE 0676 446 Table of primary partitions
(Four 16-byte entries, IBM partition table scheme)
64
01FE 0776 510 55h MBR signature;
0xAA55
2
01FF 0777 511 AAh
MBR, total size: 446 + 64 + 2 = 512

Layout of one 16-byte partition record
Offset Field
length
(bytes)
Description
0x00 1 status (0x80 = bootable (active), 0x00 = non-bootable, other = invalid ) [a]
0x01 3 CHS address of first absolute sector in partition. [b] The format is described by 3 bytes, see the next 3 rows.
0x01 1
h7-0 head [c]
x x x x x x x x
0x02 1
c9-8 s5–0 sector is in bits 5–0; bits 9–8 of cylinder are in bits 7–6 [c]
x x x x x x x x
0x03 1
c7-0 bits 7–0 of cylinder [d]
x x x x x x x x
0x04 1 partition type[5][6]
0x05 3 CHS address of last absolute sector in partition. [b] The format is described by 3 bytes, see the next 3 rows.
0x05 1
h7-0 head [c]
x x x x x x x x
0x06 1
c9-8 s5–0 sector is in bits 5–0, bits 9–8 of cylinder are in bits 7–6 [c]
x x x x x x x x
0x07 1
c7-0 bits 7–0 of cylinder [d]
x x x x x x x x
0x08 4 LBA of first absolute sector in the partition [e]
0x0C 4 Number of sectors in partition, in little-endian format [e]
Notes:

^ a Formally, status values other than 0x00 and 0x80 are undefined.

^ b Starting Sector fields are limited to 1024 cylinders, 255 heads, and 63 sectors;[citation needed] Ending Sector fields have the same limitations.

^ c The range for sector is 1 through 63; the range for cylinder is 0 through 1023; the range for head is 0 through 254 inclusive.[citation needed]

^ d The 10-bit cylinder value is split into two bytes. The value can be reassembled using this formula: cylinder = ((byte[2] & 0xc0) << 2) | byte[3]

^ e Used by OSes only in certain circumstances; in such cases the CHS addresses are ignored.[7]

从上图中可以知道MBR已经知道硬盘的分区结构(最多四个主分区--16X4),并且知道哪个分区是活动分区。MBR找到活动分区并且把该活动分区的第一个扇区内容加载到 0x7c00的地方将自己覆盖掉,并将控制权交给0x7c00处的OS启动代码。在Linux里,这就是arch/boot/header.S

MBR实际就是Boot Loader,以上就是最简单的BootLoader的例子 ,现在的Bootloader一般都比这个复杂。一般来说一个BootLoader会占据不止一个扇区以支持多重启动。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值