Set up VirtualBox 5.0 on a Headless CentOS 6 Server

Part 1 of setting up a Linux home lab environment with VirtualBox. Check this blog post for more info.

VirtualBox is a powerful and feature rich x86/AMD64/Intel64 virtualisation product for enterprise as well as home use.

Software

Software used in this article:

  1. CentOS 6
  2. VirtualBox 5

Installation

Add VirtualBox repository:

# wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo \
 -O /etc/yum.repos.d/virtualbox.repo

Install kernel headers and other dependencies:

# yum install -y binutils gcc make patch libgomp dkms \
 glibc-headers glibc-devel kernel-headers kernel-devel

Install and setup VirtualBox:

# yum install -y VirtualBox-5.0
# /etc/init.d/vboxdrv setup

Download VirtualBox extension pack (v5.0.6) which contains a VRDE module needed for VBoxHeadless:

# wget http://download.virtualbox.org/virtualbox/5.0.6/Oracle_VM_VirtualBox_Extension_Pack-5.0.6.vbox-extpack

Install extension pack:

# VBoxManage extpack install ./Oracle_VM_VirtualBox_Extension_Pack-5.0.6.vbox-extpack
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Successfully installed "Oracle VM VirtualBox Extension Pack".

Verify installation:

# VBoxManage list extpacks
Extension Packs: 1
Pack no. 0:   Oracle VM VirtualBox Extension Pack
Version:      5.0.6
Revision:     103037
Edition:
Description:  USB 2.0 and USB 3.0 Host Controller, Host Webcam, VirtualBox RDP, PXE ROM, Disk Encryption.
VRDE Module:  VBoxVRDP
Usable:       true
Why unusable:

To uninstall extension pack, do:

# VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack"

Configuration

We use a separate 500GB /dev/sdb1 disk mounted on /vb to store VirtualBox images.

Create VirtualBox CentOS Image

Configuration file can be see below:

# cat ./vbox-provision.sh
#!/bin/bash
# written by Tomas (www.lisenet.com)
# 12/04/2014 (dd/mm/yy)
# copyleft free software
#
# Variables below are passed to VBoxManage
# Modify appropriately
#
VM="CentOS_6"; #name of the virtual machine
ISO="/tmp/CentOS-6.7-x86_64-minimal.iso";
VBROOT="/vb";
OSTYPE="RedHat";
DISKSIZE=64000; #in MB
RAM=512; #in MB
CPU=1;
CPUCAP=100;
PAE="off";
ADAPTER="eth0";
HWVIRT="off";
NESTPAGING="off";
VRAM=8;
USB="off";

echo "Creating the "$VM" VM."
cd ~;
VBoxManage createhd --filename "$VBROOT"/"$VM"/"$VM".vdi --size "$DISKSIZE";
VBoxManage createvm --register --name "$VM" --basefolder "$VBROOT" --ostype "$OSTYPE";
VBoxManage storagectl "$VM" --name "SATA Controller" --add sata  --controller IntelAHCI;
VBoxManage storageattach "$VM" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$VBROOT"/"$VM"/"$VM".vdi;
VBoxManage storagectl "$VM" --name "IDE Controller" --add ide;
VBoxManage storageattach "$VM" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "$ISO";
VBoxManage modifyvm "$VM" --memory "$RAM";
VBoxManage modifyvm "$VM" --boot1 dvd --boot2 disk --boot3 none --boot4 none;
VBoxManage modifyvm "$VM" --chipset piix3;
VBoxManage modifyvm "$VM" --ioapic off;
VBoxManage modifyvm "$VM" --mouse ps2;
VBoxManage modifyvm "$VM" --cpus "$CPU" --cpuexecutioncap "$CPUCAP" --pae "$PAE";
VBoxManage modifyvm "$VM" --hwvirtex off --nestedpaging off;
VBoxManage modifyvm "$VM" --nic1 bridged --bridgeadapter1 "$ADAPTER";
VBoxManage modifyvm "$VM" --vram "$VRAM";
VBoxManage modifyvm "$VM" --monitorcount 1;
VBoxManage modifyvm "$VM" --accelerate2dvideo off --accelerate3d off;
VBoxManage modifyvm "$VM" --audio none;
VBoxManage modifyvm "$VM" --snapshotfolder "$VBROOT"/"$VM"/Snapshots;
VBoxManage modifyvm "$VM" --clipboard bidirectional;
VBoxManage modifyvm "$VM" --usb "$USB";
VBoxManage modifyvm "$VM" --vrde on;
echo "Run 'vboxmanage list -l vms | less' to check configuration."
exit 0;

Run the script to provision a new virtual machine:

# bash ./vbox-provision.sh

Please feel free to check this post:

https://www.lisenet.com/2014/virtualbox-4-1-on-a-headless-debian-wheezy-server/

for more detailed explanation of VirtualBox configuration parameters that we use in this article.

Install Virtual Machine

Start the CentOS VM and bind VirtualBox remote desktop extension server to TCP 8888 port:

# VM=CentOS_6
# VBoxHeadless --startvm "$VM" -e "TCP/Ports=8888" --vrde on

To proceed with CentOS installation, we need to connect with rdesktop/freerdp from a GUI capable machine and follow on-screen instructions:

$ rdesktop <virtualbox_server_ip>:8888

It is recommended to install VirtualBox Guest Additions. They are designed to be installed inside a virtual machine after the guest operating system has been installed. The Guest Additions consist of device drivers and system applications that optimise the guest operating system for better performance and usability and make your life much easier.

4 thoughts on “Set up VirtualBox 5.0 on a Headless CentOS 6 Server

  1. Hi Tomas,

    As part of https://www.lisenet.com/2015/setup-linux-home-lab-environment-with-oracle-virtualbox/, you wanted to set up a management server(first guest OS) with two network cards. So one should be NAT and other one is HOST-Only. Will both network cards receive their IP’s via DHCP from virtual box? or only the NAT network card. Could you please explain and if possible write an article on this , so its easy for a starter like me to follow the steps.

    Also i see that variable “$VBOXROOT” used in the script is not defined any where. It could be a typo (VBOXROOT should be “VBROOT”). if yes, please correct it.

    • Hi Sam,

      Yeah, that was a typo, well spotted. I’ve fixed it now.

      With regards to the management server, you are right, one NIC is for NAT, and another NIC is for Host-only. Now to answer your DHCP question, the NAT’ed interface will automatically receive configuration from a DHCP server integrated into VirtualBox.

      The Host-only card can receive a DHCP lease if you have your network adapter configured with a DHCP server. In my case the DHCP server on the Host-only adapter is disabled, because I use a DHCP server that is configured on the management server. All DHCP leases on the Host-only network are issues by the management server and not by VirtualBox.

  2. What did I mess up?
    VRDE server is listening on port 8888.
    Error: failed to start machine. Error message: Failed to open/create the internal network ‘HostInterfaceNetworking-eth0’ (VERR_INTNET_FLT_IF_NOT_FOUND).
    Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND)

    • Check the VirtualBox error log, it should have more info. Might be a problem with bridging/network drivers. Try NAT’ed network interface and see if that makes a difference.

Leave a Reply to Sam Cancel reply

Your email address will not be published. Required fields are marked *