Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1351493
  • 博文数量: 245
  • 博客积分: 10021
  • 博客等级: 上将
  • 技术积分: 3094
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-12 14:51
文章存档

2011年(2)

2009年(152)

2008年(91)

我的朋友

分类: LINUX

2009-01-27 14:47:27

  
  如果你的 Linux 主机本来就是 grub 的话,那么你就不需要重新安装 grub 了, 因为 grub 本来就会主动去读取设定档啊!您说是吧!但如果你的 Linux 原来使用的并非 grub , 那么就需要来安装啦!如何安装呢?首先,你必须要使用 grub-install 将一些必要的档案复制到 /boot/grub 里面去,你应该这样做的:

  [root@linux ~]# grub-install [--root-directory=DIR] INSTALL_DEVICE
  参数:
  --root-directory=DIR 那个 DIR 为实际的目录,使用 grub-install 预设会将grub 所有的档案都复制到 /boot/grub/* 当中,但如果想要复制到其他目录与装置去,就得要用这个参数。
  INSTALL_DEVICE 安装的装置代号啦!

  范例一:将 grub 安装在目前系统的 / 底下,我的系统为 /dev/hda:
  [root@linux ~]# grub-install /dev/hda
  Installation finished. No error reported.
  This is the contents of the device map /boot/grub/device.map.
  Check if this is correct or not. If any of the lines is incorrect,
  fix it and re-run the script `grub-install'.

  # this device map was generated by anaconda
  (fd0)     /dev/fd0
  (hd0)     /dev/hda
  # 如果去查阅一下 /boot/grub 的内容,会发现所有的档案都更新了,
  # 没错啊!因为我们重新安装了嘛!

  范例二:我的 /dev/hdb 挂载到 /disk2 下,如何安装 grub 到 /dev/hdb ?
  [root@linux ~]# grub-install --root-directory=/disk2 /dev/hdb
  Probing devices to guess BIOS drives. This may take a long time.
  Installation finished. No error reported.
  This is the contents of the device map /disk2/boot/grub/device.map.
  Check if this is correct or not. If any of the lines is incorrect,
  fix it and re-run the script `grub-install'.

  (fd0)   /dev/fd0
  (hd0)   /dev/hda
  (hd1)   /dev/hdb
  [root@linux ~]# ll /disk2/boot/grub/
  -rw-r--r--  1 root root     45 Sep 27 22:10 device.map
  -rw-r--r--  1 root root   7476 Sep 27 22:10 e2fs_stage1_5
  -rw-r--r--  1 root root   7300 Sep 27 22:10 fat_stage1_5
  -rw-r--r--  1 root root   6612 Sep 27 22:10 ffs_stage1_5
  -rw-r--r--  1 root root   6612 Sep 27 22:10 iso9660_stage1_5
  -rw-r--r--  1 root root   8096 Sep 27 22:10 jfs_stage1_5
  -rw-r--r--  1 root root   6772 Sep 27 22:10 minix_stage1_5
  -rw-r--r--  1 root root   8980 Sep 27 22:10 reiserfs_stage1_5
  -rw-r--r--  1 root root    512 Sep 27 22:10 stage1
  -rw-r--r--  1 root root 101704 Sep 27 22:10 stage2
  -rw-r--r--  1 root root   6952 Sep 27 22:10 ufs2_stage1_5
  -rw-r--r--  1 root root   6228 Sep 27 22:10 vstafs_stage1_5
  -rw-r--r--  1 root root   8764 Sep 27 22:10 xfs_stage1_5
  # 看!档案都安装进来了!但是注意到,我们并没有设定档喔!那要自己建立!

  所以说, grub-install 是安装 grub 到你的装置上面,但是,还需要设定好设定档 (menu.lst) 后, 再以 grub shell 来安装 grub 到 MBR 或者是 Super block 里面去喔!好了,那我们来思考一下想要安装的资料。 鸟哥的 Linux 主机上面,其实仅有一个 Linux 系统,但我的 FC4 已经升级过很多次,所以我的 Linux 有‘很多核心’,我想让每个核心都能够使用来开机,而且,还想要将 grub 同时安装在 MBR 与 Super block 当中, 并且 MBR 的 grub 可以将 loader 的控制权转交给 super block ,那么该如何安装呢? 基于这样的想法,我的设定档应该是这样的:

  [root@linux ~]# vi /boot/grub/menu.lst
  default=0
  timeout=5
  splashimage=(hd0,0)/boot/grub/splash.xpm.gz
  hiddenmenu
  title Fedora Core (2.6.12-1.1456_FC4)
  root (hd0,0)
  kernel /boot/vmlinuz-2.6.12-1.1456_FC4 ro root=LABEL=/  vga=787
  initrd /boot/initrd-2.6.12-1.1456_FC4.img
  title Fedora Core (2.6.11-1.1369_FC4)
  root (hd0,0)
  kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/  vga=787
  initrd /boot/initrd-2.6.11-1.1369_FC4.img
  title Fedora Super block loader
      root (hd0,0)
      chainloader +1

  然后再开始以 grub shell 来进行安装!整个安装与 grub shell 的动作其实很简单, 如果您有兴趣研究的话,可以使用 info grub 去查阅~鸟哥这里仅介绍几个有用的指令而已。

  * 用‘ root (hdx,x) ’选择含有 /boot 目录的那个 partition 代号;
  * 用‘ find /boot/grub/stage1 ’看看能否找到安装资讯档案;
  * 用‘ find /boot/vmlinuz ’看看能否找到 kernel file (不一定要成功!);
  * 用‘ setup (hdx,x) ’或‘ setup (hdx) ’将 grub 安装在 super block 或 MBR;
  * 用‘ quit ’来离开 grub shell !

  所以,请用 grub 来进入 grub shell 吧!进入 grub 后,会出现一个‘ grub> ’的提示字元啊!

  [root@linux ~]# grub

  1. 先设定一下含有 /boot 目录的那个 partition 啊!
  grub> root (hd0,0)
  Filesystem type is ext2fs, partition type 0x83
  # 瞧!找到啦!有这个 partition 的存在,且 grub 认识他为 ext2 的 filesystem。

  2. 搜寻一下,是否存在 stage1 这个资讯档案?
  grub> find /boot/grub/stage1
  (hd0,0)
  (hd1,0)
  # 呵呵!竟然找到两个?因为刚刚我们也安装一个在 /dev/hdb1 嘛!

  3. 搜寻一下是否可以找到核心? /boot/vmlinuz ?
  grub> find /boot/vmlinuz
  Error 15: File not found
  grub> find /boot/vmlinuz-2.6.12-1.1456_FC4
  (hd0,0)
  # 没办法,FC4 没有连结档,所以需要填写完整的 kernel 档案名称!

  4. 给他安装上去吧!安装到 MBR 看看!
  grub> setup (hd0)
  Checking if "/boot/grub/stage1" exists... yes
  Checking if "/boot/grub/stage2" exists... yes
  Checking if "/boot/grub/e2fs_stage1_5" exists... yes
  Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  15 sectors are embedded.
  succeeded
  Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/boot/grub/stage2
  /boot/grub/grub.conf"... succeeded
  Done.
  # 很好!确实有装起来~这样 grub 就在 MBR 当中了!

  5. 那么重复安装到我的 /dev/hda1 呢?亦即是 super block 当中?
  grub> setup (hd0,0)
  Checking if "/boot/grub/stage1" exists... yes
  Checking if "/boot/grub/stage2" exists... yes
  Checking if "/boot/grub/e2fs_stage1_5" exists... yes
  Running "embed /boot/grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
  Running "embed /boot/grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
  Running "install /boot/grub/stage1 (hd0,0) /boot/grub/stage2 p
  /boot/grub/grub.conf "... succeeded
  Done.
  # 虽然无法将 stage1_5 安装到 super block 去,不过,还不会有问题,
  # 重点是最后面那个 stage1 要安装后,显示 succeeded 字样就可以了!

  grub> quit

  如此一来,就已经将 grub 安装到 MBR 及 super block 里面去了! 而且读取的是 (hd0,0) 里面的 /boot/grub/menu.lst 那个档案喔! 真是很重要啊!重要到不行!

阅读(3155) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~