本人在一块硬盘上攒出一个Linux系统盘,但没有引导程序,因此该硬盘不能独立启动。为此希望将GRUB安装到自制Linux系统的硬盘上。本人参照文安装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,并保存。 按以上4步即完成了GRUB的安装。用自制Linux盘启动,出现了"login:"的提示。大功告成。 |
在自制Linux盘上安装GRUB
最新推荐文章于 2021-05-15 02:14:20 发布