GRUB

 

# grub

GNU GRUB version 0.95 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
  lists possible command completions. Anywhere else TAB lists the possible
  completions of a device/filename.]

grub>_




1、初识Linux中的grub

#ls -l /boot/grub/

-rw-r--r-- 1 root root   82 7月 24 11:08 device.map
-rw-r--r-- 1 root root   7956 7月 24 11:08 e2fs_stage1_5
-rw-r--r-- 1 root root   7684 7月 24 11:08 fat_stage1_5
-rw-r--r-- 1 root root   6996 7月 24 11:08 ffs_stage1_5
-rw------- 1 root root   660 7月 24 11:08 grub.conf
-rw-r--r-- 1 root root   7028 7月 24 11:08 iso9660_stage1_5
-rw-r--r-- 1 root root   8448 7月 24 11:08 jfs_stage1_5
lrwxrwxrwx 1 root root   11 7月 24 11:08 menu.lst -> ./grub.conf
-rw-r--r-- 1 root root   7188 7月 24 11:08 minix_stage1_5
-rw-r--r-- 1 root root   9428 7月 24 11:08 reiserfs_stage1_5
-rw-r--r-- 1 root root 11182 2004-12-03 splash.xpm.gz
-rw-r--r-- 1 root root   512 7月 24 11:08 stage1
-rw-r--r-- 1 root root 103848 7月 24 11:08 stage2
-rw-r--r-- 1 root root   7272 7月 24 11:08 ufs2_stage1_5
-rw-r--r-- 1 root root   6612 7月 24 11:08 vstafs_stage1_5
-rw-r--r-- 1 root root   9308 7月 24 11:08 xfs_stage1_5

# file stage1   stage1: x86 boot sector, code offset 0x48
# file stage2   stage2: data
# file e2fs_stage1_5   e2fs_stage1_5: data

2、#find / -name grub*

/etc/sysconfig/grub
/etc/grub.conf
/sbin/grub
/sbin/grubby
/sbin/grub-terminfo
/sbin/grub-install
/sbin/grub-md5-crypt
/usr/share/grub/i386-redhat/
/usr/share/rhn/up2date_client/grubcfg.pyc
......
/usr/share/doc/grub-0.95
/boot/grub/
/boot/grub/grub.conf

# ls /sbin/grub*
grub grubby grub-install grub-md5-crypt grub-terminfo

3、安装grub到硬盘
用脚本安装:grub-install /dev/hda
用grub 's shell安装 :grub > root (hda,x)
                    grub >setup(hda,y)
  GRUB 的 root 分区是保存 Linux 内核的分区。这可能是您的正式 root 文件系统,也可能不是。
  如:你的/boot(含有内核文件)与/分属于不同的分区的时候。
  GRUB进入 root 分区时,GRUB 将把这个分区安装成只读型,这样就可以从该分区中装入 Linux 内核。GRUB 支持多种类型的分区。.GRUB 对硬盘和分区的编号都是从 0 开始计算,硬盘和分区都用逗号分隔,整个表达式用括号括起。hda5="root (hd0,4)"

  给出内核位置(告诉grub到哪里去装)指出内核文件(装谁):  
kernel /boot/vmlinuz-2.6.9-5.EL ro root=LABEL=/1 rhgb quiet
/boot/vmlinuz-2.6.9-5.EL 就是要载入的内核。后面的都是传递给内核的参数。root=LABEL=/就是linux的硬盘分区表示法,ro是readonly的意思。
initrd /boot/initrd-2.6.9-5.EL.img
initrd是“initial ramdisk”的简写。initrd一般被用来临时的引导硬件到实际内核vmlinuz能够接管并继续引导的状态。
比如,使用的是scsi硬盘,而内核vmlinuz中并没有这个scsi硬件的驱动,那么在装入scsi模块之前,内核不能加载根文件系统,但scsi模块存储在根文件系统的/lib/modules下。为了解决这个问题,可以引导一个能够读实际内核的initrd内核并用initrd修正scsi引导问题。initrd-2.6.9-5.EL.img是用gzip压缩的文件,initrd实现加载一些模块和安装文件系统等功能。
 
4、3 配置grub
grub启动时会在/boot/grub/中寻找一个名字为menu.lst的配置文件,如果找不到此文件则不进入菜单模式而直接进入命令行模式。
有两种方法来完成启动过程:
·A.通过调用内核本地启动
·B.连续启动或者将控制转给另一个引导器
A模式启动过程
1.配置根设备或者告诉GRUB你的根文件系统。 grub > root(hdx,y)
2.告诉GRUB你的内核影像的位置,然后将参数传送给内核。grub> kernel
3.重新启动,试一下。 grub >boot
为了启动Linux,将内核以bzImage的文件名放在/boot/目录中,根文件系统是 /dev/hda1,或者GRUB中的(hd0,0)。启动过程如下: 1.root (hd0,0) [This sets the root partition]
    2.kernel /boot/bzImage root=/dev/hda1 [This sets the kernel]
