我遇到的问题,把boot loader装在/dev/sda1里面,MBR没有grub,机器启动不了
grub是linux比较常用的bootloader,它可以用来引导多种文件系统,可以引导linux也可以引导windows系统内核,若你的系统中没有安装grub,则需要手动安装grub到硬盘中。
安装grub分为两步,grub主要配置文件的拷贝,及主要引导程序stage1安装到bootloader
sector,grub是从MBR读取的,但MBR的大小只有446bits,所以不可能把grub所有的程序都安装在内,其中只有其最重要的引导程序我
们称之为stage1,那些配置信息都在/boot/grub/下,所以安装也需要分两步:
第一步:拷贝主要的配置文件到/boot/grub/下
#grub-install--root-directory=/dev/hda1 #红色标记处可以不写,默认会讲所有配置文件·都拷贝到/boot/grub/下。
第二步:安装grubstage1到MBR或boot sector下,需要使用grub shell来进行安装
主要步骤为:
- 用『 root (hdx,x) 』选择含有 grub 目录的那个 partition 代号;
- 用『 find /boot/grub/stage1 』看看能否找到安装信息文件;
- 用『 find /boot/vmlinuz 』看看能否找到 kernel file (不一定要成功!);
- 用『 setup (hdx,x) 』或『 setup (hdx) 』将 grub 安装在 boot sector 或 MBR;
- 用『 quit 』来离开 grub shell !
这里我用光盘启动,进入修复模式,然后进入shell,执行这些操作。
[root@www ~]#grub
# 1. 先设定一下含有 grub 目录的那个 partition 啊! grub>root (hd0,0) Filesystem type is ext2fs, partition type 0x83 # 鸟哥主机的分割中,/boot/grub 在 /boot 的分割槽,亦即是 /dev/hda1 内喔! # 另外, grub 也能够分辨出该分割槽的文件系统 (ext2)。
# 2. 搜寻一下,是否存在 stage1 这个信息文件? grub>find /boot/grub/stage1 (hd0,2) # 见鬼!怎么会只有一个!我们明明有 /boot/grub 与 /home/boot/grub 啊! # 因为 /boot 是独立的,因此要找到该文件名就得要用如下的方式:
grub>find /grub/stage1 (hd0,0) # 这样就能够找到啰!要特别注意 grub 找到不是目录树,而是装置内的文件。
# 3. 搜寻一下是否可以找到核心? /boot/vmlinuz-2.6.18-92.el5 ? grub>find /boot/vmlinuz-2.6.18-92.el5 Error 15: File not found grub>find /vmlinuz-2.6.18-92.el5 (hd0,0) # 再次强调,因为 /boot/ 是独立的,因此就会变成上头的模样啰!
# 4. 将主程序安装上去吧!安装到 MBR 看看! grub>setup (hd0) Checking if "/boot/grub/stage1" exists... no<==因为 /boot 是独立的 Checking if "/grub/stage1" exists... yes<==所以这个文件名才是对的! Checking if "/grub/stage2" exists... yes Checking if "/grub/e2fs_stage1_5" exists... yes Running "embed /grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded. succeeded Running "install /grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded<==将 stage1 程序安装妥当啰! Done. # 很好!确实有装起来~这样 grub 就在 MBR 当中了!
# 5. 那么重复安装到我的 /dev/hda1 呢?亦即是 boot sector 当中? grub>setup (hd0,0) Checking if "/boot/grub/stage1" exists... no Checking if "/grub/stage1" exists... yes Checking if "/grub/stage2" exists... yes Checking if "/grub/e2fs_stage1_5" exists... yes Running "embed /grub/e2fs_stage1_5 (hd0,0)"...failed (this is not fatal) Running "embed /grub/e2fs_stage1_5 (hd0,0)"...failed (this is not fatal) Running "install /grub/stage1 (hd0,0) /grub/stage2 p /grub/grub.conf "... succeeded Done. # 虽然无法将 stage1_5 安装到 boot sector 去,不过,还不会有问题, # 重点是最后面那个 stage1 要安装后,显示 succeeded 字样就可以了!
grub>quit |
如此一来,就已经将 grub 安装到 MBR 及 /dev/hda1 的 boot sector 里面去了! 而且读取的是 (hd0,0) 里面的 /grub/menu.lst 那个文件喔!真是很重要啊!重要到不行!
最后总结一下:
- 如果是从其他 boot loader 转成 grub 时,得先使用 grub-install 安装 grub 配置文件;
- 开始编辑 menu.lst 这个重要的配置文件;
- 透过 grub 来将主程序安装到系统中,如 MBR 的 (hd0) 或 boot sector 的 (hd0,0) 等等。