15

When I type the command service vboxdrv setup in my CentOS 7 terminal, I get the following error:

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

How can I resolve this error?

When I open the log file by typing vi /var/log/vbox-install.log, the contents are:

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. 

The error is happening in the process of installing VirtualBox 5.0.4 using the instructions from this tutorial. To summarize, so far, I have:

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

Add the following text, then save and exit:

[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 

Then at command prompt type:

# 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) 

See above for contents of vi /var/log/vbox-install.log

Out of curiousity, I looked in /lib/modules/ and found the following:

[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 

As per @EricRenouf's advice, I typed uname -a, and the terminal replied with:

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 

I have not rebooted the machine, but the tutorial did not say to reboot.

1
  • Did you update your kernel without rebooting at some point or something like that? Does uname -a show 3.10.0-229.el7.x86_64 or 3.10.0-229.14.1.el7.x86_64? I'm guessing it's the former, but yum installed the headers for the latter. Commented Sep 26, 2015 at 0:12

2 Answers 2

19

The solution is likely to be found at this question the short version being, run

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

That will install the kernel headers for the version of the kernel you are currently running.

I suspect that at some point you did a yum update or similar, and that actually installed a new kernel, but you have not yet started running it. What is probably happening is that when you do the yum install steps in your question it is looking at the latest installed version and getting the headers for that. Howerver, when you start vboxdrv it looks at the running kernel and tries to find the headers for that.

Your running and installed kernels are out of sync (which isn't normally a huge problem), but you found a case where it matters.

4
  • Not working for me. No package kernel-devel-uname-r == 4.4.193-1.el7.elrepo.x86_64 available. Commented Sep 21, 2019 at 10:06
  • @SadikÖzoguz if you are running the version of the kernel you want to install the headers for you can just try yum install kernel-devel perhaps that would work easier for you? If not, you might want to try asking as a new question (perhaps citing this one and giving more information about what your situation is) Commented Sep 22, 2019 at 11:54
  • I will ask a new question. Commented Sep 22, 2019 at 20:22
  • Saving my day. My home-server had this problem since last year when I updated something. Fortunately I compile only once a year Commented Dec 27, 2022 at 10:28
0

This issue still occurs on Virtualbox 6.1 and Fedora 32. My current kernel version and uname -r don't match the kernel-headers version.

# uname -r 5.10.17-100.fc32.x86_64+debug # yum list installed kernel-devel kernel-headers kernel Installed Packages kernel.x86_64 5.10.17-100.fc32 @updates kernel-devel.x86_64 5.10.17-100.fc32 @updates *kernel-headers.x86_64 5.10.13-100.fc32* 

You can work around this by changing the Virtual box script /usr/lib/virtualbox/check_module_dependencies.sh.

In my case I changed the fedora section to reflect the current version of headers I have installed, which DOES match the kernel version im running but is not identical to uname -r.   ie. ( I've hashed out the original line)

case "${UNAME}" in *.fc*.i686|*.fc*.x86_64)  # Fedora         BASE_PACKAGE="kernel-devel"         ###VERSIONED_PACKAGE="kernel-devel-${UNAME}"         VERSIONED_PACKAGE="kernel-devel-5.10.13-100" 

In the future if there is a new released kernel version that does match the header version you can always remove this is your VirtualBox stops again

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.