The "Kernel driver not installed" error in VirtualBox on Ubuntu 22.04 occurs because the vboxdrv kernel module is missing or fails to load due to unconfigured Secure Boot keys. To resolve this, you must install the linux-headers package, reinstall the VirtualBox DKMS modules using sudo dpkg-reconfigure virtualbox-dkms, and register the signing key with your system’s Machine Owner Key (MOK) manager during the next reboot.
Understanding the Root Cause
Ubuntu 22.04 LTS enforces strict security policies by default, particularly regarding Secure Boot. When Secure Boot is enabled, the Linux kernel will refuse to load unsigned kernel modules. VirtualBox relies on thevboxdrv kernel module to manage hardware virtualization extensions like Intel VT-x or AMD-V. If this module is not cryptographically signed with a key trusted by your BIOS/UEFI firmware, the kernel blocks it from loading, resulting in the generic "Kernel driver not installed (rc=-1908)" error when you attempt to start a virtual machine.
This issue is distinct from permission errors or network configuration problems. While other issues might prevent VMs from running, they typically present different symptoms such as "Permission denied" messages or network interface failures. For context on managing VM storage formats that might accompany these setup issues, you can review the differences between VDI and VHDX file structures. However, the immediate hurdle here is strictly at the kernel level, requiring administrative intervention to trust the VirtualBox drivers.
Prerequisites: Installing Kernel Headers
Before attempting to recompile or sign the drivers, your system must have the correct development headers for the currently running kernel version. Without these headers, the Dynamic Kernel Module Support (DKMS) system cannot build the necessary components. First, identify your current kernel version by opening a terminal and running:uname -r
Next, update your package lists and install the matching headers. Run the following command to ensure you have all required dependencies:
sudo apt update
sudo apt install linux-headers-$(uname -r)
It is critical that the version number returned by uname -r matches the installed headers exactly. If there is a mismatch, DKMS operations will fail silently or produce compilation errors. Once the installation completes, verify that the directory /lib/modules/$(uname -r)/build exists. This symbolic link points to the source code required for building the vboxdrv module.
Recompiling the VirtualBox Drivers
With the headers in place, you need to trigger the DKMS system to rebuild the VirtualBox kernel modules. In previous versions of Ubuntu or manual setups, users might have attempted to restart services directly. However, commands likesudo systemctl restart virtualbox are invalid because VirtualBox does not run as a standard systemd service in this manner; it relies on kernel modules loaded via modprobe.
Instead, use the dpkg-reconfigure utility which invokes the post-installation scripts for the virtualbox-dkms package. Execute the following command:
sudo dpkg-reconfigure virtualbox-dkms
This process may take several minutes as it compiles the C code for the kernel module. You should see output indicating that the module is being built and installed. If successful, the command will exit without error. If you encounter errors related to missing make tools, ensure you also have build-essential installed by running sudo apt install build-essential.
After recompilation, manually load the module to test if it is recognized by the kernel:
sudo modprobe vboxdrv
If this command returns no output, the module has loaded successfully into the kernel memory. If it returns an error about "invalid module format," your kernel headers do not match your running kernel, and you must reboot after updating the kernel packages.
Handling Secure Boot and MOK Registration
Even if the module loads manually, it may not persist across reboots if Secure Boot is active. During the boot sequence, you will be prompted to enroll a Machine Owner Key (MOK). This is the final step to authorize the VirtualBox driver. 1. Reboot your computer. 2. If Secure Boot is enabled, a blue screen titled "Shim UEFI key management" or "Enroll MOK" will appear. 3. Select "Enroll MOK" and press Enter. 4. Choose "Continue" to proceed with enrollment. 5. Enter the password you created when installing VirtualBox or when initially setting up Secure Boot keys. Note that characters will not be visible on screen as you type. 6. Confirm the enrollment by selecting "Yes". 7. Reboot the system again. Upon returning to Ubuntu, the system will have stored the signature for thevboxdrv module in its trusted key database. You can now launch VirtualBox and start your virtual machines without the kernel driver error. This process ensures that the host system maintains its security posture while allowing necessary third-party drivers to function.
For users who frequently switch between different guest operating systems, understanding how to configure dynamic disk space can optimize performance alongside these driver fixes. See our guide on configuring Linux guests with dynamic space to maximize efficiency.
Frequently Asked Questions
Why does the error persist after installing headers?
The error persists because the kernel module was not recompiled against the new headers or the Secure Boot key was not enrolled. Simply installing headers does not automatically rebuild existing modules; you must rundpkg-reconfigure virtualbox-dkms to trigger the build process. Additionally, if Secure Boot is enabled, the system will reject the module until you enroll the MOK key during reboot.
Can I disable Secure Boot instead of enrolling the key?
Yes, disabling Secure Boot in your BIOS/UEFI settings will allow unsigned kernel modules to load without restriction. However, this reduces your system's security posture by allowing any software with root-level access to load into the kernel. Enrolling the MOK key is the recommended approach as it maintains security while permitting VirtualBox to function correctly.What if dkmg-reconfigure fails with a compilation error?
Compilation failures usually indicate missing build tools or a kernel header mismatch. Ensure thatbuild-essential and dkms are installed via apt. Verify that the kernel version reported by uname -r exactly matches the installed linux-headers package. If you recently updated the kernel but did not reboot, the running kernel and the headers will differ, causing compilation to fail.
Does this fix apply to VirtualBox 7.0 as well?
Yes, the underlying mechanism for loading kernel drivers remains the same in VirtualBox 7.0. The package name may vary slightly depending on whether you installed the Oracle repository version or the Ubuntu community version, but thevboxdrv module and the DKMS workflow are consistent. The steps for compiling modules and enrolling MOK keys remain identical across recent VirtualBox releases.
How do I verify that the module is loaded correctly?
You can verify the module status by runninglsmod | grep vboxdrv. If the module is loaded, this command will return a line showing vboxdrv along with its size and usage count. If the output is empty, the module is not loaded, and you should check dmesg logs for specific error messages regarding why the kernel rejected the driver.