避开引导装入程序(grub),谈谈系统启动 (转)

                                                   作者:贾威威  ([email protected])
介绍
======
引导装入程序(boot loader)是由BIOS(Basic Input Output System)用来把操作系统的内核镜像装载到RAM中所调用的一个程序。早期的引导装入程序是MBR(Master Boot Record)中的一个小程序(MBR中其余部分是分区表),这个小程序用来装载被启动的操作系统所在分区的第一个扇区。这种小程序只能识别被活动标志标记的操作系统,所以具有一定的局限性。Linux处理方式变的很灵活了,因为Linux使用一个巧妙的程序把这个包含在MBR中的不完善的程序替换掉了,这个程序称为LILO或者GRUB(Grand Unified Bootloader),它允许用户来选择要启动的操作系统。目前我们常用的引导装入程序都是GRUB。

目的
=====
避开grub版本不一致问题,在pc上,先安装ubuntu 10.04再安装centos 5.4,然后从centos的grub中可以正确引导ubuntu。

问题描述
==========
主要问题是,ubuntu 10.04的grub版本是1.98,而centos的grub版本是0.97,两种版本的grub启动项的书写方式不一致,而且不同发行版的启动方式也存在区别。

具体步骤
=========
1, 我分别在/dev/sda1和/dev/sda3上安装了ubuntu和centos, /dev/sda2作为两者的公共swap。
2, 这时你只能通过grub引导centos,而不能引导ubuntu, 当然你也可以通过grub命令行,或者Live_CD启动ubuntu,但是那样不能治跟,只能暂时启动某一种发行版,下一次又不能通过grub选择任意启动一种。这里所存在的问题,可参考"问题描述"。
3, 启动centos, 然后把 /dev/sda1 挂载到 mnt下
       sudo mount   /dev/sda1  /mnt   &&   cd   /mnt
4,    拷贝ub下的启动内核,和initrd到centos的boot目录下
       sudo cp vmlinuz-2.6.32-21-generic vmlinuz-2.6.32-21-generic  /boot/
5,   重新配置 grub启动项,如下:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,2)
#          kernel /boot/vmlinuz-version ro root=/dev/sda3
#          initrd /boot/initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,2)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-164.el5xen)
 root (hd0,2)
 kernel /boot/xen.gz-2.6.18-164.el5 
 module /boot/vmlinuz-2.6.18-164.el5xen ro root=LABEL=/ rhgb quiet
 module /boot/initrd-2.6.18-164.el5xen.img
title Ubuntu (10.04)
 root (hd0,2)
 kernel /boot/vmlinuz-2.6.32-21-generic root=UUID=9b973a7f-de5a-4753-b3d6-b48f6fa01f06 ro   quiet splash
 initrd /boot/initrd.img-2.6.32-21-generic
 

6, 重新启动系统, reboot后即可顺利启动ub了。

注意事项
==========
1, grub启动项中ub启动项的 root (hd0, 2)是centos 的'\', 因为我们把内核和initrd拷贝到了centos的boot目录下,这样就巧妙的避免了grub版本不一致的问题。
2, 利用Live_CD启动ub,然后grub-install 和 grub-update 不适用与centos和ub,我测试过了,可能适用于redhat+ub(我的师兄测试过了)。
3, 由于我要在centos下配置xen环境,所以需要在centos下设置ub的grub启动项,因为以后xen的启动项比较好添加,当然你也可以把启动项添加到ub的grub中。
4, 抛砖引玉,修改grub启动项的方法很多,请理解为主,不要拘泥。
5, 由于本人水平有限,如果你在实验的过程中发现某些步骤不是很合理或者存在问题,请及时指正。

结束语
=======
希望大家秉承开源理念,free open share,互相学习,共同进步 ;-)

References
===========
[0] Namran. http://blog.namran.net/2009/11/13/integrating-ubuntu-boot-config-into-centos-5-4-grub/   November 13th, 2009
[1] 深入理解Linux内核. Daniel P. Bovet & Marco Cesati 著. 陈莉君 冯锐 牛欣源 译. 孙玉芳 审. 2004. 中国电力出版社

http://harryxiyou.blog.163.com/blog/static/12957033420121189301948/

猜你喜欢

转载自yiranwuqing.iteye.com/blog/1410466