📄 grub.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=gb2312" />
<title>
8.4. Making the LFS System Bootable
</title>
<link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1" />
<link rel="stylesheet" href="../stylesheets/lfs-print.css" type="text/css" media="print" />
</head>
<body id="lfs" class="6.1">
<div class="navheader">
<div class="headertitles">
<h4>
Linux From Scratch - Version 6.1
</h4>
<h3>
Chapter 8. 引导 LFS 系统
</h3>
</div>
<ul class="headerlinks">
<li class="prev">
<a accesskey="p" href="kernel.html" title="Linux-2.6.11.12">后退</a>
<p>
Linux-2.6.11.12
</p>
</li>
<li class="next">
<a accesskey="n" href="../chapter09/chapter09.html" title="The End">前进</a>
<p>
The End
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter08.html" title="Chapter 8. 引导 LFS 系统">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>
</li>
</ul>
</div>
<div class="sect1" lang="zh_cn" xml:lang="zh_cn">
<div class="titlepage">
<h1 class="sect1">
8.4. 使 LFS 系统可以启动</h1>
</div>
<p>您全新的 LFS 系统差不多要完成了,最后要做的事情是确保系统可以正确的启动。下面的指令仅适用于 IA-32 架构的计算机,就是主流的 PC 机。关于其它架构计算机“boot loading”(引导装载)的信息可以在相应的资源里找到。</p>
<p>引导装载是很复杂的,因此下面有几个警告。您需要熟悉当前的引导装载程序,以及硬盘上需要引导的其它操作系统。准备一张紧急启动盘,以便在计算机不可用(无法启动)的时候修复它。</p>
<p>先前我们编译安装了 Grub 引导装载程序,是为了现在这一步做准备,接下来的步骤要在硬盘的特殊位置写入一些特殊的 Grub 文件。我们强烈推荐您创建一张 Grub 引导软盘作为备份,插入一张空白软盘并输入下面的命令:</p>
<pre class="userinput"><kbd class="command">dd if=/boot/grub/stage1 of=/dev/fd0 bs=512 count=1
dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1</kbd></pre>
<p>
取出软盘放在安全的地方,现在运行
<span><strong class="command">grub</strong></span> shell : </p>
<pre class="userinput"><kbd class="command">grub</kbd></pre>
<p>
Grub 有自己的驱动器和分区命名结构,形式是 <span class="emphasis"><em>(hdn,m)</em></span>,这里
<span class="emphasis"><em>n</em></span> 是硬盘驱动器号,
<span class="emphasis"><em>m</em></span> 是分区号,两个数字都从零开始。例如,<tt class="filename">hda1</tt> 分区对 Grub 是 <span class="emphasis"><em>(hd0,0)</em></span> ; <tt class="filename">hdb3</tt> 是 <span class="emphasis"><em>(hd1,2)</em></span>。与 Linux 不同,Grub 不把光盘驱动器作为硬盘驱动器。例如您的 <tt class="filename">hdb</tt> 是光盘驱动器,第二个硬盘驱动器是
<tt class="filename">hdc</tt>,对于 Grub 来说,第二个硬盘驱动器仍然是
<span class="emphasis"><em>(hd1)</em></span> </p>
<p>
用上面的信息为根分区(或是 boot 分区,如果您使用了单独的 boot 分区的话)确定正确的标志符,下面的例子里假定根分区(或单独的 boot 分区)是 <tt class="filename">hda4</tt> </p>
<p>
告诉 Grub 在哪里搜索它的 <tt class="filename">stage{1,2}</tt>文件。您也可以在任何地方使用 Tab 键让 Grub 显示可选择的项:</p>
<pre class="userinput"><kbd class="command">root (hd0,3)</kbd></pre>
<div class="warning">
<div class="admonhead">
<img alt="[Warning]" src="../images/warning.png" />
<h3 class="admontitle">
警告 </h3>
</div>
<div class="admonbody">
<p>
下一个命令会覆盖当前的引导装载程序,如果不需要的话就不要运行这个命令,例如在用第三方引导管理器管理 MBR(Master Boot Record 主引导记录)的时候,这种情况下,把 Grub 安装到 LFS 分区的“引导扇区”可能更有意义,这时下一个命令就要变成
<strong class="userinput"><tt>setup (hd0,3)</tt></strong> </p>
</div>
</div>
<p>
把 Grub 安装到 <tt class="filename">hda</tt> 的 MBR 里:</p>
<pre class="userinput"><kbd class="command">setup (hd0)</kbd></pre>
<p>
如果一切正常,Grub 会报告在
<tt class="filename">/boot/grub</tt> 里找到了它的文件。这里要做的事情就是这个,退出 <span><strong class="command">grub</strong></span> shell : </p>
<pre class="userinput"><kbd class="command">quit</kbd></pre>
<p>创建一个“menu list”文件来定义 Grub 的启动菜单:</p>
<pre class="userinput"><kbd class="command">cat > /boot/grub/menu.lst << "EOF"
<tt class="literal"># Begin /boot/grub/menu.lst
# By default boot the first menu entry.
default 0
# Allow 30 seconds before booting the default.
timeout 30
# Use prettier colors.
color green/black light-green/black
# The first entry is for LFS.
title LFS 6.1
root (hd0,3)
kernel /boot/lfskernel-2.6.11.12 root=/dev/hda4</tt>
EOF</kbd></pre>
<p>如果需要的话,为宿主系统添加一项,它看起来可能是这样的:</p>
<pre class="userinput"><kbd class="command">cat >> /boot/grub/menu.lst << "EOF"
<tt class="literal">title Red Hat
root (hd0,2)
kernel /boot/kernel-2.6.5 root=/dev/hda3
initrd /boot/initrd-2.6.5</tt>
EOF</kbd></pre>
<p>如果要引导 Windows,下面的项可以引导 Windows:</p>
<pre class="userinput"><kbd class="command">cat >> /boot/grub/menu.lst << "EOF"
<tt class="literal">title Windows
rootnoverify (hd0,0)
chainloader +1</tt>
EOF</kbd></pre>
<p>
如果 <span><strong class="command">info grub</strong></span> 没有提供所有必须的资料,关于 Grub 的更多信息可以在它的网站上找到: <a href="http://www.gnu.org/software/grub/"><i>http://www.gnu.org/software/grub/</i></a> </p>
<p>
FHS 规定 GRUB 的 <tt class="filename">menu.lst</tt>
文件应当链接到 <tt class="filename">/etc/grub/menu.lst</tt> ,为了符合标准,请运行下列命令:</p>
<pre class="userinput"><kbd class="command">mkdir /etc/grub &&
ln -s /boot/grub/menu.lst /etc/grub</kbd></pre>
</div>
<div class="navfooter">
<ul>
<li class="prev">
<a accesskey="p" href="kernel.html" title="Linux-2.6.11.12">后退</a>
<p>
Linux-2.6.11.12
</p>
</li>
<li class="next">
<a accesskey="n" href="../chapter09/chapter09.html" title="The End">前进</a>
<p>
The End
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter08.html" title="Chapter 8. 引导 LFS 系统">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>.
</li>
</ul>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -