Tuesday, September 20, 2011

Build VirtualBox in Ubuntu 11.04

What is VirtualBox?
VirtualBox is a general purpose cross-platform virtualizer. It can be run on Linux, Mac, Windows and Solaris systems.

Purpose of VirtualBox
  • Simultaneously run multiple Operating Systems in a single machine
  • No hardware virtualization needed
  • Test systems, software without effecting your running system
  • Pack complete solutions as a virtual image to save the burden on configuring systems from scratch
  • Save cost on hardware, power and other infrastructure needs to run multiple systems to achieve a purpose. 
Read the Complete features list.

Some Terminologies:
  • Host OS : The system that runs the VirtualBox application
  • Guest OS : Systems run inside VirtualBox application
  • Virtual Machine (VM) : This is the environment which your Guest OS is running
  • Guest additions: Some features to improve the functionality of VMs running in VirtaulBox
This post is about building VirtualBox 4.1.51 from source in a Linux (Ubuntu 11.04) host.

  • Java Runtime Environment 
  • Several packages and libraries for the Linux distribution
  • Subversion client
Prepare your system:
  • Installing necessary packages
$ sudo apt-get install gcc g++ bcc iasl xsltproc uuid-dev zlib1g-dev libidl-dev libsdl1.2-dev libxcursor-dev libasound2-dev libstdc++5 libhal-dev libpulse-dev libxml2-dev libxslt1-dev python2.5-dev libqt4-dev qt4-dev-tools libcap-dev libxmu-dev mesa-common-dev libglu1-mesa-dev linux-kernel-headers libcurl4-openssl-dev libpam0g-dev libxrandr-dev libxinerama-dev libqt4-opengl-dev makeself subversion

If you run on 64bit machine (As I'm now) you'll have to install the following 32bit packages too.

$ sudo apt-get install ia32-libs libc6-dev-i386 lib32gcc1 gcc-multilib lib32stdc++6

(Note:I've copied the packages from VirtualBox web site but practically I've installed them one by one checking what that package really does. And some times the packages are named differently in other systems.)
  • Install and setup Java RE 1.6.x
Check whether you have the Canonical partner repository is enabled in your sources.list

$ sudo apt-get install sun-java6-jdk sun-java6-jre sun-java6-bin sun-java6-plugin
  • Setup the Java home in your system into environment variable. 
Append the following to the ~/.bashrc

export JAVA_HOME="/usr/lib/jvm/java-6-sun-"

Checkout the source code from VirtualBox SVN

$ svn co http://www.virtualbox.org/svn/vbox/trunk vbox

Building the VirtualBox

1. Navigate to vbox directory and run configure script

$ ./configure --disable-hardening

2. To build the VBox you need to source the generated environment script
$ source ./env.sh

3. Build the package

$ kmk all

4. Build and install the VirtualBox kernel module

$ cd out/linux.x86/release/bin/src 
$ make 
$ sudo make install 
$ sudo modprobe vboxdrv 
$ sudo chown user:group /dev/vbodrv 

Once the kernel module is installed and loaded in to the kernel, navigate to "/vbox/out/linux.amd64/release/bin" and you can run the VirtualBox by issuing the following command.
$ ./VirtualBox

That way you can build the Oracle's VirtualBox from source. For the easy of running you may create a local alias or a menu icon to run VBox.

$sudo ln -s /usr/local/bin/virtaulbox ~/vbox/out/linux.amd64/release/bin/VirtualBox

VirtualBox source code is under GNU GPL V2.

No comments: