Merge pull request #2151 from geekpi/master

translated
This commit is contained in:
geekpi 2014-12-27 12:01:26 +08:00
commit 2eef77cedb
2 changed files with 74 additions and 74 deletions

View File

@ -1,74 +0,0 @@
Linux FAQs with Answers--How to install kernel headers on Linux
================================================================================
> **Question**: I need to install kernel headers to install a device driver for my kernel. What is a proper way to install matching kernel headers on [insert your Linux distro]?
When you compile a device driver a custom kernel module, you need to have kernel header files installed on your Linux system. Kernel headers are needed also when you build a userspace application which links directly against the kernel. When you install kernel headers in such cases, you must make sure to kernel headers are exactly matched with the kernel version of your system (e.g., 3.13.0-24-generic).
If your kernel is the default version that comes with the distribution, or you upgraded it using the default package manager (e.g., apt-get, aptitude or yum) from base repositories, you can install matching kernel headers using the package manager as well. On the other hand, if you downloaded the [kernel source][1] and compiled it manually, you can install matching kernel headers by using [make command][2].
Here we assume that your kernel comes from base repositories of your Linux distribution, and see how we can install matching kernel headers.
### Install Kernel Headers on Debian, Ubuntu or Linux Mint ###
Assuming that you did not manually compile the kernel, you can install matching kernel headers using apt-get command.
First, check if matching kernel headers are already available on your system using dpkg-query command.
$ dpkg-query -s linux-headers-$(uname -r)
----------
dpkg-query: package 'linux-headers-3.11.0-26-generic' is not installed and no information is available
Go ahead and install matching kernel headers as follows.
$ sudo apt-get install linux-headers-$(uname -r)
![](https://farm9.staticflickr.com/8681/16000652415_a7c399992e_z.jpg)
Verify that matching kernel headers are successfully installed.
$ dpkg-query -s linux-headers-$(uname -r)
----------
Package: linux-headers-3.11.0-26-generic
Status: install ok installed
The default location of kernel headers on Debian, Ubuntu or Linux Mint is **/usr/src**.
### Install Kernel Headers on Fedora, CentOS or RHEL ###
If you did not manually upgrade the kernel, you can install matching kernel headers using yum command.
First, check if matching kernel headers are already installed on your system. If the following command does not produce any output, it means kernel headers are not available.
$ rpm -qa | grep kernel-headers-$(uname -r)
Go ahead and install kernel headers with yum command. This command will automatically find a package of matching kernel headers, and install it.
$ sudo yum install kernel-headers
![](https://farm9.staticflickr.com/8594/15378403114_c51ff6f4ae_z.jpg)
Verify the status of the installed package.
$ rpm -qa | grep kernel-headers-$(uname -r)
----------
kernel-headers-3.10.0-123.9.3.el7.x86_64
The default location of kernel headers on Fedora, CentOS or RHEL is **/usr/include/linux**.
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/install-kernel-headers-linux.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://www.kernel.org/pub/linux/kernel/
[2]:https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt

View File

@ -0,0 +1,74 @@
Linux有问必答-- 如何在Linux上安装内核头文件
================================================================================
> **提问**:我在安装一个设备驱动前先要安装内核头文件。怎样安装合适的内核头文件?
当你在编译一个设备驱动模块时你需要在系统中安装内核头文件。内核头文件同样在你编译与内核直接链接的用户空间程序时需要。当你在这些情况下安装内核头文件时你必须确保内核头文件精确地与你当前内核版本匹配比如3.13.0-24-generic
如果你的内核发行版自带的内核版本或者使用默认的包管理器的基础仓库升级的比如apt-ger、aptitude或者yum你也可以使用包管理器来安装内核头文件。另一方面如果下载的是[kernel源码][1]并且手动编译的,你可以使用[make命令][2]来安装匹配的内核头文件。
现在我们假设你的内核是发行版自带的,让我们看下该如何安装匹配的头文件。
### 在 Debian、Ubuntu 或者 Linux Mint 上安装内核头文件 ###
假设你没有手动编译内核你可以使用apt-get命令来安装匹配的内核头文件。
首先使用dpkg-query命令检查是否有可用的内核头文件。
$ dpkg-query -s linux-headers-$(uname -r)
----------
dpkg-query: package 'linux-headers-3.11.0-26-generic' is not installed and no information is available
接着使用下面的命令安装匹配的内核头文件。
$ sudo apt-get install linux-headers-$(uname -r)
![](https://farm9.staticflickr.com/8681/16000652415_a7c399992e_z.jpg)
验证头文件是否成功安装。
$ dpkg-query -s linux-headers-$(uname -r)
----------
Package: linux-headers-3.11.0-26-generic
Status: install ok installed
Debian、Ubuntu、Linux Mint默认头文件在**/usr/src**下。
### 在 Fedora、CentOS 或者 RHEL 上安装内核头文件 ###
假设你没有手动编译内核你可以使用yum命令来安装匹配的内核头文件。
首先用下面的命令检查系统是否已经按炸ung了头文件。如果下面的命令没有任何输出这就意味着还没有头文件。
$ rpm -qa | grep kernel-headers-$(uname -r)
接着用yum命令安装头文件。这个命令会自动找出合适的头文件并安装。
$ sudo yum install kernel-headers
![](https://farm9.staticflickr.com/8594/15378403114_c51ff6f4ae_z.jpg)
验证包安装的状态。
$ rpm -qa | grep kernel-headers-$(uname -r)
----------
kernel-headers-3.10.0-123.9.3.el7.x86_64
Fedora、CentOS 或者 RHEL上默认内核头文件的位置是**/usr/include/linux**。
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/install-kernel-headers-linux.html
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://www.kernel.org/pub/linux/kernel/
[2]:https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt