Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2116808
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2016-11-05 01:40:14

1.软盘启动的流程
1.1 bochs的配置
  1. megs: 32
  2. romimage: file=$BXSHARE/BIOS-bochs-latest
  3. vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
  4. floppya: 1_44="./arch/i386/boot/bzImage", status=inserted
  5. ata0-master: type=disk, path="/work/os/rootfs/ext2/hdc.img", mode=flat, cylinders=195, heads=16, spt=21
  6. boot: floppy
  7. log: /tmp/bochsout.txt
启动截图:


1.2 软盘启动流程:BIOS-->0x7C00
a. 从软盘启动时加载到0x7C00的是arch/i386/boot/bootsect.S-->自己将自己复制到0x90000
b. 实在不想写了,过程就是前面的部分

2.grub引导的流程
2.1 bochs的配置
  1. megs: 32
  2. romimage: file=$BXSHARE/BIOS-bochs-latest
  3. vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
  4. ata0-master: type=disk, path="./hdc.img", mode=flat, cylinders=130, heads=16, spt=63
  5. boot: disk
  6. log: /tmp/bochsout.txt
启动截图:


2.2 THE LINUX/I386 BOOT PROTOCOL-->linux-2.4.12/Documentation/i386/boot.txt

2.3 grub 0.97启动流程:BIOS-->0x7C00 ()
a.在说明grub启动流程之前先看一下硬盘上有什么
  1. grub> device (hd0) hdc.img

  2. grub> geometry (hd0) 130 16 63
  3. drive 0x80: C/H/S = 130/16/63, The number of sectors = 131040, hdc.img
  4.    Partition num: 0, Filesystem type is ext2fs, partition type 0x83

  5. grub> root (hd0,0)

  6. grub> setup (hd0)
  7.  Checking if "/boot/grub/stage1" exists... yes
  8.  Checking if "/boot/grub/stage2" exists... yes
  9.  Checking if "/boot/grub/e2fs_stage1_5" exists... yes
  10.  Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 17 sectors are embedded.
  11. succeeded
  12.  Running "install /boot/grub/stage1 (hd0) (hd0)1+17 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded
  13. Done.
第1个扇区是stage1                          -->其作用是加载第2个扇区
第2-18共17个扇区是e2fs_stage1_5  -->包括两部分head+stage1_5

b.为什么会把e2fs_stage1_5写到第2个扇区呢?
因为boot所在硬盘的分区是ext3的,有了e2fs_stage1_5的存在grub就有了在文件系统中查找文件的能力
这样就会找到stage2,进入grub的shell中

c. stage1的作用是加载第2个扇区
在第2个扇区的是e2fs_stage1_5的head
e2fs_stage1_5的head会Loading stage1.5

d.  grub是进了保护模式才来加载bzImage的
但不是直接加载到1M开始处的,因为bzImage=bootsect+setup+bvmlinux
是分开加载的,bootsect放在0x90000处, setup放在0x90200处
bvmlinux才是放在0x100000(1M)处的

注意:以上grub的引导启动过程我没有看源码,得出的结论如果出错还请指出。

附录:


附录2.创建grub引导的硬盘镜像脚本
  1. cong@msi:/work/os/rootfs/grub/grub0.97$ tree
  2. .
  3. ├── bochrc -->bochs启动配置
  4. ├── bzImage -->内核
  5. ├── creatext2.sh -->创建文件系统的脚本
  6. ├── grub -->在grub的install时会用到
  7. │   ├── default
  8. │   ├── device.map
  9. │   ├── e2fs_stage1_5
  10. │   ├── fat_stage1_5
  11. │   ├── installed-version
  12. │   ├── jfs_stage1_5
  13. │   ├── menu.lst --->grub的启动配置文件
  14. │   ├── menu.lst_bak
  15. │   ├── minix_stage1_5
  16. │   ├── reiserfs_stage1_5
  17. │   ├── stage1
  18. │   ├── stage2
  19. │   └── xfs_stage1_5
  20. ├── grub-floppy
  21. ├── grub-install
  22. ├── grub-md5-crypt
  23. ├── grub-mkdevicemap
  24. ├── grub-probe
  25. ├── grub-reboot
  26. ├── grub-set-default
  27. ├── grub_sh -->grub的命令行,但与grub目录重名,改名了
  28. ├── grub-terminfo
  29. ├── Makefile -->make qemu 启动qemu
  30. └── Readme.txt

  31. 2. 使用说明
  32. a. 执行creatext2.sh脚本会在当前目录下生成hdc.img
  33. 这个是只ext2文件系统的镜像
  34. cong@msi:/work/os/rootfs/grub/grub0.97$ ./creatext2.sh

  35. b.启动qemu即可看到启动grub的界面
  36. cong@msi:/work/os/rootfs/grub/grub0.97$ make qemu
grub0.rar  (下载后改名为grub0.97img.tar.gz)
阅读(1078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~