Kevin on the Kororaa Forums asked a question about VirtualBox and why it needs kernel modules.
Just wondering if someone could give me an idea of what Kernel Modules are and what they do in relation to Virtual Box? Every time I try to install VB it says you need “this” or “that” (mostly kernel modules) and I have no idea where to look, what they are, and what they do, so I am hoping to learn something. Also, if I get VB to work, and “they” update the kernel, do I have to add modules again or? Basically when I install VB, what do I have to install along side it?
Here’s my reply, as it might be useful for anyone running Fedora (note, this is using the latest package from Oracle, rather than the pre-compiled OSE in the Fedora repos).
So your operating system is made up of three (main) components:
- Physical hardware (computer bits)
- Kernel (software which talks to your hardware and makes it work, think drivers)
- Software (talks to your kernel to get to your hardware)
Your kernel is what makes your computer work (this is actually what Linux is, a kernel) and it’s actually the most important part of the operating system. When you’re talking about VirtualBox, it needs to create fake hardware on top of your real hardware, so to do that, it needs a driver. Drivers sit in the kernel layer.
The Linux kernel has thousands of drivers in it, but it does not have VirtualBox drivers in it (yet). This means you need to compile these and load them into your running kernel of you want to use VirtualBox. Once you do that, your kernel will have the fake hardware that the VirtualBox software needs to run. Drivers which you can load and unload into the kernel are called modules.
The VirtualBox host computer needs these drivers, but the VirtualBox guest also needs some drivers to make full use of the fake hardware. When you install Linux or Windows as a VirtualBox guest, the hardware is fake, so that OS needs drivers too! Some of those drivers (like audio and network) are already in the Linux kernel, so if your guest is running Linux, you just need drivers for the video, etc.
In order to compile the drivers for VirtualBox (on both host and guest) on Linux you need some development libraries, compiler program (such as GCC), as well as the headers for the running kernel. You need the headers because you need to compile a driver to load into the kernel and it needs to know detailed information about it.
Fortunately, if you’re using Kororaa, all of the required tools and packages are already installed! 🙂 All you need to do is build the drivers.
If you’re running a vanilla instance of Fedora, then you need to install the build tools like so:
su -c 'yum install gcc kernel-devel'
Now you have the build tools required to compile the drivers.
Automatically building drivers after kernel update
Modules are for a specific kernel and so when you get a kernel update, you need to re-compile the drivers for VirtualBox hosts and guests. Fortunately, there’s a neat little package called DKMS (Dynamic Kernel Module Support Framework) which will do this for you automatically – and of course Kororaa comes with this pre-installed.
If you’re running Fedora, you can easily install it like so:
su -c 'yum install dkms time'
When you install VirtualBox (see below), it will register the drivers with DKMS and on boot it will re-compile them for you, if it needs to. So, you just need to do it once and forget! Any updates to VirtualBox that are pulled in will also be automatically updated.
Building drivers on the host
Because Kororaa has all of the requirements for VirtualBox (including the package repository), all you need to do to get VirtualBox up and running is to install it using the package manager. If you prefer, you can install it manually like so (note the version is currently 4.1):
sudo yum install VirtualBox-4.1
Again, if you’re using vanilla Fedora, then you need to grab the VirtualBox repository file so that you can install VirtualBox from the Oracle repository (the packaged version from Fedora is usually a few versions behind).
su -c 'wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo -O /etc/yum.repos.d/virtualbox.repo'
Now you can install VirtualBox on Fedora:
su -c 'yum install VirtualBox-4.1'
You should see something like this during the install process:
No precompiled module for this kernel found -- trying to build one.
Stopping VirtualBox kernel modules [ OK ]
Uninstalling old VirtualBox DKMS kernel modules [ OK ]
Trying to register the VirtualBox kernel modules using DKMS [ OK ]
Starting VirtualBox kernel modules [ OK ]
As you can see, the modules were successfully compiled and registered with DKMS for future automatic compilation.
Just remember that any user who wants to run and use VirtualBox on the host needs to be in the vboxusers group. You can use the users graphical tool to do this (system-config-users), or add them to the group by running the command (substitute chris with your username):
sudo gpasswd -a chris vboxusers
Then just run VirtualBox and away you go!
Building drivers on the guest
Once you have your host up and your guest operating system installed, the way to install the required drivers is using the built in method. Once you have booted your guest operating system, simply click the Devices menu at the top, and click Install Guest Addons.
This will load a CD in your guest and you can run the autorun.sh script from the disk, which will ask you for the root password and then detect your operating system and compile the drivers for you.
Once again, if your guest is running Kororaa too, then you already have the required build tools and libraries. If not, you will need to install them first – how this is done depends on your distro (for Fedora, see above).
Remember, with DKMS you will automatically get updated drivers this way after a kernel update.
That’s it! Just reboot your guest and away you go.
Thanks a ton chris…..
Your article resolved issues i was facing.
Glad it could help! 🙂
An alternate option is to use VirtualBox-OSE from rpmfusion
They have the virtualbox kmod, meaning you do not need to compile the kernel module.
I prefer this method as I do not like installing gcc and the releated development tools and it is easier to maintain, yum will update the kmod with the kernel, so no need to build a kernel module manually with each new kernel.
Install the guest additions, however, is another matter. Some distros include the guest additions in the repos, so you might want to check on that before you compile.
Hey, thanks for your thoughts.
Yep, that’s certainly another way to do it – I mentioned at the beginning that the method in my post was not using the pre-packaged Fedora versions (from RPMFusion) because they are old (currently 4.0.2, vs 4.1).
I don’t think that kmod is actually easier to maintain at all – sometimes when you get a new kernel update there is no new kmod package for VirtualBox yet – that means when you reboot, you can’t use VirtualBox unless you boot back to your old kernel, or build it you yourself anyway. The akmod method would be better as it gets around this problem (akmod-VirtualBox-OSE) but this means that you need devel tools anyway.
By comparison, using the method in my post, you never ever have to manually build the kernel modules on the host. It’s all done for you automatically, no-matter what kernel you have, or what kernel you boot! To me, that’s much less annoying than the kmod method 🙂
thanks bro this article helped me
No problems 🙂
Thank you Chris. I am trying to setup a guest server for a class that I am taking. I could not get the drv to load. Your steps fixed the problem.
Thanks a lot for this guide, I’m pretty new to the fedora/red hat environment, so I’m glad you were here to guide us noobies through it all. thanks.
Hey! I’ve tried this steps carefully, as well as a lot fo different tutorials and stpe by step guides but just keep bumping into this error
#yum install VirtualBox-4.1
Redirecting to ‘/usr/bin/dnf install VirtualBox-4.1’ (see ‘manyum2dnf’)
Failed to synchronize cache for repo ‘fedora-spotify’, disabling.
Failed to synchronize cache for repo ‘home_ztefn’, disabling.
Last metadata expiration check: 0:10:34 ago on Thu Aug 9 13:54:23 2018.
No package VirtualBox-4.1 available.
Error: Unable to find a match.
I don’t use VirtualBox, but try without the version:
sudo dnf install VirtualBox