Getting Started with the Linux Kernel
- Obtaining the Kernel Source
- The Kernel Source Tree
- Building the Kernel
- A Beast of a Different Nature
- Conclusion
尽管在许多wa内核肯定是独一无二的ys, at the end of the day it is little different from any other large software project.
Obtaining the Kernel Source
The current Linux source code is always available in both a completetarball(an archive created with thetarcommand) 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, youalwayswant the latest code. The repository atkernel.orgis the place to get it, along with additional patches from a number of leading kernel developers.
Using Git
Over the last couple of years, the kernel hackers, led by Linus himself, have begun using a new version control system to manage the Linux kernel source. Linus created this system, calledGit, with speed in mind. Unlike traditional systems such asCVSGit是分布式,其用法和工作流is consequently unfamiliar to many developers. I strongly recommend using Git to download and manage the Linux kernel source.
You can use Git to obtain a copy of the latest "pushed" version of Linus's tree:
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
When checked out, you can update your tree to Linus's latest:
$ git pull
使用这两个命令,您可以获得和subsequently keep up to date with the official kernel tree. To commit and manage your own changes, see Chapter 20, "Patches, Hacking, and the Community." A complete discussion of Git is outside the scope of this book; many online resources provide excellent guides.
Installing the Kernel Source
The kernel tarball is distributed in both GNU zip (gzip) and bzip2 format. Bzip2 is the default and preferred format because it generally compresses quite a bit better than gzip. The Linux kernel tarball in bzip2 format is namedlinux-x.y.z.tar.bz2, wherex.y.zis the version of that particular release 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.bz2
If it is compressed with GNU zip, run
$ tar xvzf linux-x.y.z.tar.gz
This uncompresses and untars the source to the directorylinux-x.y.z. If you use git to obtain and manage the kernel source, you do not need to download the tarball. Just run thegit clonecommand as described and git downloads and unpacks the latest source.
Using Patches
Throughout the Linux kernel community, patches are thelingua francaof communication. You will distribute your code changes in patches and receive code from others as patches.Incremental patchesprovide an easy way to move from one kernel tree to the next. 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, frominsideyour kernel source tree, simply run
$ patch –p1 < ../patch-x.y.z
Generally, 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.