Debian/Ubuntu Linux安装内核头文件包

时间:2020-01-09 10:40:20  来源:igfitidea点击:

如何内核头文件来为vmware工具或Virtualbox guest虚拟机编译模块。
如何使用命令行选项在Debian或Ubuntu Linux操作系统上安装Linux内核标头?

您可以在shell提示符下使用以下命令轻松地为当前正在运行的内核版本安装Linux内核标头。
用于Linux内核构建模块的头文件和脚本包含在linux-header-YOUR-Kernel-Version软件包中。
打开一个终端并以root用户身份执行命令以为正在运行的内核安装linux-headers *软件包。

确保您已更新版本

执行以下apt-get命令或apt命令:

$ sudo apt-get update

或者以root用户身份执行:

# apt-get update

搜索内核版本(可选)

输入以下apt-cache命令:

$ apt-cache search linux-headers-$(uname -r)

或者

$ apt search linux-headers-$(uname -r)

输出示例:

Sorting... Done
Full Text Search... Done
linux-headers-4.9.0-3-amd64/testing,now 4.9.30-2 amd64 [installed]
  Header files for Linux 4.9.0-3-amd64

在Debian或Ubuntu Linux下安装linux-header软件包

输入以下apt-get命令:

$ sudo apt-get install linux-headers-$(uname -r)

这是最新的Debian 9的输出:
使用apt-get安装Linux内核头文件

# apt-get install linux-headers-$(uname -r)

来自旧系统的输出示例:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libftdi1
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  binutils cpp-4.3 gcc-4.3 gcc-4.3-base libc-dev-bin libc6-dev libgmp3c2 libgomp1 libmpfr4
  linux-headers-2.6.32-5-common linux-kbuild-2.6.32 linux-libc-dev manpages-dev
Suggested packages:
  binutils-doc gcc-4.3-locales gcc-4.3-multilib libmudflap0-4.3-dev gcc-4.3-doc libgcc1-dbg
  libgomp1-dbg libmudflap0-dbg glibc-doc
Recommended packages:
  gcc c-compiler
The following NEW packages will be installed:
  binutils cpp-4.3 gcc-4.3 gcc-4.3-base libc-dev-bin libc6-dev libgmp3c2 libgomp1 libmpfr4
  linux-headers-2.6.32-5-amd64 linux-headers-2.6.32-5-common linux-kbuild-2.6.32 linux-libc-dev
  manpages-dev
0 upgraded, 14 newly installed, 0 to remove and 0 not upgraded.
Need to get 20.8 MB of archives.
After this operation, 68.9 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
....
..

安装后,您可以为VMWare或VirtualBox或您需要的任何其他内容编译模块。
还要确保在Debian/Ubuntu Linux上安装GNU GCC编译器集合:

$ sudo apt-get install build-essential