linux内核设计与实现 第二章.doc

上传人:壹****1 文档编号:548208759 上传时间:2024-02-22 格式:DOC 页数:13 大小:115.01KB
返回 下载 相关 举报
linux内核设计与实现 第二章.doc_第1页
第1页 / 共13页
linux内核设计与实现 第二章.doc_第2页
第2页 / 共13页
linux内核设计与实现 第二章.doc_第3页
第3页 / 共13页
linux内核设计与实现 第二章.doc_第4页
第4页 / 共13页
linux内核设计与实现 第二章.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《linux内核设计与实现 第二章.doc》由会员分享,可在线阅读,更多相关《linux内核设计与实现 第二章.doc(13页珍藏版)》请在金锄头文库上搜索。

1、Chapter 2. Getting Started with the KernelIn this chapter, we introduce some of the Basics of the Linux kernel: where to get its source, how to compile it, and how to install the new kernel. We then go over some kernel assumptions, differences between the kernel and user-space programs, and common m

2、ethods used in the kernel.The kernel has some intriguing differences over other beasts, but certainly nothing that cannot be tamed. Lets tackle it.第二章 从内核出发在这一章,我们介绍Linux内核一些基本常识:从何处获取源码,如何编译它,又如何安装新内核。那么,让我们考察一下内核的一些状态、内核程序与用户空间程序的差异,以及内核所用一般函数的特点。 内核像性格怪异的猛兽,但并非不可驯服。让我们来驾驭它。Obtaining the Kernel So

3、urceThe current Linux source code is always available in both a complete tarball and an incremental patch from the official home of the Linux kernel, http:/www.kernel.org.Unless you have a specific reason to work with an older version of the Linux source, you always want the latest code. The reposit

4、ory at kernel.org is the place to get it, along with additional patches from a number of leading kernel developers.2.1获取内核源码在Linux内核官方网站http:/www.kernel.org,可以随时获取当前版本的Linux源代码,可以是完整的压缩形式,也可以是增量补丁形式。除非特殊情况下需要Linux源码的旧版本,一般都希望拥有最新的代码。kernel.org是源码的库存之处,那些领导潮流的内核开发者所发布的增量补丁也放在这里。Installing the Kernel

5、SourceThe kernel tarball is distributed in both GNU zip (gzip) and bzip2 format. Bzip2 is the default and preferred format, as it generally compresses quite a bit better than gzip. The Linux kernel tarball in bzip2 format is named linux-x.y.z.tar.bz2, where x.y.z is the version of that particular re

6、lease of the kernel source. After downloading the source, uncompressing and untarring it is simple. If your tarball is compressed with bzip2, run$ tar xvjf linux-x.y.z.tar.bz2If it is compressed with GNU zip, run$ tar xvzf linux-x.y.z.tar.gzThis uncompresses and untars the source to the directory li

7、nux-x.y.z.2.1.1安装内核源代码 内核压缩以GNU zip(gzip)和bzip2两种形式发布。bzip2是缺省和首选形式,因为它在压缩上比gzip有相当的优势。以bzip2形式发布的Linux内核叫做linux-x.y.z.tar.bz2,这里x.y.z是内核源码的具体版本。下载了源代码之后,就可以轻而易举地对其解压。如果压缩形式是bzip2,则运行:$ tar xvjf linux-x.y.z.tar.bz2如果压缩形式是GNU的zip,则运行$ tar xvzf linux-x.y.z.tar.gz解压后的源代码位于linux-x.y.z.目录下。何处安装源码内核源码一般安装

8、在/usr/src/linux目录下。但请注意,不要把这个源码树用于开发。相反,编译你的C库所用的内核版本就链接到这颗树。此外,不要以root身份对内核进行修改,而应当是,建立自己的主目录,仅以root身份安装新内核。即使在安装新内核时,/usr/src/linux目录都应当原封不动。 Where to Install and Hack on the SourceThe kernel source is typically installed in/usr/src/linux. Note that you should not use this source tree for developm

9、ent. The kernel version that your C library is compiled against is often linked to this tree. Besides, you do not want to have to be root to make changes to the kernelinstead, work out of your home directory and use root only to install new kernels. Even when installing a new kernel, /usr/src/linux

10、should remain untouched.2.2 2 使用补丁在Linux内核社区中,补丁是通用语。你可以以补丁的形式发布对代码的修改,也可以以补丁的形式接收其他人所做的修改。时间流失,内核版本在不断更新,增量补丁可以作为版本转移的桥梁。你不再需要下载内核源码的全部压缩,而只需给旧版本打上一个增量补丁,让其旧貌换新颜。这不仅节约了带宽,还省了时间。要应用增量补丁,从你的内部源码树开始,只是运行:$ patch p1 ./patch-x.y.z一般说来,一个给定版本的内核补丁总是打在前一个版本上。有关产生和应用补丁更深入的讨论会在后续章节进行。Using PatchesThroughout

11、 the Linux kernel community, patches are the lingua franca of communication. You will distribute your code changes in patches as well as receive code from others as patches. More relevant to the moment is the incremental patches that are provided to move from one version of the kernel source to anot

12、her. Instead of downloading each large tarball of the kernel source, you can simply apply an incremental patch to go from one version to the next. This saves everyone bandwidth and you time. To apply an incremental patch, from inside your kernel source tree, simply run$ patch p1 ./patch-x.y.zGeneral

13、ly, a patch to a given version of the kernel is applied against the previous version.Generating and applying patches is discussed in much more depth in later chapters. 2.2 内核源码树内核源码树由很多目录组成,而大多数目录又包含更多的子目录。源码树的根目录及其子目录如表2.1所示表2.1 内核源码树的根目录描述目录描述arch特定体系结构的源码cryptoCrypto APIDocumentation内核源码文档drivers

14、设备驱动程序fsVFS和各种文件系统include内核头文件init内核引导和初始化ipc进程间通信代码kernel像调度程序这样的核心子系统lib通用内核函数mm内存管理子系统和VMnet网络子系统scripts编译内核所用的脚本securityLinux安全模块sound语音子系统usr早期用户空间代码 (所谓的 initramfs)在源码树根目录中的很多文件值得提及。COPYING文件是内核许可证(GNU GPL v2)。CREDITS是开发者列表,其中还有不少内核代码的细节。MAINTAINERS是维护者列表,他们维护内核子系统和驱动程序。最后, Makefile是基本内核的Makef

15、ile。 The Kernel Source TreeThe kernel source tree is divided into a number of directories, most of which contain many more subdirectories. The directories in the root of the source tree, along with their descriptions, are listed in Table 2.1.Table 2.1. Directories in the Root of the Kernel Source TreeDirectoryDescriptionarchArchitecture-specific sourcecryptoCrypto APIDocumentationKernel source documentationdriversDevice driversfsThe VFS and the individual file systemsincludeKernel headersinitKernel boot and initializationipcInterprocess communication codekernelCore su

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号