Introduction

We explained how to install VirtualBox on a Centos 7 machine in an earlier article wherein we ran into an issue during the install itself and were unable to start the service. In this article, we will share the diagnostic steps and the consequent resolution after which we were finally able to start the service and use the VirtualBox application.

 

Issue

On installing VirtualBox from Oracles’ official repository we received the following message

This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
kernel-devel kernel-devel-3.10.0-123.el7.x86_64
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
kernel-devel kernel-devel-3.10.0-123.el7.x86_64

I tried to start the vboxdrv service but the startup failed and given below is the systemctl status output

[root@linuxnix ~]# systemctl status vboxdrv.service
vboxdrv.service - VirtualBox Linux kernel module
Loaded: loaded (/usr/lib/virtualbox/vboxdrv.sh; enabled)
Active: failed (Result: exit-code) since Wed 2018-09-19 12:25:08 EDT; 10s ago
Process: 58858 ExecStart=/usr/lib/virtualbox/vboxdrv.sh start (code=exited, status=1/FAILURE)
Sep 19 12:25:08 linuxnix vboxdrv.sh[58858]: vboxdrv.sh: Starting VirtualBox services.
Sep 19 12:25:08 linuxnix vboxdrv.sh[58858]: vboxdrv.sh: Building VirtualBox kernel modules.
Sep 19 12:25:08 linuxnix vboxdrv.sh[58858]: This system is currently not set up to build kernel modules.
Sep 19 12:25:08 linuxnix vboxdrv.sh[58858]: Please install the Linux kernel "header" files matching the current kernel
Sep 19 12:25:08 linuxnix vboxdrv.sh[58858]: for adding new hardware support to the system.
Sep 19 12:25:08 linuxnix vboxdrv.sh[58858]: The distribution packages containing the headers are probably:
Sep 19 12:25:08 linuxnix vboxdrv.sh[58858]: kernel-devel kernel-devel-3.10.0-123.el7.x86_64
Sep 19 12:25:08 linuxnix systemd[1]: vboxdrv.service: control process exited, code=exited status=1
Sep 19 12:25:08 linuxnix systemd[1]: Failed to start VirtualBox Linux kernel module.
Sep 19 12:25:08 linuxnix systemd[1]: Unit vboxdrv.service entered failed state.
[root@linuxnix ~]#

I tried to load the vboxdrv kernel module manually but still no luck.

[root@linuxnix ~]# modprobe -v vboxdrv
modprobe: FATAL: Module vboxdrv not found.
[root@linuxnix ~]# /usr/lib/virtualbox/vboxdrv.sh setup
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
kernel-devel kernel-devel-3.10.0-123.el7.x86_64
[root@linuxnix ~]#

Diagnostics and resolution

I looked for the kernel-devel package and foudn that it was already installed on the system. On further checking I found out that the kernel package and the kernel-devel had different versions.

[root@linuxnix ~]# uname -r
3.10.0-123.el7.x86_64
[root@linuxnix ~]# yum list kernel-devel*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.nbrc.ac.in
* extras: mirrors.nhanhoa.com
* updates: mirrors.viethosting.com
Installed Packages
kernel-devel.x86_64 3.10.0-862.11.6.el7 @updates
[root@linuxnix ~]# yum install kernel-devel.x86_64 -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.nbrc.ac.in
* extras: mirrors.nhanhoa.com
* updates: mirrors.viethosting.com
Package kernel-devel-3.10.0-862.11.6.el7.x86_64 already installed and latest version
Nothing to do

Due to this our VirtualBox installation was failing.  You might also face this scenario in case you have not installed the development tools rpms. To rectify this I updated my operating system kernel using the following command:

yum update kernel -y

After this I rebooted my system to boot it up with the new kernel. Once the kernel and the kernel-devel packages had the same version I executed the vboxdrv.sh script which started VirtualBox flawlessly.

[root@linuxnix ~]# /usr/lib/virtualbox/vboxdrv.sh setup
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
[root@linuxnix ~]#

Conclusion

In this article we explained the resolution of one of the common errors that users face while installing VirtualBox on Linux. We hope that you found this article to be useful and we look forward towards your suggestions and feedback.

The following two tabs change content below.

Sahil Suri

He started his career in IT in 2011 as a system administrator. He has since worked with HP-UX, Solaris and Linux operating systems along with exposure to high availability and virtualization solutions. He has a keen interest in shell, Python and Perl scripting and is learning the ropes on AWS cloud, DevOps tools, and methodologies. He enjoys sharing the knowledge he's gained over the years with the rest of the community.