Centos

找不到核心 3.10.0-229.el7.x86_64 的核心標頭檔

  • February 27, 2021

當我在我的 CentOS 7 終端中鍵入命令service vboxdrv setup時,我收到以下錯誤:

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

我還沒有重新啟動機器,但是教程沒有說要重新啟動。

解決方案很可能在這個問題上找到,簡短的版本是,執行

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

這將為您目前執行的核心版本安裝核心標頭檔。

我懷疑在某些時候你做了一個yum update或類似的,並且實際上安裝了一個新核心,但你還沒有開始執行它。可能發生的情況是,當您執行yum install問題中的步驟時,它正在查看最新安裝的版本並獲取標題。但是,當您啟動vboxdrv它時,它會查看正在執行的核心並嘗試為其查找標頭檔。

您正在執行和安裝的核心不同步(這通常不是一個大問題),但您發現了一個重要的案例。

引用自:https://unix.stackexchange.com/questions/232147