2024年6月14日发(作者:)

GRUB2及启动过程详解

作者: 南瓜剪子

2016年7月28日

1. 概述 ............................................................................................................................................ 2

2. CentOS7中GRUB2 ..................................................................................................................... 3

3。 GRUB2 的 bootstrap image文件 ............................................................................................ 5

3.1。 boot。img ...................................................................................................................... 5

3。2。 diskboot。img ............................................................................................................ 5

3.3. kernel。img ....................................................................................................................... 6

3.4。 core。img ...................................................................................................................... 6

3。5. *.mod .............................................................................................................................. 6

4. 对比GRUB Legacy ...................................................................................................................... 7

4.1. stage1 ................................................................................................................................ 7

4。2. *_stage1_5 ...................................................................................................................... 7

4.3。 stage2 ............................................................................................................................. 7

5。 grub2-mkimage定制 ................................................................................................. 8

6。 GRUB2安装 ............................................................................................................................ 10

6。1. Linux是怎么命名设备(/dev/sda) ............................................................................. 10

6.2. MBR(Master Boot Record) ......................................................................................... 11

6。3。 MBR分区表DPT(Disk Partition Table) ............................................................... 14

6.4。 LBA and CHS ................................................................................................................. 22

6.4。1. CHS(cylinders—heads—sectors) ..................................................................... 22

6.4。2。 LBA(Logical Block Address) .......................................................................... 23

6。5。 boot。img和安装 .................................................................................... 23

6.6。 硬盘总结 ..................................................................................................................... 28

7. 启动过程................................................................................................................................... 29

7。1. BIOS .............................................................................................................................. 29

7.2。 GRUB2中 ..................................................................................................... 31

7.2。1。 Step1无条件跳转 ......................................................................................... 32

7。2。2. Step2 初始化 ................................................................................................. 32

7。2.3. Step3 判断硬盘是否支持LBA还是只支持CHS ............................................. 34

7。2.4。 Step4 采用LBA加载第一个扇区 ................................................ 37

7。2.5. Step5 拷贝第一个扇区到内存指定位置 ......................................... 40

7。2。6。 Step6 执行core。img第一条语句........................................................... 42

7。2。7。 Step7 boot。img总结 ................................................................................ 43

7。3。 GRUB2中core。img ................................................................................................ 44

7.3.1。 ...................................................................................................... 44

7。3。2。 GRUB2 core Startup .................................................................................... 54

7.3。3。 GRUB主函数即GRUB主要功能 .................................................................. 59

7。3。4。 加载Linux Kernel ........................................................................................ 60

7。4。 Linux kernel ............................................................................................................... 74

8。 结束语..................................................................................................................................... 75

9。 参考文献................................................................................................................................. 75

1. 概述

计算机系统上电之后由固化到ROM中的BIOS(UEFI)进行操作,然后导入硬盘MBR