This article will show you how to install VirtualBox 4.1 on a fresh installation of CentOS 6.2 Linux. In the tutorial below VirtualBox is installed immediately after having installed CentOS 6.2 (desktop setup) and rebooting it after having applied all the latest OS updates.
The following steps will need to be done with the root account.
Installation
Change to the /etc/yum.repos.d/ directory and download the VirtualBox repo file into your yum repository. With this you’ll be able to install VirtualBox through yum and updates for VirtualBox will also be included whenever you run the yum update command:
[root@Linux ]# cd /etc/yum.repos.d/ [root@Linux ]# wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
Take a look at the contents of the downloaded repo file to confirm that gpgcheck is enabled (gpgcheck=1) and to verify the location of the gpg key:
[root@Linux ]# cat virtualbox.repo [virtualbox] name=RHEL/CentOS-$releasever / $basearch - VirtualBox baseurl=http://download.virtualbox.org/virtualbox/rpm/rhel/$releasever/$basearch enabled=1 gpgcheck=1 gpgkey=http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc
The following steps are optional: Verify the fingerprint of the gpg key in order confirm that the key downloaded belongs to virtualbox.org. In the command below the character surrounded by a dashes before the pipe is an uppercase letter «O» (not zero):
[root@Linux ]# wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | gpg --quiet --with-fingerprint
pub 1024D/98AB5139 2010-05-18 Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org>
Key fingerprint = 7B0F AB3A 13B9 0743 5925 D9C9 5442 2A4B 98AB 5139
sub 2048g/281DDC4B 2010-05-18
Go to http://pgp.mit.edu/ and in the search string enter virtualbox.org, and checkmark «Show PGP fingerprints for keys». Confirm that the key fingerprint matches the one above for the addresses info@virtualbox.org:
Type bits/keyID Date User ID pub 1024D/98AB5139 2010-05-18 Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org> Fingerprint=7B0F AB3A 13B9 0743 5925 D9C9 5442 2A4B 98AB 5139 pub 1024D/6DFBCBAE 2008-07-14 Sun Microsystems, Inc. (xVM VirtualBox archive signing key) <info@virtualbox.org> Fingerprint=AF45 1228 01DA D613 29EF 9570 DCF9 F87B 6DFB CBAE
As you can see there are two keys found for info@virtualbox.org with the most recent key being the one that matches. Also notice that the key ID (98AB5139) shown in the output from pgp.mit.edu matches the key ID shown in the previous command.
Another optional step is to review the information of the VirtualBox package before proceeding with the installation (this will confirm the minor version):
[root@Linux ]# yum info VirtualBox-4.1
Available Packages
Name : VirtualBox-4.1
Arch : i686
Version : 4.1.8_75467_rhel6
Release : 1
Size : 58 M
Repo : virtualbox
Summary : Oracle VM VirtualBox
URL : http://www.virtualbox.org/
License : GPLv2
Description : VirtualBox is a powerful PC virtualization solution allowing
: you to run a wide range of PC operating systems on your Linux
: system. This includes Windows, Linux, FreeBSD, DOS, OpenBSD
: and others. VirtualBox comes with a broad feature set and
: excellent performance, making it the premier virtualization
: software solution on the market.
Proceed with installing VirtualBox (the command below is case sensitive). When prompted about the GPG key enter Y as long as the key ID matches the one above:
[root@Linux ]# yum install VirtualBox-4.1 Setting up Install Process . <snip> . Downloading Packages: VirtualBox-4.1-4.1.8_75467_rhel6-1.i686.rpm | 58 MB 01:08 warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID 98ab5139: NOKEY Retrieving key from http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc Importing GPG key 0x98AB5139: Userid: "Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org>" From : http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc Is this ok [y/N]: y . <snip> . Creating group 'vboxusers'. VM users must be member of that group! No precompiled module for this kernel found -- trying to build one. Messages emitted during module compilation will be logged to /var/log/vbox-install.log. Stopping VirtualBox kernel modules [ OK ] Uninstalling old VirtualBox DKMS kernel modules [ OK ] Trying to register the VirtualBox kernel modules using DKMS [FAILED] (Failed, trying without DKMS) Recompiling VirtualBox kernel modules [FAILED] (Look at /var/log/vbox-install.log to find out what went wrong) Installed: VirtualBox-4.1.i686 0:4.1.8_75467_rhel6-1 Complete!
(note that the second failed entry above shows that a problem which you might not experience on your system did occur for us. We’ll address this shortly)
Finally don’t forget to add your user account to the newly created vboxusers group, where «username» is the Linux user that you are adding to this group:
[root@Linux ]# /usr/sbin/usermod -a -G vboxusers username
Problems which some may encounter
Although this problem may not occur for your environment, in ours we can see from the output above that something failed and we are advised to examine /var/log/vbox-install.log to see what went wrong. In our case it tells us the following:
«unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.»
We were able to fix the issue by completing the following additional steps (if you don’t experience this problem you can skip to the end).
Install the following three packages (kernel-headers, kernel-devel, gcc):
[root@Linux ]# yum install kernel-headers kernel-devel gcc
Your system will install the packages above if they aren’t installed already, plus the package dependencies. Next confirm the version of your current kernel release:
[root@Linux ]# uname -r 2.6.32-220.2.1.el6.i686
Check /usr/src/kernels/ to confirm that a directory for the version of your current kernel release exists (this directory should exist after the installation of the packages above):
ls /usr/src/kernels/ 2.6.32-220.2.1.el6.i686
Above we see a match for «2.6.32-220.2.1.el6.i686». Specify and export the KERN_DIR parameter making sure to match the release version with whichever one is current for your system:
[root@Linux ]# KERN_DIR=/usr/src/kernels/2.6.32-220.2.1.el6.i686 [root@Linux ]# export KERN_DIR
Echo KERN_DIR to confirm that you’ve set it up properly:
[root@Linux ]# echo $KERN_DIR /usr/src/kernels/2.6.32-220.2.1.el6.i686
Finally re-run vboxdrv setup. This step may take a while to complete:
[root@Linux ]# /etc/init.d/vboxdrv setup Stopping VirtualBox kernel modules [ OK ] Uninstalling old VirtualBox DKMS kernel modules [ OK ] Removing old VirtualBox pci kernel module [ OK ] Removing old VirtualBox netadp kernel module [ OK ] Removing old VirtualBox netflt kernel module [ OK ] Removing old VirtualBox kernel module [ OK ] Trying to register the VirtualBox kernel modules using DKMS[FAILED] (Failed, trying without DKMS) Recompiling VirtualBox kernel modules [ OK ] Starting VirtualBox kernel modules [ OK ]
(the FAILED entry above for DKMS does not matter since recompiling the VirtualBox kernel modules succeeded).
Lastly don’t forget to add your user account to the vboxusers group if you haven’t done so already:
[root@Linux ]# /usr/sbin/usermod -a -G vboxusers username