In this example, i install a CentOS in VirtualBox virtual machine. Then i click the virtual machine to focus it, and then i click Devices —> Insert Guest Additions CD image… menu item in the virtual machine top menu bar to install additions image like below picture. But during the installation process, i meet an error with error message VirtualBox Guest Additions: Kernel headers not found for target kernel 3.10.0-1062.el7.x86_64. This article will tell you how to fix it.
1. Reproduce VirtualBox Guest Additions: Kernel Headers Not Found For Target Kernel Error Steps.
- Click Devices —> Insert Guest Additions CD image… menu item.
- Then it will popup a dialog in the guest CentOS window like below, click Run button.
- Then it will open a terminal and run command like below picture, but you may encounter error message like below also.
VirtualBox Guest Additions: Kernel headers not found for target kernel 3.10.0-1062.el7.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. Press Return to close this window..
2. Fix VirtualBox Guest Additions: Kernel Headers Not Found For Target Kernel Error Steps.
- Open a terminal and run command uname -r to list current linux kernel version.
$ uname -r 3.10.0-1062.el7.x86_64
- Run command ls /usr/src/kernels/ to list all the installed kernels.
- If there are no kernels listed or the listed kernel version do not match your CentOS linux kernel version. Then you should run command yum install “kernel-devel-uname-r == $(uname -r)” to install your CentOS linux kernel. This command need root user to run, so first you need to run command su to login use root user.
$su Password: # yum install "kernel-devel-uname-r == $(uname -r)"
- When above install command execute success, you can run ls /usr/src/kernels/ to verify the CentOS kernel has been installed.
# ls /usr/src/kernels/ 3.10.0-1062.el7.x86_64
- Close the terminal, and you can find the VirtualBox Guest Additions CD has been mounted on the desktop. Right click the CD image and click Open in Terminal menu item in the popup menu list. Then run command ./autorun.sh, then it will open a new tab to install the VirtualBox Guest Additions software.
- During above installation process, you may encounter below error message This system is currently not set up to build kernel modules. Please install the gcc make perl packages from your distribution.
- Now run command yum install -y gcc perl kernel-headers kernel-devel in terminal with root user permission to install gcc make perl packages, this command may take some time longer.
# yum install -y gcc perl kernel-headers kernel-devel
- After execute above command, reboot the CentOS system.
- Now goto step 5, and the error will disappear when you install VirtualBox Guest Additions software.