Linux加载程序GRUB和LILO配置示例
2013-03-26 11:16
281 查看
前言:
PCs 的引导过程:
当 PC 启动时,BIOS (Basic Input Output Service) 会执行一个自检。
当机器通过自检时,BIOS 会加载 Master Boot Record(或 MBR,通常位于引导驱动器的第一个 512 字节扇区)。引动驱动器通常是系统上的第一个硬盘驱动器,但也可以是一个磁盘、CD 或 USB 密匙。
对于硬盘驱动器,MBR 加载一个阶段 1 启动加载程序,该程序通常是 Linux 系统上的 LILO 或 GRUB 阶段 1 启动加载程序。这是另一个 512 字节单扇区记录。
阶段 1 启动加载程序通常加载一个记录序列,该序列通常称为阶段 2 启动加载程序(有时称为阶段 1.5 加载程序)。
阶段 2 加载程序加载操作系统。对于 Linux,这是内核,也可能是初始 RAM 磁盘 (initrd)。
您的系统应该能够安装两个流行启动加载程序的其中一个:LILO (LInux LOader) 或 GRUB (GRand Unified Boot loader)。
清单 1. /boot/grub/menu.lst GRUB 配置示例(/boot/grub/grub.conf(或 /boot/grub/menu.lst))
(注:GRUB(至少是 GRUB Legacy)是从 0 而不是从 1 开始对驱动器、分区和其他需要计数的东西进行计数的。还要注意的是,第一个内核行非常长。对于发行版,我们使用一个反斜杠(\)来指出何处需要中断。)
示例中的所有其他部分应用的菜单命令包括:
#以 # 开头的所有行都是注释,GRUB 将对它们置之不理。这个特殊的配置文件最初由 Red Hat 安装程序 anaconda 生成。如果安装 Linux 时安装 GRUB,可能会发现您的 GRUB 配置文件添加了一些注释。这些注释通常用于帮助系统升级程序,以便您的 GRUB 配置能够与升级后的内核保持同步。当您自己编辑这个配置文件时,一定要注意为此目的而保留下来的任何标记。default如果用户在规定时限内没有做出任何选择,该命令将指定要加载的系统。在我们的示例中,default=2 表示加载第三项。不要忘了,GRUB 从 0 而不是 1 开始计数。如果没有指定,那么默认值是引导第一项,编号为 0。
timeout指定启动默认项超时,以秒为单位。注意,LILO 以 0.1 秒作为超时单位,而 GRUB 使用 1 秒作为超时单位。splashimage指定将与启动菜单一起显示的背景(或 splash)映像。GRUB 将第一个硬盘驱动器称之为 (hd0),将该驱动器上的第一个分区称之为 (hd0,0)。因此,splashimage=(hd0,6)/boot/grub/splash.xpm.gz 表示使用位于第一个硬盘驱动器的第 7 个分区上的文件 /boot/grub/splash.xpm.gz。注意,这个映像是一个使用 gzip 压缩的 XMP 文件。支持 splashimage 的是一个补丁,您的版本中可能没有包含。password 指定用户在能够解锁菜单、编辑一个配置行或输入 GRUB 命令前必须输入的密码。这个密码可能是明文格式。GRUB 还允许将密码存储为一个 MD5 摘要,我们的示例就是这样做的。这样更安全一些,大多数管理员都会设置一个密码。如果不设置密码,用户就能够完全访问 GRUB 命令行。
title 一个描述性标题,当 Grub 启动时显示为菜单项。使用方向键上下移动标题列表并按 Enter 键选择一个特定项。root 指定将要启动的分区。与 splashimage 一样,从 0 开始计数,因此指定为 root (hd0,6) 的第一个 Red Hat 系统实际上是在第一个硬盘驱动器的第 7 个分区上(本例中为 /dev/hda7),而指定为 root (hd1,10) 的第一个 Ubuntu 系统位于第二个硬盘驱动器上。GRUB 将尝试加载这个分区以检查它,并在某些情况下向已启动操作系统提供一些值。kernel指定将被加载的内核映像以及所需内核参数。这类似于 LILO
initrd初始 RAM 磁盘 的名称,包含文件系统挂载之前内核需要的模块。savedefault本示例中不使用。如果指定了菜单命令
chainloader指定将作为阶段 1 文件加载的另一个文件。值 “+1” 等同于 0+1,表示加载从扇区 0 开始的一个扇区,即,从 root 或 rootnoverify 指定的设备加载第一个扇区。
清单 2. 将 GRUB 安装到软盘上
注意:您可能使用 GRUB 设备名 (fd0) 而不是 /dev/fd0,如果您的确那样做,则必须用引号括起来,以免 shell 将其解释为圆括号。例如:
清单 3. 将 GRUB 安装到软盘
对于第一个 IDE 硬盘驱动器,您应该使用:
或
要将它安装到分区 11 的分区引导记录中,使用:
或
别忘了 GRUB 从 0 开始计数。
您可以向该命令添加引导参数。事实上,您可以编辑 GRUB 配置中的任何命令,或者甚至在引导时加载另一个配置文件。如果您使用一个密码,您将需要输入
Enter 键返回菜单。输入
清单 4. /usr/bin 和 /usr/sbin 中的 GRUB 2 可执行文件
GRUB 2 的核心是一个多重引导内核(/boot/grub/core.img)和一个配置文件(/boot/grub/grub.cfg)。如果您运行
清单 10. 尝试将 GRUB 2 安装到一个分区引导记录
清单 11. /etc/lilo.conf 示例
我们将通过创建一个启动软盘来测试我们的配置,因此指定了靠近文件顶部的 boot=/dev/fd0。我们还将提示超时增加到 20 秒(200 个 0.1 秒增量),并添加了第二个 “other” 条目来链式加载到 Fedora 8 分区上的启动加载程序(/dev/sda6)。在一个配置文件中,LILO 只支持一个
您可以使用 /sbin/lilo 中的
现在,如果我们使用一个 Linux 文件系统(比如 ext2)来格式化一个软盘,可以运行
清单 12 显示了我们的输出。请注意,
清单 12. 使用 lilo 创建一个可引导软盘
我们现在拥有了属于我们自己的可引导 LILO 软盘。如果 LILO 遇到一个错误,您可能会看到一条错误消息,引导扇区将不会被写入。这条错误消息会使您对需要修复的问题有所了解。
通过 GRUB 使用一个小型引导分区
创建一个 GRUB 启动软盘
创建一个 GRUB 可引导 CD 映像
在包含一个文件系统的软盘上安装 GRUB
LILO
LILO 配置文件默认为 /etc/lilo.conf。清单 1 展示了一个系统示例,该系统当前正在 /dev/sda10 上运行 Slackware,在 /dev/sda1 上运行 Windows,在 /dev/sdb12 上运行 Fedora 14。这个示例使用 /sbin/liloconfig 命令构建。
清单 1. LILO 配置示例
清单 1 中的配置文件包含一个位图参数,参数值为 /boot/slack.bmp。这是一个位图图像,将用于代替传统的 LILO 文本提示,如 图 2 所示。默认的引导图像 Slackware13 为突出显示
lilo 命令
记住,每当更改 /etc/lilo.conf 或者安装新内核时,都必须运行
除显示 LILO 配置文件外,可以使用
清单 3. 显示 LILO 配置
GRUB 配置示例
GRUB 提供一个菜单界面。它还使用一个通过 MD5 算法加密的密码,而不是 LILO 的纯文本密码。而且,也许最重要的是,对 GRUB 配置文件进行的更改不需要在 MBR 中安装 GRUB。注意,许多发行版均能在更新到一个新的内核级别时自动更新 GRUB(或 LILO)配置文件,但是,如果您安装一个新内核或创建一个新的初始 RAM 磁盘,那么可能需要编辑配置文件。
要为分区配置一个启动条目,GRUB 不需要装载该分区。您将看到
n 是一个整数,从 0 开始。类似地,磁盘上的分区从 0 开始编号。注意:GRUB2 已经更改了磁盘命名方式,因此在 GRUB 和 GRUB2 之间切换时要小心。
因此,在这个系统上,(hd0,0) 代表 Windows 主分区 /dev/sda1,而 (hd0,9) 代表 Slackware 逻辑分区 /dev/sda10。软盘驱动器通常是 (fd0)。如果使用这些参数从一个 bash shell 调用 GRUB,例如,在软盘、USB 密匙或您的 MBR 上安装 GRUB 时,别忘了使用引号将参数引起来。
PCs 的引导过程:
当 PC 启动时,BIOS (Basic Input Output Service) 会执行一个自检。
当机器通过自检时,BIOS 会加载 Master Boot Record(或 MBR,通常位于引导驱动器的第一个 512 字节扇区)。引动驱动器通常是系统上的第一个硬盘驱动器,但也可以是一个磁盘、CD 或 USB 密匙。
对于硬盘驱动器,MBR 加载一个阶段 1 启动加载程序,该程序通常是 Linux 系统上的 LILO 或 GRUB 阶段 1 启动加载程序。这是另一个 512 字节单扇区记录。
阶段 1 启动加载程序通常加载一个记录序列,该序列通常称为阶段 2 启动加载程序(有时称为阶段 1.5 加载程序)。
阶段 2 加载程序加载操作系统。对于 Linux,这是内核,也可能是初始 RAM 磁盘 (initrd)。
您的系统应该能够安装两个流行启动加载程序的其中一个:LILO (LInux LOader) 或 GRUB (GRand Unified Boot loader)。
清单 1. /boot/grub/menu.lst GRUB 配置示例(/boot/grub/grub.conf(或 /boot/grub/menu.lst))
# 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,5) # kernel /boot/vmlinuz-version ro root=/dev/sda6 # initrd /boot/initrd-version.img #boot=/dev/sda6 default=1 timeout=10 splashimage=(hd0,5)/boot/grub/splash.xpm.gz #hiddenmenu password --md5 $1$RW1VW/$4XGAklxB7/GJk0uO47Srx1 title Upgrade to Fedora 11 (Leonidas) kernel /boot/upgrade/vmlinuz preupgrade \ repo=hd::/var/cache/yum/preupgrade stage2=\ hd:UUID=8b4c62e7-2022-4288-8995-5eda92cd149b:/boot/upgrade/install.img \ ks=hd:UUID=8b4c62e7-2022-4288-8995-5eda92cd149b:/boot/upgrade/ks.cfg initrd /boot/upgrade/initrd.img title Fedora (2.6.26.8-57.fc8) root (hd0,5) kernel /boot/vmlinuz-2.6.26.8-57.fc8 ro root=LABEL=FEDORA8 rhgb quiet initrd /boot/initrd-2.6.26.8-57.fc8.img title Fedora (2.6.26.6-49.fc8) root (hd0,5) kernel /boot/vmlinuz-2.6.26.6-49.fc8 ro root=LABEL=FEDORA8 rhgb quiet initrd /boot/initrd-2.6.26.6-49.fc8.img title GRUB Menu rootnoverify (hd0,1) chainloader +1 title Windows rootnoverify (hd0,0) chainloader +1
(注:GRUB(至少是 GRUB Legacy)是从 0 而不是从 1 开始对驱动器、分区和其他需要计数的东西进行计数的。还要注意的是,第一个内核行非常长。对于发行版,我们使用一个反斜杠(\)来指出何处需要中断。)
示例中的所有其他部分应用的菜单命令包括:
#以 # 开头的所有行都是注释,GRUB 将对它们置之不理。这个特殊的配置文件最初由 Red Hat 安装程序 anaconda 生成。如果安装 Linux 时安装 GRUB,可能会发现您的 GRUB 配置文件添加了一些注释。这些注释通常用于帮助系统升级程序,以便您的 GRUB 配置能够与升级后的内核保持同步。当您自己编辑这个配置文件时,一定要注意为此目的而保留下来的任何标记。default如果用户在规定时限内没有做出任何选择,该命令将指定要加载的系统。在我们的示例中,default=2 表示加载第三项。不要忘了,GRUB 从 0 而不是 1 开始计数。如果没有指定,那么默认值是引导第一项,编号为 0。
timeout指定启动默认项超时,以秒为单位。注意,LILO 以 0.1 秒作为超时单位,而 GRUB 使用 1 秒作为超时单位。splashimage指定将与启动菜单一起显示的背景(或 splash)映像。GRUB 将第一个硬盘驱动器称之为 (hd0),将该驱动器上的第一个分区称之为 (hd0,0)。因此,splashimage=(hd0,6)/boot/grub/splash.xpm.gz 表示使用位于第一个硬盘驱动器的第 7 个分区上的文件 /boot/grub/splash.xpm.gz。注意,这个映像是一个使用 gzip 压缩的 XMP 文件。支持 splashimage 的是一个补丁,您的版本中可能没有包含。password 指定用户在能够解锁菜单、编辑一个配置行或输入 GRUB 命令前必须输入的密码。这个密码可能是明文格式。GRUB 还允许将密码存储为一个 MD5 摘要,我们的示例就是这样做的。这样更安全一些,大多数管理员都会设置一个密码。如果不设置密码,用户就能够完全访问 GRUB 命令行。
title 一个描述性标题,当 Grub 启动时显示为菜单项。使用方向键上下移动标题列表并按 Enter 键选择一个特定项。root 指定将要启动的分区。与 splashimage 一样,从 0 开始计数,因此指定为 root (hd0,6) 的第一个 Red Hat 系统实际上是在第一个硬盘驱动器的第 7 个分区上(本例中为 /dev/hda7),而指定为 root (hd1,10) 的第一个 Ubuntu 系统位于第二个硬盘驱动器上。GRUB 将尝试加载这个分区以检查它,并在某些情况下向已启动操作系统提供一些值。kernel指定将被加载的内核映像以及所需内核参数。这类似于 LILO
映像和
append命令的组合,您将在 LILO 小节看到该命令。在本例中,有两个不同的 Fedora 8 内核,以及升级内核。
initrd初始 RAM 磁盘 的名称,包含文件系统挂载之前内核需要的模块。savedefault本示例中不使用。如果指定了菜单命令
default=saved,并为一个操作系统指定了
savedefault命令,那么引导该操作系统将导致它变为默认值,直至启动带有指定
savedefault的另一个操作系统。在这个示例中,default=2 将覆盖保存的所有默认值。boot一个可选参数,指示 GRUB 启动选择的操作系统。当一个选项所有命令全部执行完时,这将是一个默认操作。lock本示例中不使用。没有输入密码之前不会启动指定项。如果使用这个命令,那么还应该在初始选项中指定一个密码;否则,用户可以编辑您的锁定选项并启动系统,或者添加 “single” 到其中的一项。如果您愿意的话,还可以为个别条目指定一个不同的密码。rootnoverify类似于 root,除非 GRUB 不尝试挂载文件系统或验证其参数。这通常用于 GRUB 不支持的文件系统,比如 NIFS。如果您想要 GRUB 加载硬盘驱动器上的主引导记录,也可以使用这个命令,例如,访问不同的配置文件或者重新加载您之前的启动加载程序。
chainloader指定将作为阶段 1 文件加载的另一个文件。值 “+1” 等同于 0+1,表示加载从扇区 0 开始的一个扇区,即,从 root 或 rootnoverify 指定的设备加载第一个扇区。
清单 2. 将 GRUB 安装到软盘上
[root@pinguino ~]# grub-install /dev/fd0 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'. (fd0) /dev/fd0 (hd0) /dev/sda
注意:您可能使用 GRUB 设备名 (fd0) 而不是 /dev/fd0,如果您的确那样做,则必须用引号括起来,以免 shell 将其解释为圆括号。例如:
grub-install '(fd0)'。
清单 3. 将 GRUB 安装到软盘
[root@pinguino ~]# grub-install /dev/fd0 /dev/fd0 does not have any corresponding BIOS drive.
对于第一个 IDE 硬盘驱动器,您应该使用:
grub-install /dev/sda
或
grub-install '(hd0)'。
要将它安装到分区 11 的分区引导记录中,使用:
grub-install /dev/sda11
或
grub-install '(hd0,10)'。
别忘了 GRUB 从 0 开始计数。
您可以向该命令添加引导参数。事实上,您可以编辑 GRUB 配置中的任何命令,或者甚至在引导时加载另一个配置文件。如果您使用一个密码,您将需要输入
p命令,然后输入您的密码。然后,选择一个条目并输入
e命令对其进行编辑。选择想要编辑的行并再次输入
e。通过输入新的字符或删除现有字符编辑该行,然后按
Enter 键返回菜单。输入
b命令来使用修改值启动您的系统。
清单 4. /usr/bin 和 /usr/sbin 中的 GRUB 2 可执行文件
ian@pinguino:~$ dpkg -L grub-pc|grep "bin/" /usr/bin/grub-mkimage /usr/bin/grub-mkrescue /usr/sbin/grub-setup /usr/sbin/update-grub2 /usr/sbin/update-grub /usr/sbin/grub-install /usr/sbin/upgrade-from-grub-legacy /usr/sbin/grub-set-default /usr/sbin/grub-reboot
GRUB 2 的核心是一个多重引导内核(/boot/grub/core.img)和一个配置文件(/boot/grub/grub.cfg)。如果您运行
grub-install并设置目标为您的 MBR(例如:
grub-install /dev/sda),这些文件会自动生成。运行
grub-install --help,了解被调用来完成所有这些工作的程序。
清单 10. 尝试将 GRUB 2 安装到一个分区引导记录
ian@pinguino:~$ sudo grub-install /dev/sda7 grub-setup: warn: Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea. grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and its use is discouraged. 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'. (hd0) /dev/sda
清单 11. /etc/lilo.conf 示例
# Originally generated by liloconfig - modified by Ian Shields # This allows booting from any partition on disks with more than 1024 # cylinders. lba32 # Specifies the boot device (floppy) boot=/dev/fd0 # Specifies the device that should be mounted as root. # If the special name CURRENT is used, the root device is set to the # device on which the root file system is currently mounted. If the root # has been changed with -r , the respective device is used. If the # variable ROOT is omitted, the root device setting contained in the # kernel image is used. It can be changed with the rdev program. root=/dev/sda7 # Bitmap configuration for /boot/coffee.bmp bitmap=/boot/coffee.bmp bmp-colors=12,,11,15,,8 bmp-table=385p,100p,1,10 bmp-timer=38,2,13,1 # Enables map compaction: # Tries to merge read requests for adjacent sectors into a single # read request. This drastically reduces load time and keeps the map # smaller. Using COMPACT is especially recommended when booting from a # floppy disk. compact # Install the specified file as the new boot sector. # LILO supports built in boot sectors, you only need # to specify the type, choose one from 'text', 'menu' or 'bitmap'. # new: install=bmp old: install=/boot/boot-bmp.b # new: install=text old: install=/boot/boot-text.b # new: install=menu old: install=/boot/boot-menu.b or boot.b # default: 'menu' is default, unless you have a bitmap= line # Note: install=bmp must be used to see the bitmap menu. # install=menu install=bmp # Specifies the number of _tenths_ of a second LILO should # wait before booting the first image. LILO # doesn't wait if DELAY is omitted or if DELAY is set to zero. # delay=20 # Prompt to use certain image. If prompt is specified without timeout, # boot will not take place unless you hit RETURN. Timeout is in tenths of # a second. prompt timeout=200 # Enable large memory mode. large-memory # Specifies the location of the map file. If MAP is # omitted, a file /boot/map is used. map=/boot/map # Specifies the VGA text mode that should be selected when # booting. The following values are recognized (case is ignored): # NORMAL select normal 80x25 text mode. # EXTENDED select 80x50 text mode. The word EXTENDED can be # abbreviated to EXT. # ASK stop and ask for user input (at boot time). # <number> use the corresponding text mode. A list of available modes # can be obtained by booting with vga=ask and pressing [Enter]. vga=normal # Defines non-standard parameters for the specified disk. #disk=/dev/sda # bios=0x80 # If you are using removable USB drivers (with mass-storage) # you will need to tell LILO to not use these devices even # if defined in /etc/fstab and referenced in /proc/partitions. # Adjust these lines to your devices: # # disk=/dev/sda inaccessible # disk=/dev/sdb inaccessible # These images were automagically added. You may need to edit something. image=/boot/vmlinuz-2.6.31-14-generic label="Lin 2.6.31-14" initrd=/boot/initrd.img-2.6.31-14-generic read-only image=/boot/vmlinuz-2.6.31-20-generic label="Lin 2.6.31-20" initrd=/boot/initrd.img-2.6.31-20-generic read-only image=/boot/memtest86+.bin label="Memory Test+" read-only # If you have another OS on this machine (say DOS), # you can boot if by uncommenting the following lines # (Of course, change /dev/sda1 to wherever your DOS partition is.) other=/dev/sda6 label="Fedora 8" other=/dev/sda1 label="Windows XP" |
root命令,因此它可以启动 root 分区中的多个映像,但需要链式加载到另一个启动加载程序来启动另一个不同安装中的映像,比如我们的示例中的 Fedora 8 (/dev/sda6) 或 Windows XP (/dev/sda1)。
您可以使用 /sbin/lilo 中的
lilo命令来编写一个阶段 1 引导记录,并使用通常位于 /etc/lilo.conf 中的配置信息(比如上面的示例)来创建一个映像文件(/boot/map)。我们稍后会提到一些辅助用法。
现在,如果我们使用一个 Linux 文件系统(比如 ext2)来格式化一个软盘,可以运行
lilo命令(/sbin/lilo)来创建一个可引导软盘。
清单 12 显示了我们的输出。请注意,
lilo命令有 5 个级别,为每个级别指定一个额外的 -v 参数。该示例是使用
lilo -v -v创建的。
清单 12. 使用 lilo 创建一个可引导软盘
LILO version 22.8, Copyright (C) 1992-1998 Werner Almesberger Development beyond version 21 Copyright (C) 1999-2006 John Coffman Released 19-Feb-2007, and compiled at 10:52:38 on Aug 25 2009 Running Linux kernel 2.6.31-14-generic on i686 Ubuntu raid_setup returns offset = 00000000 ndisk = 0 BIOS VolumeID Device Reading boot sector from /dev/fd0 pf_hard_disk_scan: ndevs=1 0800 54085408 /dev/sda device codes (user assigned pf) = 0 device codes (user assigned) = 0 device codes (BIOS assigned) = 1 device codes (canonical) = 1 mode = 0x03, columns = 80, rows = 25, page = 0 Using BITMAP secondary loader Calling map_insert_data Secondary loader: 19 sectors (0x3800 dataend). Warning: The boot sector and map file are on different disks. bios_boot = 0x00 bios_map = 0x80 map==boot = 0 map S/N: 54085408 Mapping bitmap file /boot/coffee.bmp Calling map_insert_file Compaction removed 592 BIOS calls. Bitmap: 603 sectors. BIOS data check was okay on the last boot Boot image: /boot/vmlinuz-2.6.31-14-generic Setup length is 26 sectors. Compaction removed 7452 BIOS calls. Mapped 7601 sectors. Mapping RAM disk /boot/initrd.img-2.6.31-14-generic Compaction removed 14696 BIOS calls. RAM disk: 14930 sectors. Added Lin_2.6.31-14 * Boot image: /boot/vmlinuz-2.6.31-20-generic Setup length is 26 sectors. Compaction removed 7468 BIOS calls. Mapped 7617 sectors. Mapping RAM disk /boot/initrd.img-2.6.31-20-generic Compaction removed 14704 BIOS calls. RAM disk: 14938 sectors. Added Lin_2.6.31-20 Boot image: /boot/memtest86+.bin Setup length is 4 sectors. Compaction removed 243 BIOS calls. Mapped 254 sectors. Added Memory_Test+ Boot other: /dev/sda6, loader CHAIN Pseudo partition start: 43198848 Compaction removed 0 BIOS calls. Mapped 6 (4+1+1) sectors. Added Fedora_8 Boot other: /dev/sda1, on /dev/sda, loader CHAIN Compaction removed 0 BIOS calls. Mapped 6 (4+1+1) sectors. Added Windows_XP BIOS VolumeID Device 80 54085408 0800 Writing boot sector. /boot/boot.0200 exists - no boot sector backup copy made. Map file size: 336896 bytes. RAID device mask 0x0000 One warning was issued. |
通过 GRUB 使用一个小型引导分区
# menu.lst - See: grub(8), info grub, update-grub(8) # grub-install(8), grub-floppy(8), # grub-md5-crypt, /usr/share/doc/grub # and /usr/share/doc/grub-doc/. ## default num # Set the default entry to the entry number NUM. Numbering starts from 0, and # the entry number 0 is the default if the command is not used. # # You can specify 'saved' instead of a number. In this case, the default entry # is the entry saved with the command 'savedefault'. default 0 ## timeout sec # Set a timeout, in SEC seconds, before automatically booting the default entry # (normally the first entry defined). timeout 10 ## password ['--md5'] passwd # If used in the first section of a menu file, disable all interactive editing # control (menu entry editor and command-line) and entries protected by the # command 'lock' # e.g. password topsecret # password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/ # password topsecret title Fedora 8 (sda6) Grub menu root (hd0,5) chainloader +1 boot # Ubuntu 9.10 uses GRUB 2, so use kernel to drive GRUB 2 menu. title Ubuntu 9.10 (sda7) root (hd0,6) kernel /boot/grub/core.img # This is a divider, added to separate the menu items below from the Debian # ones. title Other operating systems: root # Windows XP title Windows NT/XP root (hd0,0) savedefault chainloader +1
创建一个 GRUB 启动软盘
[root@pinguino ~]# ls /usr/share/grub/ i386-redhat [root@pinguino ~]# cd /usr/share/grub/i386-redhat/ [root@pinguino i386-redhat]# ls -l st* -rw-r--r-- 1 root root 512 2008-05-28 12:05 stage1 -rw-r--r-- 1 root root 109212 2008-05-28 12:05 stage2 -rw-r--r-- 1 root root 109212 2008-05-28 12:05 stage2_eltorito [root@pinguino i386-redhat]# dd if=stage1 of=/dev/fd0 bs=512 count=1 1+0 records in 1+0 records out 512 bytes (512 B) copied, 0.29007 s, 1.8 kB/s [root@pinguino i386-redhat]# dd if=stage2 of=/dev/fd0 bs=512 seek=1 213+1 records in 213+1 records out 109212 bytes (109 kB) copied, 7.4094 s, 14.7 kB/s [root@lyrebird root]# ls /usr/share/grub i386-redhat [root@lyrebird root]# cd /usr/share/grub/i386-redhat [root@lyrebird i386-redhat]# ls -l st* -rw-r--r-- 1 root root 512 Aug 3 2004 stage1 -rw-r--r-- 1 root root 104092 Aug 3 2004 stage2 [root@lyrebird i386-redhat]# dd if=stage1 of=/dev/fd0 bs=512 count=1 1+0 records in 1+0 records out [root@lyrebird i386-redhat]# dd if=stage2 of=/dev/fd0 bs=512 seek=1 203+1 records in 203+1 records out
创建一个 GRUB 可引导 CD 映像
[ian@pinguino ~]$ mkdir -p grubcd/boot/grub [ian@pinguino ~]$ cp /usr/share/grub/i386-redhat/stage2_eltorito grubcd/boot/grub [ian@pinguino ~]$ genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot \ > -boot-load-size 4 -boot-info-table -o grubcd.iso grubcd I: -input-charset not specified, using utf-8 (detected in locale settings) Size of boot image is 4 sectors -> No emulation Total translation table size: 2048 Total rockridge attributes bytes: 760 Total directory bytes: 4576 Path table size(bytes): 34 Max brk space used 0 233 extents written (0 MB)
在包含一个文件系统的软盘上安装 GRUB
[root@pinguino ~]# mkdosfs -R 220 /dev/fd0 mkdosfs 2.11 (12 Mar 2005) [root@pinguino ~]# mkdir /mnt/floppy [root@pinguino ~]# mount /dev/fd0 /mnt/floppy [root@pinguino ~]# mkdir -p /mnt/floppy/boot/grub [root@pinguino ~]# cp /boot/grub/stage1 /mnt/floppy/boot/grub [root@pinguino ~]# cp /boot/grub/stage2 /mnt/floppy/boot/grub [root@pinguino ~]# cp /boot/grub/splash* /mnt/floppy/boot/grub [root@pinguino ~]# cp /boot/grub/grub.conf /mnt/floppy/boot/grub [root@pinguino ~]# umount /dev/fd0 [root@pinguino ~]# grub Probing devices to guess BIOS drives. This may take a long time. GNU GRUB version 0.97 (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 (fd0) Filesystem type is fat, using whole disk grub> setup (fd0) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/fat_stage1_5" exists... no Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/grub.c onf "... succeeded Done.
LILO
LILO 配置文件默认为 /etc/lilo.conf。清单 1 展示了一个系统示例,该系统当前正在 /dev/sda10 上运行 Slackware,在 /dev/sda1 上运行 Windows,在 /dev/sdb12 上运行 Fedora 14。这个示例使用 /sbin/liloconfig 命令构建。
清单 1. LILO 配置示例
# LILO configuration file # generated by 'liloconfig' # # Start LILO global section lba32 # Allow booting past 1024th cylinder with a recent BIOS boot = /dev/root #compact # faster, but won't work on all systems. # Boot BMP Image. # Bitmap in BMP format: 640x480x8 bitmap = /boot/slack.bmp # Menu colors (foreground, background, shadow, highlighted # foreground, highlighted background, highlighted shadow): bmp-colors = 255,0,255,0,255,0 # Location of the option table: location x, location y, number of # columns, lines per column (max 15), "spill" (this is how many # entries must be in the first column before the next begins to # be used. We don't specify it here, as there's just one column. bmp-table = 60,6,1,16 # Timer location x, timer location y, foreground color, # background color, shadow color. bmp-timer = 65,27,0,255 # Standard menu. # Or, you can comment out the bitmap menu above and # use a boot message with the standard menu: #message = /boot/boot_message.txt # Append any additional kernel parameters: append=" vt.default_utf8=0" prompt timeout = 300 # Normal VGA console vga = normal # VESA framebuffer console @ 1024x768x64k # vga=791 # VESA framebuffer console @ 1024x768x32k # vga=790 # VESA framebuffer console @ 1024x768x256 # vga=773 # VESA framebuffer console @ 800x600x64k # vga=788 # VESA framebuffer console @ 800x600x32k # vga=787 # VESA framebuffer console @ 800x600x256 # vga=771 # VESA framebuffer console @ 640x480x64k # vga=785 # VESA framebuffer console @ 640x480x32k # vga=784 # VESA framebuffer console @ 640x480x256 # vga=769 # ramdisk = 0 # paranoia setting # End LILO global section # Linux bootable partition config begins image = /boot/vmlinuz root = /dev/sda10 label = Slackware13 read-only # Partitions should be mounted read-only for checking # Linux bootable partition config ends # Windows bootable partition config begins other = /dev/sda1 label = Windows table = /dev/sda # Windows bootable partition config ends # Linux bootable partition config begins image = /boot/vmlinuz root = /dev/sdb13 label = Fedora14 read-only # Partitions should be mounted read-only for checking # Linux bootable partition config ends
清单 1 中的配置文件包含一个位图参数,参数值为 /boot/slack.bmp。这是一个位图图像,将用于代替传统的 LILO 文本提示,如 图 2 所示。默认的引导图像 Slackware13 为突出显示
lilo 命令
记住,每当更改 /etc/lilo.conf 或者安装新内核时,都必须运行
lilo。
lilo程序会重写 MBR 或分区引导记录以反映您的更改,包括记录内核的绝对磁盘路径。如果您的配置文件包含来自多个分区的 Linux 映像,那么必须加载那些分区,这是因为
lilo命令需要访问分区才能定位映像。
除显示 LILO 配置文件外,可以使用
lilo命令的
-q选项来显示关于 LILO 启动选项的信息。添加
-v选项以获得更详细的输出。清单 3 展示了两个示例,一个是使用 清单 1 中的图形配置文件,另一个是使用 图 4 中的文本配置文件。
清单 3. 显示 LILO 配置
root@echidna:~# lilo -q -C /etc/lilo-graphic.conf Slackware13 * Windows Fedora14 root@echidna:~# lilo -q -v -C /etc/lilo-text.conf LILO version 22.8, Copyright (C) 1992-1998 Werner Almesberger Development beyond version 21 Copyright (C) 1999-2006 John Coffman Released 19-Feb-2007 and compiled at 20:09:28 on Feb 14 2010 Reading boot sector from /dev/root Installed: Tue Sep 6 15:51:49 2011 Global settings: Delay before booting: 0.0 seconds Command-line timeout: 30.0 seconds No unattended booting No PC/AT keyboard hardware presence check Always enter boot prompt Boot-time BIOS data saved Boot-time BIOS data auto-suppress write bypassed Large memory (>15M) is NOT used to load initial ramdisk Non-RAID installation Boot device will not be used for the Map file Serial line access is disabled Boot prompt message is 1083 bytes No default boot command line Images: Slackware13 * No password Boot command-line won't be locked No single-key activation VGA mode: NORMAL Kernel is loaded "high" No initial RAM disk No fallback Options: "ro root=80a vt.default_utf8=0" Windows No password Boot command-line won't be locked No single-key activation No fallback No options Fedora14 No password Boot command-line won't be locked No single-key activation VGA mode: NORMAL Kernel is loaded "high" No initial RAM disk No fallback Options: "ro root=81d vt.default_utf8=0"
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 (hd1,12) # kernel /boot/vmlinuz-version ro root=/dev/sdb13 # initrd /boot/initrd-[generic-]version.img #boot=/dev/sdb13 default=0 timeout=5 splashimage=(hd1,12)/boot/grub/splash.xpm.gz hiddenmenu title Fedora (2.6.35.14-95.fc14.x86_64) root (hd1,12) kernel /boot/vmlinuz-2.6.35.14-95.fc14.x86_64 ro root=UUID=5e22a2e0-5ac2-47d5-b98a-d5b25eff585a rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet initrd /boot/initramfs-2.6.35.14-95.fc14.x86_64.img title Fedora (2.6.35.13-92.fc14.x86_64) root (hd1,12) kernel /boot/vmlinuz-2.6.35.13-92.fc14.x86_64 ro root=UUID=5e22a2e0-5ac2-47d5-b98a-d5b25eff585a rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet initrd /boot/initramfs-2.6.35.13-92.fc14.x86_64.img title Fedora (2.6.35.13-91.fc14.x86_64) root (hd1,12) kernel /boot/vmlinuz-2.6.35.13-91.fc14.x86_64 ro root=UUID=5e22a2e0-5ac2-47d5-b98a-d5b25eff585a rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet initrd /boot/initramfs-2.6.35.13-91.fc14.x86_64.img title GRUB rootnoverify (hd0,1) chainloader +1 title Slackware 13 rootnoverify (hd0,9) chainloader +1 title Windows rootnoverify (hd0,0) chainloader +1 |
要为分区配置一个启动条目,GRUB 不需要装载该分区。您将看到
root (hd0,9)和
splashimage=(hd1,12)/boot/grub/splash.xpm.gz这样的条目。GRUB 将您的硬盘引用为 hdn,其中
n 是一个整数,从 0 开始。类似地,磁盘上的分区从 0 开始编号。注意:GRUB2 已经更改了磁盘命名方式,因此在 GRUB 和 GRUB2 之间切换时要小心。
因此,在这个系统上,(hd0,0) 代表 Windows 主分区 /dev/sda1,而 (hd0,9) 代表 Slackware 逻辑分区 /dev/sda10。软盘驱动器通常是 (fd0)。如果使用这些参数从一个 bash shell 调用 GRUB,例如,在软盘、USB 密匙或您的 MBR 上安装 GRUB 时,别忘了使用引号将参数引起来。
相关文章推荐
- libgdx示例-SuperJumper分析 1. 程序入口与初始化资源,加载配置信息
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB[ZT]
- linux启动引导程序lilo与grub区别
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB
- Eclipse中使用Hadoop伪分布模式开发配置及简单程序示例(Linux下)
- 【Linux】启动引导程序--grub及其配置文件
- 如何配置Ubuntu 16.04 GRUB 2引导加载程序
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB
- 如何配置Ubuntu 16.04 GRUB 2引导加载程序
- 引导加载程序之争:了解 LILO 和 GRUB
- 引导加载程序之争:了解 LILO 和 GRUB