找不到内核3.10.0-229.el7.x86_64的内核头文件


12

service vboxdrv setup在CentOS 7终端中键入命令时,出现以下错误:

Your kernel headers for kernel 3.10.0-229.el7.x86_64 cannot be found  

如何解决此错误?

通过输入打开日志文件时vi /var/log/vbox-install.log,内容为:

Uninstalling modules from DKMS
  removing old DKMS module vboxhost version  5.0.4

------------------------------
Deleting module version: 5.0.4
completely from the DKMS tree.
------------------------------
Done.
Attempting to install using DKMS

Creating symlink /var/lib/dkms/vboxhost/5.0.4/source ->
                 /usr/src/vboxhost-5.0.4

DKMS: add completed.
Failed to install using DKMS, attempting to install without
Makefile:185: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  Stop.

使用本教程中的说明,在安装VirtualBox 5.0.4的过程中会发生错误。总结一下,到目前为止,我有:

vi /etc/yum.repos.d/virtualbox.repo

添加以下文本,然后保存并退出:

[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc

然后在命令提示符下键入:

# rpm -Uvh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# yum install gcc make patch  dkms qt libgomp 
# yum install kernel-headers kernel-devel fontforge binutils glibc-headers glibc-devel
...
Complete!  
# cd /usr/src/kernels
# ls -al
total 12
drwxr-xr-x.  3 root root 4096 Sep 25 16:14 .
drwxr-xr-x.  4 root root 4096 Sep 25 14:17 ..
drwxr-xr-x. 22 root root 4096 Sep 25 16:14 3.10.0-229.14.1.el7.x86_64
# export KERN_DIR=/usr/src/kernels/3.10.0-229.14.1.el7.x86_64
# yum install VirtualBox-5.0
...
Complete!  
# service vboxdrv setup
Stopping VirtualBox kernel modules                         [  OK  ]
Uninstalling old VirtualBox DKMS kernel modules            [  OK  ]
Removing old VirtualBox pci kernel module                  [  OK  ]
Removing old VirtualBox netadp kernel module               [  OK  ]
Removing old VirtualBox netflt kernel module               [  OK  ]
Removing old VirtualBox kernel module                      [  OK  ]
Trying to register the VirtualBox kernel modules using DKMSError! echo
Your kernel headers for kernel 3.10.0-229.el7.x86_64 cannot be found at
/lib/modules/3.10.0-229.el7.x86_64/build or /lib/modules/3.10.0-229.el7.x86_64/source.
                                                       [FAILED]
(Failed, trying without DKMS)
Recompiling VirtualBox kernel modules                      [FAILED]
(Look at /var/log/vbox-install.log to find out what went wrong)

请参阅上面的内容 vi /var/log/vbox-install.log

出于好奇,我查看/lib/modules/了以下内容:

[root@localhost kernels]# cd /lib/modules
[root@localhost modules]# ls -al
total 16
drwxr-xr-x.  4 root root 4096 Sep 25 15:58 .
dr-xr-xr-x. 30 root root 4096 Sep 25 16:23 ..
drwxr-xr-x.  7 root root 4096 Sep 25 15:59 3.10.0-229.14.1.el7.x86_64
drwxr-xr-x.  8 root root 4096 Sep 25 16:24 3.10.0-229.el7.x86_64

按照@EricRenouf的建议,我输入uname -a,终端回复:

Linux localhost.localdomain 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

我尚未重新启动计算机,但本教程并未说要重新启动。


您是否在不重新启动内核的情况下更新了内核?是否uname -a显示3.10.0-229.el7.x86_643.10.0-229.14.1.el7.x86_64?我猜是前者,但是yum安装了后者的标题。
埃里克·雷诺夫

Answers:


12

可能在此问题的短版本中找到解决方案,运行

sudo yum install "kernel-devel-uname-r == $(uname -r)"

这将为您当前正在运行的内核版本安装内核头文件。

我怀疑您在某个时候做了一个yum update或类似的事情,并且实际上安装了一个新内核,但是您尚未开始运行它。可能发生的情况是,当您执行问题中的yum install步骤时,它正在查看最新安装的版本并获取该文件的标题。但是,当您启动vboxdrv它时,它会查看正在运行的内核,并尝试找到该内核的标头。

您正在运行和安装的内核不同步(通常这不是一个大问题),但是您发现了一个重要的案例。


不为我工作。No package kernel-devel-uname-r == 4.4.193-1.el7.elrepo.x86_64 available.
SadikÖzoguz19年

@SadikÖzoguz如果您正在运行要安装头文件的内核版本,可以尝试尝试一下,yum install kernel-devel也许对您来说更容易些?如果不是,您可能想尝试提出一个新问题(也许引用这个问题,并提供有关您的处境的更多信息)
Eric Renouf

我会问一个新问题。
SadikÖzoguz19年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.