在自制Linux盘上安装GRUB

     本人在一块硬盘上攒出一个Linux系统盘,但没有引导程序,因此该硬盘不能独立启动。为此希望将GRUB安装到自制Linux系统的硬盘上。本人参照文[1]安装GRUB,由于安装环境和作者的不同,在安装过程中出现了些问题。后来反复阅读和查找资料,终于正确安装GRUB,并在自制Linux盘中独立启动了Linux系统。现在将制作过程记录如下:

第1步:先确定硬盘标识。

用命令fdisk查看当前的所以硬盘情况。

[root@localhost root]# fdisk -l

Disk /dev/hda: 255 heads, 63 sectors, 1305 cylinders
Units = cylinders of 16065 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1      1273  10225341   83  Linux
/dev/hda2          1274      1305    257040   82  Linux swap

Disk /dev/hdb: 16 heads, 63 sectors, 8322 cylinders
Units = cylinders of 1008 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hdb1   *         1      8322   4194256+  83  Linux

[root@localhost root]#

从上诉显示中,确定我们需要安装GRUB的硬盘标识为/dev/hdb。

第2步:安装GRUB的配置。

本人参照文[1],在系统提示符下键入grub-install命令。
[root@localhost root]# grub-install /dev/hdb
/dev/hdb does not have any corresponding BIOS drive.
[root@localhost root]#
系统提示错误。

通过阅读其它资料,发现需要指定grub安装的根目录。若未指定根目录,则系统默认安装在系统的根目录下,即目录"/"下,则grub将被安装在目录/boot/grub中。但目录/boot/grub是在设备/dev/hda上,而不是我们指定的设备/dev/hdb。所以就产生了上述错误提示。

为了能正确安装GRUB的配置,则需要将/dev/hdb挂接到系统的目录中,使系统可以读写该设备,同时通过grub-install的参数指定根目录。具体操作如下:
[root@localhost root]# mkdir /mnt/boot
[root@localhost root]# mount /dev/hdb1 /mnt/boot
[root@localhost root]# grub-install --root-directory=/mnt /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 /mnt/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@localhost root]#

grub-install命令是将grub的配置安装在指定根目录的/boot/grub子目录中。因为本人制作的Linux系统盘为/boot分区,所以将设备/dev/hdb1挂接到目录/mnt/boot上,而在grub-install中指定根目录为目录/mnt。

第3步:设定GRUB的/boot分区并写入MBR

用gurb命令设定GRUB的/boot分区并写入MBR。

[root@localhost root]# grub

    GRUB  version 0.92  (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> root (hd1,0)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd1)
 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 (hd1)"...  22 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd1) (hd1)1+22 p (hd1,0)/grub/stage2 /grub/grub
.conf"... succeeded
Done.

grub> quit

[root@localhost root]#

第4步:配置GRUB

现在剩下最后一步,编辑GRUB配置文件。

[root@localhost root]# vi /mnt/boot/grub/grub.conf
# 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,0)
#          kernel /boot/vmlinuz-version ro root=/dev/hda1
#          initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title linux
        root (hd0,0)
        kernel /vmlinuz ro root=/dev/ram0
        initrd /initrd.img

[root@localhost root]#

按上述配置编辑文件grub.conf,并保存。

注意:GRUB 0.92默认的配置文件名是grub.conf,而GRUB 0.97默认的配置文件名是menu.lst。
若使用的GRUB的版本为0.97,还需要执行以下命令:
[root@localhost root]# ln -fs grub.conf /mnt/boot/grub/menu.lst

按以上4步即完成了GRUB的安装。用自制Linux盘启动,出现了"login:"的提示。大功告成:))

参考文献:
[1] "系统引导管理器GRUB,为初学者指南", http://www.linuxsir.org/main/?q=node/129
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值