VirtualBox kernel driven not installed (missing gcc-12)

Updated: February 5, 2024

The problem you're facing is as follows: You use a Debian-based system, probably Ubuntu or one of its flavors. You have recently ran a system-wide update, which also includes a new version of VirtualBox. You use the upstream VirtualBox repository. After applying the update, you can no longer run virtual machines.

You get the following error: Kernel driver not installed (rc=-1908) . The VirtualBox Linux kernel driver is either not loaded or not set up correctly. Please try setting it up again by executing '/sbin/vboxconfig' as root. And there you have it. Now let's go into details, and fix this problem, shall we.

Problem in more detail

The full error message is as follows:

Kernel driver not installed (rc=-1908).

The VirtualBox Linux kernel driver is either not loaded or not set up correctly. Please try setting it up again by executing

'/sbin/vboxconfig'

as root.

If your system has EFI Secure Boot enabled you may also need to sign the kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load them. Please see your Linux system's documentation for more information.

where: suplibOsInit what: 3 VERR_VM_DRIVER_NOT_INSTALLED (-1908) - The support driver is not installed. On linux, open returned ENOENT.

Kernel driver error

To be fair, this error message is a bit misleading, as it includes the Secure Boot stuff in there, which is most likely totally not relevant, plus the last part of the error message uses a different syntax and grammar than the first part. So let's be systematic about it, and proceed step by step.

If you run sudo /sbin/vboxconfig on the command line, you will see the following:

[sudo] password for igor:
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
vboxdrv.sh: failed: Look at /var/log/vbox-setup.log to find out what went wrong.

There were problems setting up VirtualBox. To re-start the set-up process, run
/sbin/vboxconfig
as root. If your system is using EFI Secure Boot you may need to sign the
kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load
them. Please see your Linux system's documentation for more information.

In the /var/log/vbox-setup.log, we have the following:

Building the main VirtualBox module.
Error building the module:
make V=1 CONFIG_MODULE_SIG= CONFIG_MODULE_SIG_ALL= -C /lib/modules/6.5.0-14-generic/build M=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 -j20 modules
make[1]: warning: -j20 forced in submake: resetting jobserver mode.
warning: the compiler differs from the one used to build the kernel
The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
You are using:
make -f ./scripts/Makefile.build obj=/tmp/vbox.0 need-builtin=1 need-modorder=1
# cmd_mod /tmp/vbox.0/vboxdrv.mod
printf '%s
' linux/SUPDrv-linux.o SUPDrv.o SUPDrvGip.o SUPDrvSem.o SUPDrvTracer.o SUPLibAll.o
...
/tmp/vbox.0/linux/SUPDrv-linux.c   ; ./tools/objtool/objtool --hacks=jump_label --hacks=noinstr --hacks=skylake --retpoline --rethunk --sls --stackval --static-call --uaccess --prefix=16 --module /tmp/vbox.0/linux/SUPDrv-linux.o
/bin/sh: 1: gcc-12: not found
make[2]: *** [scripts/Makefile.build:251: /tmp/vbox.0/linux/SUPDrv-linux.o] Error 127
make[1]: *** [Makefile:2037: /tmp/vbox.0] Error 2
make: *** [/tmp/vbox.0/Makefile-footer.gmk:133: vboxdrv] Error 2

I truncated the log on purpose, because it contains a ton of compilation stuff that is simply not relevant. Furthermore, reading the make compilation logs can be a bit difficult. But you want to look at the end of the log, and search for any line that reads 'Error' or 'not found'.

Indeed, in our log, we have:

/bin/sh: 1: gcc-12: not found

For whatever reason, the system does not have the gcc-12 compiler, needed to build the VirtualBox kernel modules. Just so you know, one of my Kubuntu 22.04 boxen did have it, and another didn't. There. I do not want to go into the million reasons why you may not have this package. The main idea is for us to figure out what went wrong and fix it.

Solution

The actual fix is quite underwhelming. We need to install the gcc-12 package.

sudo apt install gcc-12

Then, once this command completes, rerun:

sudo /sbin/vboxconfig

The command should complete successfully, and you can go back to using VirtualBox.

Conclusion

This issue stems from a combination of factors. New Ubuntu kernel, new VirtualBox version, incompatible compiler and driver and whatnot. Lots of nerdy stuff, unfortunately. If you encounter the -1908 error message, the best thing is to work methodically. Rerun the configuration command manually, in a terminal window, follow and trace and verbose error log, until you find the culprit.

As it turns out, I noticed the most recent reason for this kind of error seems to be a missing gcc-12 compiler package. Once you install it, VirtualBox drivers will compile successfully. After that, you should be able to use your virtualization software and launch your virtual machines without any problems. Hopefully, this little tutorial will help you regain your productivity. Take care, fellas.

Cheers.