B模式启动过程(这种模式假设当前的分区中安装了另一个启动管理器,例如LILO或者NTLDR):
1.设置根分区但不要安装它   1.rootnoverify (hd1,0)
2.激活这个分区             2.makeactive
3.配置需要启动的分区的第一个扇区   3.chainloader +1 [+1 sets the first sector of the current root partition]
4.重新启动,看一下效果。   4.boot [transfers the control and quits GRUB]

5、4 GRUB的交互性
  如果更新内核或更改它在磁盘上的位置,不必重新安装 GRUB。如有必要,只要更新 menu.lst 文件即可,一切将保持正常。
  只有少数情况下,才需要将 GRUB 引导装入器重新安装到引导记录。
  首先,如果更改 GRUB root 分区的分区类型(例如,从 ext2 改成 ReiserFS),则需要重新安装。
  或者,如果更新 /boot/grub 中的 stage1 和 stage2 文件,由于它们来自更新版本的 GRUB,很有可能要重新安装引导装入器。
  GRUB的最大的特点就是交互性特别强。在开机时,按一下“c”,将进入GRUB 控制台。显示如下:

  GRUB version 0.5.96.1 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
grub>
欢迎使用 GRUB 控制台。
grub> root (h
现在,按一次 Tab 键。如果系统中有多个硬盘,GRUB 将显示可能完成的列表,从 "hd0" 开始。如果只有一个硬盘,GRUB 将插入 "hd0,"。如果有多个硬盘,继续进行,在 ("hd2") 中输入名称并在名称后紧跟着输入逗号,
grub> root (hd0,
现在,继续操作,再按一次 Tab 键。GRUB 将显示特定硬盘上所有分区的列表,以及它们的文件系统类型。在我的系统中,按 Tab 键时得到以下列表:
grub> root (hd0, (tab,按tab一下键)
Possible partitions are:
Partition num: 0, Filesystem type is fat, partition type 0x6
Partition num: 2, Filesystem type is ext2fs, partition type 0x83
Partition num: 4, Filesystem type unknown, partition type 0x7
Partition num: 5, Filesystem type is ext2fs, partition type 0x83
...........

grub> root (hd0,
现在已安装了 root 文件系统,到装入内核的时候了
grub> kernel /boot/vmlinuz-2.4.2 root=/dev/hda5 ro
您已经安装了 root 文件系统并装入了内核。现在,只要输入 "boot",Linux 引导过程就将开始。

6、常见grub除错方法的思路
首先进去Linux的rescue模式!
用软盘或光盘启动,然后在启动的提示符输入:linux rescue
按照提示进入一个Shell状态,你可以到/mnt/下面看到一个sysp_w_picpath这么目录,进去以后,就是你安装linux的/分区.
使用命令将根分区变为当前目录的根分区:chroot /mnt/sysp_w_picpath
然后转到/sbin/这个目录中.
使用fdisk -l 显示当前分区情况,然后使用#grub-install /dev/hdx(x为你使用的是那块硬盘安装的,一般情况下是hda)
使用exit推出chroot,再使用exit退出linux rescue模式,系统将重新启动!
取出光盘,应该可以看到grub安装好了.
在具体的环境中,编辑/boot/grub/grub.conf文件和menu.lst文件

7、简化:
1.安装盘启动
2.进入linux rescue模式
3.一系列键盘以及几项简单的配制,就[继续]了......。
4.然后会出现这样的字符
sh#
5. sh#grub
会出现这样的字符:grub>我们就可以在这样的字符后面,输入:grub>root (hdX,Y)
grub>setup (hd0)
如果成功会有一个successful......
这里的X,如果是一个盘,就是0,如果你所安装的linux的根分区在第二个硬盘上,那X就是1了;Y,就是装有linux系统所在的根分区。 setup (hd0)就是把GRUB写到硬盘的MBR上。

8、其他:
grub菜单项丢失,只有字符grub>时的处理方法:
grub>cat (hd0,0) /root/grub/grub.conf(为了看参数。)
grub>root (hd0,1)
grub>kernel (hd0,0) /boot/vmlinuz-2.4.18-11 ro root=/dev/hda2
grub>initrd (hd0,0) /boot/initrd-2.4.18-11.img
grub>boot

将“color light-gray/blue ”加在default语句的下面OR“color light-blue/red"!
实验前请做好备份
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值