Please enable JavaScript to view the comments powered by Disqus. SONKUN-DEV.net
Fix vboxdrv kernel module is not loaded
Friday, 24 August 2018

On a dedicated server, after installing VirtualBox with the underlying package manager (apt-get, yum, pacman, etc), there is chance that VirtualBox won't start and displays a message saying the vboxdrv kernel module is not loaded. This is because most providers install Linux with a custom kernel tuned for your underlying hardware. At least, this is the case for both Online.net and Kimsufi providers.

In this article, I'll explain how to put back the default Linux kernel on Arch Linux machine, fixing the problem. If you happen to use a different distribution, this article will likely give you some pointers for how to solve the problem.

Identifying the problem

More precisely, most VirtualBox command-lines will abruptly stop and display the following error message. For instance typing vboxmanage --version, will print the version after the message is displayed.

WARNING: The vboxdrv kernel module is not loaded. Either there is no module
         available for the current kernel (4.14.14-xxxx-std-ipv6-64) or it failed to
         load. Please recompile the kernel module and install it by

           sudo /sbin/vboxconfig

If this message is displayed, VirtualBox just can't run; vboxdrv is a mandatory kernel. One way to fix that is to use the default Linux kernel and reinstall VirtualBox. Type uname -r to verify which kernel your OS is currently using. Our objective will be to display a message that ressemble to 4.14.32-1-lts. Notice the -lts suffix.

In fact, installing the default Linux LTS kernel isn't even the complicated thing. It's rather configuring the boot options to pick it at boot time. So let's install the new kernel straight away.

sudo pacman -s linux-lts linux-lts-headers

To reconfigure the boot loader, we need to understand which boot loader is in used... and that will be different across machines. I found out that Online.net servers use Syslinux and Kimsufi uses GRUB boot loader. Skip the section that isn't your boot loader.

GRUB boot loader (Kimsufi)

I assume all Kimsufi dedicated servers use GRUB as the system boot loader but that might not be true. If this doesn't happen to be true on your machine, the explanation will obviously not make sense. For instance, if you can't find the /etc/grub.d/ directory, you have the answer.

To reconfigure GRUB to use the default kernel at boot time, we have to remove OVH configuration files from GRUB then regenerate the main GRUB configuration file grub.cfg. But before we proceed, let's make a backup.

mkdir ovh.d
sudo mv /etc/grub.d/06_OVH* ovh.d/

With the OVH configuration files removed, the last step is emptying the main GRUB configuration file and refilling it with the grub-mkconfig command.

cat /dev/null > /boot/grub/grub.cfg
grub-mkconfig > /boot/grub/grub.cfg

This regenerates the grub.cfg file without the OVH kernel stuff. You can now reboot your machine.

Syslinux boot loader (Online.net)

I assume all Online.net dedicated servers use Syslinux but that might be true. If this doesn't happen to be true on your machine, the explanation will obviously not make sense. For instance, if you can't find the /boot/syslinux/ directory, you have the answer.

To reconfigure Syslinux to use the default kernel at boot time, edit the relevant parts of file /boot/syslinux/syslinux.cfg to make it look like the following.

LABEL arch
    MENU LABEL Arch Linux
    LINUX ../vmlinuz-linux-lts
    APPEND root=/dev/sda3 rw
    INITRD ../initramfs-linux-lts.img

LABEL archfallback
    MENU LABEL Arch Linux Fallback
    LINUX ../vmlinuz-linux
    APPEND root=/dev/sda3 rw
    INITRD ../initramfs-linux-lts-fallback.img

Be very cautious when making the changes. It's not that difficult, it's basically just changing 3 occurrences by adding a -lts suffix. All occurences refers to an existing file in the /boot directory. Thefore you type ls /boot to verify if all occurences are typo-free. You can now reboot your machine.

Finishing up the installation of VirtualBox

After rebooting the system, typing uname -r should display the generic kernel (you should see a -lts suffix somewhere).

Install VirtualBox software was previously done with the pacman -S virtualbox command-line. I suggest a reinstallation of the package followed with rebooting the machine again. During the installation, choose virtualbox-host-dkms provider.

:: There are 3 providers available for libgl:
:: Repository extra
   1) libglvnd  2) nvidia-304xx-utils  3) nvidia-340xx-utils

Enter a number (default=1): 1
:: There are 2 providers available for VIRTUALBOX-HOST-MODULES:
:: Repository community
   1) virtualbox-host-dkms  2) virtualbox-host-modules-arch

Enter a number (default=1): 1

Displaying the version of VirtualBox with the vboxmanage --version will now print without the error message.

Conclusion

To fix the vboxdrv kernel module is not loaded, you install the default Linux kernel and reconfigure the boot loader. It's a fairly easy task but feel free to ask your questions. Please share your solution for other distributions as I would be happy to update the article to include them.

Next week in another article, I'll explain how to run a password-protected VirtualBox instance in headless mode, which will then be graphically accessible with the the RDP protocol using a client such as Remmina. All of this on a remote server using only command-lines.