Guest additionals: Kernel headers not found for target kernel
Solution 1
On my CentOS 6 VM, the kernel development package was not installed, so I had to do:
yum install kernel-devel
This, however, created a mismatch between the kernel development version (2.6.32-754.31.1.el6
) and the actual kernel version (2.6.32-754.el6
). You can check all these versions using yum list kernel*
. So, I then updated my kernel version and rebooted:
yum update kernel kernel-headers
reboot now
On my system, the Guest Additions autorun.sh
file still did not complete after this, because the gcc
package was missing:
yum install gcc
After installing gcc
, the Guest Additions installation succeeded, and they took effect after another reboot.
Solution 2
here's the code from the Virtual Box script:
if test -d /lib/modules/"$TARGET_VER"/build; then
setup_modules "$TARGET_VER"
depmod
else
info "Kernel headers not found for target kernel $TARGET_VER. [...]
The variable $TARGET_VER
is defined as:
test -z "${TARGET_VER}" && TARGET_VER=`uname -r`
So I'd check if /lib/modules/$(uname -r)/build
points to a valid directory with kernel source...
Solution 3
I am not sure, but i think even if you are loading the correct kernel, the devel package that include headers since the newest kernel versions is incompatible with the current kernel, to check this :
rpm -qa | grep kernel
Then install the correct devel version and make sure gcc and make are installed :
yum -y install gcc make
yum -y install kernel-uek-devel-`uname -r`
if the repo is not available, execute this before
yum-config-manager --add-repo=yum.oracle.com/repo/OracleLinux/OL6/UEKR4/archive/x86_64
sudo yum install -y kernel-uek-4.1.12-124.24.3.el6uek.x86_64
sudo yum install -y kernel-uek-devel-4.1.12-124.24.3.el6uek.x86_64
Solution 4
Let's see the message:
VirtualBox Guest Additions: Kernel headers not found for target kernel
5.3 (in may case).
the target kernel is the kernel version the OS is using. you can see it with:
uname -r
5.3
The kernel headers are made by the kernel-devel package: you can see the versión of kernel-devel with:
dnf list kernel-level*
kernel-devel.x86_64 5.10
I have Kernel headers for kernel version 5.10, but virtual box is trying to use headers for kernel versión 5.3.
You have to boot the OS using kernel version 5.10 instead of 5.3
to see if you have kernel versión 5.10:
dnf list kernel-core*
kernel-core.x86_64 5.3 @updates
kernel-core.x86_64 5.9 @updates
kernel-core.x86_64 5.10
There it is.
Now you just need to update grub2 so it can see the new kernel versión:
grub2-mkconfig –o /boot/grub2/grub.cfg
reboot
Now check again which kernel version the OS is using:
uname –r
5.10
this solved the problem for me.
Related videos on Youtube
Dyno Sedano
Updated on September 18, 2022Comments
-
Dyno Sedano over 1 year
I've been having a difficult time getting Guest Additions to install on my Oracle Linux 7. I have VirtualBox version 6.1.4. I have guest additions version 6.0.4
The machine had 4.14.35-1902.7.3.1 kernel version. I succesed installed it a kernel version 4.1.12-124.24.3 on it. To do so, I followed the instructions from this page: https://www.thegeekdiary.com/centos-rhel-7-change-default-kernel-boot-with-old-kernel/
Installation steps:
yum -y install kernel-uek-firmware-4.1.12-124.24.3.el6uek.noarch.rpm yum -y install kernel-uek-4.1.12-124.24.3.el6uek.x86_64.rpm yum -y install kernel-uek-devel-4.1.12-124.24.3.el6uek.x86_64.rpm awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg grub2-set-default 0 #depends on the above result grub2-mkconfig -o /boot/grub2/grub.cfg And reboot.
When I run
uname -r
I got this: 4.1.12-124.24.3.el6uek.x86_64At this point, everything it's fine until I have to install Guest Additions.
When I run ./VBoxLinuxAdditions.run this error is returned:
Verifying archive integrity... All good. Uncompressing VirtualBox 6.0.4 Guest Additions for Linux........ VirtualBox Guest Additions installer Removing installed version 6.1.4 of VirtualBox Guest Additions... Copying additional installer modules ... Installing additional modules ... VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Kernel headers not found for target kernel 4.1.12-124.24.3.el6uek.x86_64. Please install them and execute /sbin/rcvboxadd setup modprobe vboxguest failed The log file /var/log/vboxadd-setup.log may contain further information.
I reran
/sbin/rcvboxadd setup
but it was the same log message. The log file just showed up "modprobe vboxguest failed". I also exported KERN_DIR environment variable as/usr/src/kernels/4.1.12-124.24.3.el6uek.x86_64
What I am doing wrong? Does anyone knows how to install it properly? If anyone has any ideas I would really appreciate feedback.
-
Dyno Sedano about 4 yearsI tried it and it didn't work.
[root@devbox ~]# yum -y install kernel-uek-devel-`uname -r` Loaded plugins: langpacks, ulninfo No package kernel-uek-devel-4.1.12-124.24.3.el6uek.x86_64 available. Error: Nothing to do
-
Reda Salih about 4 yearsTry to add this repo : yum.oracle.com/repo/OracleLinux/OL6/UEKR4/archive/x86_64
-
DavidS about 3 yearsThis answer basically worked for me. For me there was no mismatched version, but I did have a lot other missing packages. The error log guided me through which packages to
yum install
. At the end of it all I rebooted and now things seem to be working nicely.