Tuesday 11 May 2010

HOWTO: VirtualBox "headless" on Lucid Lynx

As of karmic koala, Vbox 3.x is provided via the standard Ubuntu repositories. Unfortunately, this is the OSE version and it does not appear to work headless.

So, we have to download the "free as in beer" version from the Oracle website, which is currently here

At the time of writing the current build for Lucid is virtualbox-3.2_3.2.4-62467~Ubuntu~lucid_i386.deb

Before we can install the deb, we will also need to install some dependencies.
sudo apt-get install libcurl3 dkms libqt4-network libqtgui4 libxslt1.1 libasound2 \
libdirectfb-1.2-0 libgl1-mesa-dri libgl1-mesa-glx libqt4-opengl libsdl1.2debian \
libsdl1.2debian-alsa libsysfs2 libts-0.0-0 libxcursor1 linux-headers-`uname -r` \
libxdamage1 libxfixes3 libxmu6 libxxf86vm1 tsconf libqtcore4 libaudio2 libmng1

Now we can install the virtualbox deb that we downloaded earlier.
sudo dpkg -i virtualbox-3.2_3.2.4-62467~Ubuntu~lucid_i386.deb

Next, add your user account to the vboxusers group
sudo adduser brettg vboxusers

Virtualbox machines that you create will by default go in your home directory
/home/brettg/.VirtualBox/

Ensure vboxusers have appropriate permissions to the kernel, create the file;
sudo vi /etc/udev/rules.d/40-permissions.rules

/etc/udev/rules.d/40-permissions.rules
KERNEL=="vboxdrv", GROUP="vboxusers", MODE="0660"

That's it, Virtualbox should be installed and ready to go.
Now we can move on to creating a virtual machine
Create a machine named "io"
VBoxManage createvm -name io --ostype Ubuntu -register

Configure it with a nic bridged to eth0, 256Mb RAM, enable acpi and set to boot from DVD
VBoxManage modifyvm io --memory 256 --pae on --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0

Create a virtual IDE controller
VBoxManage storagectl io --name IDE0 --add ide

Create a virtual HDD
VBoxManage createvdi -filename ~/.VirtualBox/Machines/io/sda.vdi -size 48000 -register

Attach the virtual HDD
VBoxManage storageattach io --storagectl IDE0 --port 0 --device 0 --type hdd --medium ~/.VirtualBox/Machines/io/sda.vdi

Create and attach a virtual DVD drive to the controller and insert the DVD image
VBoxManage storageattach io --storagectl IDE0 --port 1 --device 0 --type dvddrive --medium /store/archive/ISO/ubuntu-10.04-server-i386.iso

The default vrdp port for machines is 3389, however, if you intend to run more than one guest then each one will need to listen on a different port. I use the 3xxx range with the xxx being the last octet of the machines IP address. For example, 192.168.0.1 would be 3001.
VBoxManage modifyvm io --vrdpport 3001

And thats it, your machine has been created. Time to start it up and give it a test drive!

Using the virtual machine

Start the machine
nohup VBoxHeadless -startvm io &

On a GUI workstation, establish a remote desktop connection to the machine. In my case, the host server is called "jupiter" so I type;
rdesktop -a 8 jupiter:3001

After you have installed the OS, you need to tell the machine to boot from the hdd.
VBoxManage modifyvm io --boot1 disk

You can also deregister the dvd image if you don't intend to use it again.
VBoxManage unregisterimage dvd /store/archive/ISO/ubuntu-10.04-server-i386.iso


Here are some other useful commands;
VBoxManage showvminfo io
VBoxManage list hdds
VBoxManage list runningvms
VBoxManage controlvm io poweroff
VBoxManage unregistervm io --delete
VBoxManage controlvm io savestate
VBoxManage closemedium disk UUID
VBoxManage modifyhd UUID --type immutable

7 comments:

MD said...

Thanks for your work, it made my day !

YOU made my day.

Thanks again from France.

Anonymous said...

Excellent article -- very concise!

I had configured a headless Windows XP on Ubuntu 9.10 and made it to automatically start along with Linux. But it wouldn't shutdown automatically. I had to shutdown Windows XP before shutting down or restating Ubuntu Server. It would be great if you can update the article to do auto start and shutdown of the guest along with Ubuntu (without needing someone to login into the system).

Dave Marshall said...

Great article, helped me out no end.

After struggling, first with vmware and all the patches, then requiring FF3.5 to view the management console, then VirtualBox in the ubuntu repos, this post saved my sanity.

Anonymous said...

Excellent, right out the box it works flawlessly.
Setting up from remote works...
After messing up with vmware and Firefox trouble and all this is the way to go
Thanks a million

Eric Awuy

Harry Sufehmi said...

Hi, I'm using Lucid 10.04.2 here, and needed to change the installation line to :

sudo apt-get install libcurl3 dkms libqt4-network libqtgui4 libxslt1.1 libasound2 libdirectfb-1.2-0 libgl1-mesa-dri libgl1-mesa-glx libqt4-opengl libsysfs2 libts-0.0-0 libxcursor1 linux-headers-`uname -r` libxdamage1 libxfixes3 libxmu6 libxxf86vm1 tsconf libqtcore4 libaudio2 libmng1

Otherwise, excellent post. Thanks very much for sharing.

Ian Schwartz said...

I also had a dependency that was missing 'libxinerama1'

also with the line:
VBoxManage createvdi -filename ~/.VirtualBox/Machines/io/sda.vdi -size 48000 -register

I had to leave off the '-register' it wasn't a recognized tag...

One question, are these auto starting on boot, if not how would you do that?

Brett said...

Thanks Ian, VirtualBox is something of a moving target, they keep changing the way it works and a lot has changed since this was posted.

I don't believe that virtualbox has the ability to start automatically but it should be relatively simple to put a script in /etc/init.d or simply add a line to your /etc/rc.local file to start it up.

I've moved to using KVM which is a lot easy to manage in headless scenarios.