Linux – Guest additionals: Kernel headers not found for target kernel

centoskernellinuxvirtualbox

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_64

At 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.

Best Answer

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.

Related Question