Using VirtualBox with Ubuntu 11.04 Server

Virtual Box is a free software package from Oracle (formerly Sun) that allows software virtualization (through the kernel or OS, rather than at the hardware level) on platforms that don't support hardware virtualization. Virtualization allows us to modularize our servers and easily back up entire servers by cloning the VM's. For more information on why virtualization is desireable, see the Grand Plan.

Installing VirtualBox 4.0.4 on our Ubuntu Server 10.10 64-Bit Host

before we can install Virtualbox, we need to add their repository to our sources list. To do this, use the following command:

sudo echo deb maverick contrib non-free >> /etc/apt/sources.list

and then download and the public key for secure downloads from the repository:

wget -q -O- | sudo apt-key add -

now we should be able to update our apt-get database:

sudo apt-get update

If you get an error, make sure that you added the public key. Now you can go ahead and install VirtualBox:

sudo apt-get install dkms virtualbox-4.0

The dkms package makes sure that the VirtualBox drivers get added back in anytime a kernel update is downloaded, so it's pretty important. Without it, you'll need to reinstall VirtualBox anytime a kernel update is released.

After this we need to add the extension pack so that we have VRDP (Virtual Remote Desktop Protocol) support. VRDP is the only real option we have to create VM's on our headless server, as you can't ssh into the VM until you finish installing the Guest OS. To install the extension pack, we first need to go ahead and download the tarball. Go ahead and make a temporary directory and change into it:

mkdir ~/tmp && cd ~/tmp

then go ahead and download the tarball:


and install it:

sudo VBoxManage extpack install *.vbox-extpack

You can verify that it installed correctly by issuing:

VBoxManage list extpacks

if the output looks like this then it installed correctly:

Extension Packs: 1
Pack no. 0:   Oracle VM VirtualBox Extension Pack
Version:      4.0.4
Revision:     70112
Description:  USB 2.0 Host Controller, VirtualBox RDP, PXE ROM with E1000 support.
VRDE Module:  VBoxVRDP
Usable:       true 
Why unusable: 

it's also best to go ahead and create a user to run your virtual machines as, so that they are modularized from the rest of the system:

sudo useradd -g users -G audio,floppy,lp,games -s /bin/bash vboxuser

and then give it a password with:

sudo passwd vboxuser

additionally, if you chose to create a separate Logical Volume for your VM Hard Disks as I did, you'll need to change the permissions on the partition like this:

sudo chown vboxuser /media/VirtualBoxVMs
sudo chmod 700 /media/VirtualBoxVMs

This makes it so that only vboxuser can access the partition without using the sudo command. We do this so that none of the system users (users created by Ubuntu for particular tasks) can affect the partition incidentally.

Now that it's installed, you have a couple choices to use it, since we're on a headless system:

  • You can administer to VirtualBox entirely from the command-line with the VboxManage Command. There is a bunch more information in the VirtualBox Manual. While this option is really annoying, as they commands change slightly with each release of VirtualBox, it is important as this is how we're going to write scripts for VirtualBox.
  • You can administer to it via ssh X Forwarding if you're on linux. The upside to this way is you don't have to install and configure phpVirtualBox, which isn't always that easy. The downside is that sometimes VirtualBox is frustratingly slow through SSH. To administer this way, all you have to do is add the -X flag when you ssh to the server like this: ssh -X [hostname] and then run the VirtualBox command to open the GUI.
  • You can administer to VirtualBox with phpVirtualBox. This is a Web GUI for VirtualBox. It's almost identical to the VirtualBox interface, but it's available in your browser. This is my preferred method, as it runs quite quickly, and is accessibly by any computer on your network, or anywhere in the world if you configure it that way (I confine it to my network since I'm paranoid).

If you would like to install phpVirtualBox, you can jump there next, or you can skip directly to creating a VM to create your first VM.