Saturday 15 October 2016

Install VirtualBox headless on CentOS

This is a basic outline of the actions to install VirtualBox headless on CentOS. It is mostly for my own notes, but I share it here.
This log is based on CentOS 6.8 and VirtualBox 5.1. It may need to be modified for other versions.

1. Add the Virtual Box yum repository from Oracle website


$ cd /etc/yum.repos.d
$ sudo wget http://yum.oracle.com/public-yum-ol6.repo


2. Edit public-yum-ol6.repo


$ sudo nano public-yum-ol6.repo

Remove everything except the Oracle Linux addons from the repo, so it looks like this:

[ol6_addons]
name=Oracle Linux $releasever Add ons ($basearch)
baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/addons/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1


3. Download and import Oracle GPG keys


Instructions at Oracle website

$ wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
$ gpg --quiet --with-fingerprint ./RPM-GPG-KEY-oracle-0l6

If the fingerprint matches with the published Oracle fingerprint, import the key:
$ sudo rpm --import ./RPM-GPG-KEY-oracle-ol6

4. Install Dependencies


$ sudo yum install gcc make
$ sudo yum install kernel-devel


You may need to replace kernel-devel with a substitute, such as vzkernel-devel, depending on your set up. If unsure, do not install this dependency for now and see the error message that comes up during the installation of VirtualBox

5. Install VirtualBox


Since this is a headless installation, we do not want to pull in the X/Qt/Mesa etc. dependencies. Yum does not have functionality to omit dependencies, so we need to use rpm directly.
$ sudo rpm -Uvh --nodeps $(repoquery --enablerepo ol6_addons --location VirtualBox-5.1)

6. Add users to vboxusers group


$ sudo usermod -a -G vboxusers username

7. Install VirtualBox extension pack


$ wget http://download.virtualbox.org/virtualbox/5.1.6/Oracle_VM_VirtualBox_Extension_Pack-5.1.6-110634.vbox-extpack
$ sudo VBoxManage extpack install ./Oracle_VM_VirtualBox_Extension_Pack-5.1.6-110634.vbox-extpack


7. Create and run Virtual machines with headless frontend


follow instructions in the VirtualBox manual