📄 kernel.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.3. Linux-2.6.11.12
</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="fstab.html" title="Creating the /etc/fstab File">后退</a>
<p>
Creating the /etc/fstab File
</p>
</li>
<li class="next">
<a accesskey="n" href="grub.html" title="Making the LFS System Bootable">前进</a>
<p>
Making the LFS System Bootable
</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="wrap" lang="zh_cn" xml:lang="zh_cn">
<div class="titlepage">
<h1 class="sect1">
8.3. Linux-2.6.11.12
</h1>
</div>
<div class="package" lang="zh_cn" xml:lang="zh_cn">
<p>Linux 内核软件包包含内核源代码及其头文件。</p>
<div class="segmentedlist">
<div class="seglistitem">
<div class="seg">
<strong><span class="segtitle">预计编译时间:</span></strong> <span class="seg">4.20 SBU</span>
</div>
<div class="seg">
<strong><span class="segtitle">所需磁盘空间:</span></strong> <span class="seg">181 MB</span>
</div>
</div>
</div>
<div class="segmentedlist">
<div class="seglistitem">
<div class="seg">
<strong><span class="segtitle">安装依赖于:</span></strong> <span class="seg">Bash, Binutils, Coreutils, Findutils, GCC, Glibc, Grep, Gzip, Make, Modutils, Perl, Sed</span>
</div>
</div>
</div>
</div>
<div class="installation" lang="zh_cn" xml:lang="zh_cn">
<div class="titlepage">
<h2 class="sect2">
8.3.1. 安装 the kernel
</h2>
</div>
<p>
编译内核包含几个步骤(配置、编译和安装)请阅读内核源码树里的 <tt class="filename">README</tt> 文件,选择不同于本书的其它配置内核的方式。</p>
<p>运行下面的命令做编译前的准备:</p>
<pre class="userinput"><kbd class="command">make mrproper</kbd></pre>
<p>这样可以确保内核源码树是绝对干净的,内核开发组推荐每次编译内核之前都先运行这个命令。请不要以为解包后内核源码树自动就是干净的。</p>
<p>
如果在 <a href="../chapter07/console.html" title="7.6. Configuring the Linux Console">Section 7.6, “Configuring the Linux Console, ”</a> 中决定了要把键盘映射表编入内核,请运行下面的命令:</p>
<pre class="userinput"><kbd class="command">loadkeys -m /usr/share/kbd/keymaps/<em class="replaceable"><tt>[path to keymap]</tt></em> > \
drivers/char/defkeymap.c</kbd></pre>
<p>
例如,如果您使用荷兰语键盘,请使用 <tt class="filename">/usr/share/kbd/keymaps/i386/qwerty/nl.map.gz</tt> </p>
<p>
通过菜单界面配置内核。BLFS 有一些关于 LFS 之外的一些软件包的特别的内核配置需求<a href="http://www.linuxfromscratch.org/blfs/view/svn/longindex.html#kernel-config-index">
<i>http://www.linuxfromscratch.org/blfs/view/svn/longindex.html#kernel-config-index</i></a>: </p>
<pre class="userinput"><kbd class="command">make menuconfig</kbd></pre>
<p>
另外,在某些情况下 <span><strong class="command">make
oldconfig</strong></span> 可能是更恰当的,请参考 <tt class="filename">README</tt> 以获得更多信息。</p>
<p>
如果您愿意,可以跳过配置内核的步骤,直接把宿主系统里的内核配置文件 <tt class="filename">.config</tt>(如果存在的话)复制到解压后的 <tt class="filename">linux-2.6.11.12</tt> 目录下。当然,我们不推荐这样做,考察全部的配置菜单并从头开始创建内核配置是更好的办法。</p>
<div class="note">
<div class="admonhead">
<img alt="[Note]" src="../images/note.png" />
<h3 class="admontitle">
注意 </h3>
</div>
<div class="admonbody">
<p>
NPTL 的支持要求内核使用 GCC-3.x 及以上的版本编译,在这本书里是GCC-3.4.3。不推荐使用
GCC-2.95.x,因为它会导致 Glibc 测试套件失败并且在LFS Book中不会提及这样的失败,因为 LFS 不是用
GCC-2.95.x 创建的。很不幸,内核文档相当陈旧,还在建议使用 GCC-2.95.3 作为编译器。</p>
</div>
</div>
<p>编译内核镜像和模块:</p>
<pre class="userinput"><kbd class="command">make</kbd></pre>
<p>
如果使用内核模块,需要 <tt class="filename">/etc/modprobe.conf</tt> 文件。关于模块和内核配置的信息请参考 <tt class="filename">linux-2.6.11.12/Documentation</tt> 目录下的内核文档,<tt class="filename">modprobe.conf(5)</tt>也是有用的。</p>
<p>
阅读其它文档的时候请小心,因为它们通常只适用于 2.4.x 版本的内核。据我们所知,关于 Hotplug 和 Udev 的内核配置问题还没有文档说明。这个问题是这样的:如果 Hotplug 或用户写的脚本把模块插入内核,Udev 只创建了一个设备节点,而且不是所有模块都可以被 Hotplug 检测到。请注意,<tt class="filename">/etc/modprobe.conf</tt> 文件里像下面这样的语句在 Udev 下是不起作用的:</p>
<pre class="screen">alias char-major-XXX some-module</pre>
<p>
因为 Hotplug、Udev 和模块的复杂性,我们强烈推荐您从完全非模块化的内核配置开始,特别是第一次使用 Udev 的时候。</p>
<p>如果内核配置了模块,就安装它们:</p>
<pre class="userinput"><kbd class="command">make modules_install</kbd></pre>
<p>
内核编译完之后,还需要一些步骤来完成安装,有些文件要复制到
<tt class="filename">/boot</tt> 目录里去。</p>
<p>内核镜像文件所在的路径根据您使用的平台不同而不同,x86平台上请运行下面的命令安装内核:</p>
<pre class="userinput"><kbd class="command">cp arch/i386/boot/bzImage /boot/lfskernel-2.6.11.12</kbd></pre>
<p>
<tt class="filename">System.map</tt> 是内核的符号文件,它映射了每个内核 API 函数的入口,以及运行中内核数据结构的地址。请运行下面的命令安装这个文件:</p>
<pre class="userinput"><kbd class="command">cp System.map /boot/System.map-2.6.11.12</kbd></pre>
<p>
上面 <span><strong class="command">make
menuconfig</strong></span> 这一步产生的内核配置文件 <tt class="filename">.config</tt>
包含了刚才编译的内核的全部配置选项,保留这个文件以备将来参考:</p>
<pre class="userinput"><kbd class="command">cp .config /boot/config-2.6.11.12</kbd></pre>
<p>
很重要的一点是要注意到内核源码目录里的文件所有者不是 <span class="emphasis"><em>root</em></span>。只要是用 <span class="emphasis"><em>root</em></span> 用户解压软件包(像我们在 chroot 环境里做的那样),解压出来的文件的用户和组 ID 是这个软件包打包者计算机上的用户和组 ID,对于其它软件包,这通常不是问题,因为安装完这些软件包之后源码目录就删除了,但是 Linux 内核源码树常常会保存很长的时间,这样就有可能打包者的用户 ID 和您计算机上某个用户的 ID 相同,从而让您计算机上的这个用户获得了内核源码的写权限。</p>
<p>
如果您准备保留内核源代码,在
<tt class="filename">linux-2.6.11.12</tt> 目录下运行
<span><strong class="command">chown -R 0:0</strong></span> 命令以确保全部文件的所有者是 <span class="emphasis"><em>root</em></span> </p>
<div class="warning">
<div class="admonhead">
<img alt="[Warning]" src="../images/warning.png" />
<h3 class="admontitle">
警告
</h3>
</div>
<div class="admonbody">
<p>
一些内核文档推荐创建一个从
<tt class="filename">/usr/src/linux</tt> 指向内核源代码目录的符号连接。这只是一个对 2.6
以前版本内核的特殊要求,并且在 LFS 系统上是 <span class="emphasis"><em>不允许</em></span> 这样做的,因为这样做会导致你的基本 LFS 系统安装好以后再安装别的软件包的时候导致问题。</p>
<p>
另外,系统 <tt class="filename">include</tt> 目录下的头文件应当 <span class="emphasis"><em>永远</em></span> 保持
Glibc 在编译时使用的那个版本,也就是
Linux-Libc-Headers 包中的那个版本。<span class="emphasis"><em>决不要</em></span> 使用内核包中的头文件。</p>
</div>
</div>
</div>
<div class="content" lang="zh_cn" xml:lang="zh_cn">
<div class="titlepage">
<a id="contents-kernel" name="contents-kernel"></a>
<h2 class="sect2">
8.3.2. Linux 内核的内容 </h2>
</div>
<div class="segmentedlist">
<div class="seglistitem">
<div class="seg">
<strong><span class="segtitle">安装的文件:</span></strong>
<span class="seg">config-2.6.11.12, lfskernel-2.6.11.12, System.map-2.6.11.12</span>
</div>
</div>
</div>
<div class="variablelist">
<h3>
<a id="id3342026" name="id3342026"></a>简要描述</h3>
<table border="0">
<col align="left" valign="top" />
<tbody>
<tr>
<td><a id="config" name="config"></a><span class="term"><tt class="filename">config-2.6.11.12</tt></span> </td>
<td><p> 内核配置选项。</p></td>
</tr>
<tr>
<td><a id="lfskernel" name="lfskernel"></a><span class="term"><tt class="filename">lfskernel-2.6.11.12</tt></span> </td>
<td><p>内核是 Linux 系统的引擎。启动计算机时,内核是操作系统首先装入的部分,它检测并初始化所有的硬件,然后将这些设备以文件树的形式存放使得其它软件可以访问,内核还使单个 CPU 成为拥有多任务处理能力的机器,可以同时运行许多程序。</p></td>
</tr>
<tr>
<td><a id="System.map" name="System.map"></a><span class="term"><tt class="filename">System.map-2.6.11.12</tt></span> </td>
<td><p>一个地址和符号的列表,映射了内核中所有函数和数据结构的入口和地址。</p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="navfooter">
<ul>
<li class="prev">
<a accesskey="p" href="fstab.html" title="Creating the /etc/fstab File">后退</a>
<p>
Creating the /etc/fstab File
</p>
</li>
<li class="next">
<a accesskey="n" href="grub.html" title="Making the LFS System Bootable">前进</a>
<p>
Making the LFS System Bootable
</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 + -