Merge pull request #2451 from martin2011qi/master

translated
This commit is contained in:
Xingyu.Wang 2015-03-01 20:58:07 +08:00
commit 3bbfbeeb23
2 changed files with 58 additions and 60 deletions

View File

@ -1,60 +0,0 @@
translating by martin.
Linux FAQs with Answers--How to install full kernel source on Debian or Ubuntu
================================================================================
> **Question**: I need to download and install a full kernel source tree to compile a custom kernel for my Debian or Ubuntu system. What is a proper way to download full kernel source on Debian or Ubuntu?
Before installing full kernel source on your Linux system, ask yourself whether you really need the full kernel source. If you are trying to compile a kernel module or a custom driver for your kernel, you do not need the full kernel source. You only need to install [matching kernel header files][1], and that's it.
You need the full kernel source tree only if you want to build a custom kernel after modifying the kernel code in any way and/or tweaking default kernel options.
Here is how to **download and install full kernel source tree from Debian or Ubuntu repositories**. While you can download the official kernel source code from [https://www.kernel.org/pub/linux/kernel/][2], using distro's repositories allows you to download a kernel source with the maintainer's patches applied to it.
### Install Full Kernel Source on Debian ###
Before downloading kernel source, install dpkg-dev, which contains a suite of development tools needed to build Debian source packages. Among other things, dpkg-dev contains dpgk-source tool which can extract a Debian source package and automatically apply patches.
$ sudo apt-get install dpkg-dev
Next, run the following command to download full kernel source.
$ apt-get source linux-image-$(uname -r)
Along with the full kernel source (linux_X.X.XX.orig.tar.xz), any available kernel patches (linux_X.X.X+XXX.debian.tar.xz) and source control file (linux_XXXX.dsc) will also be downloaded and stored in the current directory. The .dsc file instructs how the patches are applied to the kernel sources.
Upon the completion of download, the above command will automatically invoke dpkg-source tool, which will unpack the downloaded kernel source in the current directory, and apply downloaded patches according to .dsc file.
The final full kernel source tree will be available in the current directory as "linux-X.X.XX".
![](https://farm9.staticflickr.com/8676/16341110300_b4f059eeb0_b.jpg)
### Install Full Kernel Source on Ubuntu ###
If you want to install full kernel source, the Debian way described above should work on Ubuntu as well.
There is another way to download full kernel source on Ubuntu. You can actually check out the kernel source tree maintained by Canonical for different Ubuntu releases.
$ sudo apt-get install git
$ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-$(lsb_release --codename | cut -f2).git
For example, if you are using Ubuntu 14.04, the above command will check out code from "ubuntu-trusty" Git repository.
![](https://farm9.staticflickr.com/8642/16526856391_de636ff9b8_c.jpg)
Once you check out the Git repository, use the following command to install necessary development packages to meet the build dependencies for the kernel source tree.
$ sudo apt-get build-dep linux-image-$(uname -r)
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/install-full-kernel-source-debian-ubuntu.html
作者:[Dan Nanni][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://ask.xmodulo.com/author/nanni
[1]:http://ask.xmodulo.com/install-kernel-headers-linux.html
[2]:https://www.kernel.org/pub/linux/kernel/

View File

@ -0,0 +1,58 @@
Linux有问必答如何在Debian或Ubuntu上安装完整的内核源码
================================================================================
> **问题**:我需要为我的Debian或Ubuntu下载并安装完整树结构的内核源码以供编译一个定制的内核。那么在Debian或Ubuntu上有什么可行的方法来下载完整的内核源码呢
在给你的Linux安装完整内核源码之前先问问自己是否真的需要这样做。如果你仅仅是尝试去编译一个内核模块或是为内核定制驱动你并不需要完整的内核源码树。你只需要安装[一些与内核对应的头文件][1],这样就足够了。
只有在你需要生成一个定制的内核,而且内核源码中的一些内核默认设置要被你调整了的情况下,你才需要完整的内核源码树。
这里将会解答如何**在Debian或Ubuntu的库中下载并安装完整树结构的内核源码**。虽然你可以在这个网站[https://www.kernel.org/pub/linux/kernel/][2]下载官方的内核源码,但是发行版软件仓库可以允许你下载包含补丁的内核源码。
### 在Debian上安装完整的内核源码 ###
在下载内核源码之前先安装dpkg-dev其中包含你在Debian上生成源代码时需要的开发工具套件。不仅如此dpkg-dev中还包含在用来解压Debian源码包并自动打补丁的工具dpgk-source。
$ sudo apt-get install dpkg-dev
然后,运行以下命令下载完整的内核源码。
$ apt-get source linux-image-$(uname -r)
伴随着完整内核源码linux_X.X.XX.orig.tar.xz的还有一些可用的内核补丁linux_X.X.X+XXX.debian.tar.xz和源码控制文件linux_XXXX.dsc这些都将被下载并存储到当前目录。在.dsc文件中会指出如何给内核源码打补丁。
当下载完成以上的命令将会自动调用工具dpkg-source将下载的内核源码解压到当前的目录中与此同时更具.dsc文件来下补丁。
最终完整的内核源码树将会以"linux-X.X.XX"的形式呈现在当前目录中。
![](https://farm9.staticflickr.com/8676/16341110300_b4f059eeb0_b.jpg)
### 在Ubuntu上安装完整内核源码 ###
如果你想安装完整内核源码的话以上在Debian上的那一套做法在Ubuntu上仍然奏效。
在Ubuntu上还有另一套方法安装完整内核源码。事实上你可以查一下由Canonical为Ubuntu不同发行版维护的内核源码树。
$ sudo apt-get install git
$ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-$(lsb_release --codename | cut -f2).git
举个例子如果你使用的是Ubuntu14.04以上的命令将会查看Git的"ubuntu-trusty"仓库中的代码。
![](https://farm9.staticflickr.com/8642/16526856391_de636ff9b8_c.jpg)
一旦在你对Git仓库的查询结束后使用以下的命令来安装用来访问生成内核源码树所需依赖的重要开发包。
$ sudo apt-get build-dep linux-image-$(uname -r)
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/install-full-kernel-source-debian-ubuntu.html
作者:[Dan Nanni][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://ask.xmodulo.com/author/nanni
[1]:http://ask.xmodulo.com/install-kernel-headers-linux.html
[2]:https://www.kernel.org/pub/linux/kernel/