VirtualBox 4.1 & phpVirtualBox on Ubuntu 10.04 LTS Server

This is a HOWTO on setting up Headless VirtualBox 4.1 (PUEL optional) with a GUI web based front-end using phpVirtualBox on an Ubuntu 10.04 Long Term Support (LTS) Server.

If you haven’t used it, phpVirtualBox is totally slick. It’s very nearly as good as the regular VirtualBox graphical user interface, but without needing all that X-windows fluff to support it.

Unless noted otherwise, I’m doing everything as the ‘root’ user, yeah, yeah, I know that’s “bad”, but I’m lazy, and prefixing “sudo” to everything just gets annoying.

user@vbox:~$ sudo su -

Make sure you are running the latest 10.04 LTS release.

root@vbox:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.04.2 LTS
Release:        10.04
Codename:       lucid

We’re not quite up to date, so lets address that first

root@vbox:~# apt-get update
root@vbox:~# apt-get upgrade
root@vbox:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.04.3 LTS
Release:        10.04
Codename:       lucid

OK, good deal. At the time of writing Ubuntu 10.04[.3] is the current LTS release (and will be supported until April 2015).

phpVirtualbox is very light weight, it doesn’t even need MySQL, and technically doesn’t even need to run on the same machine as VirtualBox, but I’m going to install all the LAMP stuff just to have anyhow

root@vbox:~# apt-get install lamp-server^

The caret “^” character on the end there isn’t a typo, it’s required for that faux package name to work.

Edit /etc/apt/sources.list (I normally use vim, but I used nano here to be friendly)

root@vbox:~# nano /etc/apt/sources.list

Add the following lines to your sources.list, you can put them pretty much anywhere in the file you like provided they start on a new line.

#From https://www.virtualbox.org/wiki/Linux_Downloads
deb http://download.virtualbox.org/virtualbox/debian lucid contrib non-free

You’ll also want to add VirtualBox/Oracle’s public key to your apt-key ring

root@vbox:~# wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

Now update, update again, Muhahah!

root@vbox:~# apt-get update
root@vbox:~# apt-get dist-upgrade
root@vbox:~# apt-get install virtualbox-4.1 linux-headers-`uname -r` dkms unzip

Those are backticks around the “uname -r” statement up there, not single quotes. It’s just to make sure you get the linux-headers for the version you’re running is all

Optionally you can download the Extension Pack, this gives you neat stuff like USB 2.0 support and RDP access to your VM’s boot screen. You probably want this if it’s for personal use, if you have a license or if you are “evaluating” the software indefinitely (I have yet to see how long they consider a reasonable evaluation period, but we’re probably supposed to be nice).

Make sure you get the right version of the Extension Pack, double check by looking at https://www.virtualbox.org/wiki/Linux_Downloads

You can see what version of VirtualBox got installed like so:

root@vbox:~# VBoxManage --version
4.1.4r74291

We can probably simliarly grab the needed Extension Pack like we did with the kernel-headers

root@vbox:~# cd ~
root@vbox:~# vbox_ver="`VBoxManage --version`"
root@vbox:~# wget "http://download.virtualbox.org/virtualbox/${vbox_ver%%r*}/Oracle_VM_VirtualBox_Extension_Pack-${vbox_ver/r/-}.vbox-extpack"

That’s a little more confusing, we have the backticks again of course, then the VBoxManage –version we saw gives us the version number. The variable “vbox_ver” stores this information so we can use it again later. When the variable is referenced as ${vbox_ver%%r*} only the version information before the ‘r’ is used, for example a version of “4.1.4r74291” would result in “4.1.4”. Referencing the variable as {vbox_ver/r/-} replaces the ‘r’ with a hyphen as that’s how the file is named (without the ‘r’) on the server.

Now to add the Extension Pack to VirtualBox

root@vbox:~# VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-${vbox_ver/r/-}.vbox-extpack

Now we should make a user that will run VirtualBox, since the same people that want me to ‘sudo’ everything really don’t want me to run all programs setuid 0.

root@vbox:~# adduser virtualbox
Adding user `virtualbox' ...
Adding new group `virtualbox' (1002) ...
Adding new user `virtualbox' (1002) with group `virtualbox' ...
Creating home directory `/home/virtualbox' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for virtualbox
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

Now add the ‘virtualbox’ user to the vboxusers group (created by the VirtualBox deb installation)

root@vbox:~# adduser virtualbox vboxusers

Now we’re going to install phpVirtualBox. I’m going to put it right into the main web directory so it’s the default web site, but you’ll want to make a new directory for it if you already have a website on this computer. Also you should go to http://phpvirtualbox.googlecode.com/ and see if there is a newer version of the software instead of the one I use below. Keep in mind that there are currently two branches of the phpVirtualBox code, one for 4.0.x compatible VirtualBox installations and one for 4.1.x compatible. There’s actually one for 3.2.x compatible as well which you’ll probably want if you just ran “apt-get install virtualbox-ose” without following this guide.

root@vbox:~# cd /var/www
root@vbox:~# mkdir backup ; mv * ./backup # this is for dumb people that copy and paste blindly
root@vbox:~# wget http://phpvirtualbox.googlecode.com/files/phpvirtualbox-4.1-4.zip
root@vbox:~# unzip phpvirtualbox-4.1-4.zip
root@vbox:~# mv ./phpvirtualbox-4.1-4/* .
root@vbox:~# rmdir phpvirtualbox-4.1-4
root@vbox:~# rm phpvirtualbox-4.1-4.zip

All that’s left to phpVirtualBox is setting up the config

root@vbox:~# mv config.php-example config.php
root@vbox:~# nano config.php

Find this section and replace with the username and password you created during the adduser step

/* Username / Password for system user that runs VirtualBox */
var $username = 'virtualbox';
var $password = 'passw0Rd is secret and cleartext';

As part of the virtualbox deb package the script /etc/init.d/vboxweb-service should have been installed. We need to create a configuration file for use with the vboxweb-service init script that will supply the username of our virtualbox user.

root@vbox:~# nano /etc/default/virtualbox

Add one line:

VBOXWEB_USER=virtualbox

Save the file and exit the editor. Additional /etc/default/virtualbox configuration options can be found here.
If everything worked you should not be able to start and stop the vboxweb-service

root@vbox:~# service vboxweb-service start
 * Starting VirtualBox web service
 *  done.
root@vbox:~# service vboxweb-service stop
 * Stopping VirtualBox web service
 *  done.

OK, that should start the vboxwebsrv as the virtualbox user. You can verify with the command below.

root@vbox:~# ps -U virtualbox
PID TTY          TIME CMD
 2431 ?        00:00:00 vboxwebsrv
 2433 ?        00:00:00 VBoxXPCOMIPCD
 2439 ?        00:00:00 VBoxSVC

You should see the vboxwebsrv command running as well of some of it’s friends.

If you are having problems you can manually start the vboxwebsrv with the following command.

root@vbox:~# sudo -u virtualbox /usr/bin/vboxwebsrv --background

The deb package should have already created system start/stop links for /etc/init.d/vboxweb-service, but if not you can manually create them with the following command:

root@vbox:~# update-rc.d -f vboxweb-service remove
 Removing any system startup links for /etc/init.d/vboxweb-service ...
   /etc/rc0.d/K20vboxweb-service
   /etc/rc1.d/K20vboxweb-service
   /etc/rc2.d/S20vboxweb-service
   /etc/rc3.d/S20vboxweb-service
   /etc/rc4.d/S20vboxweb-service
   /etc/rc5.d/S20vboxweb-service
   /etc/rc6.d/K20vboxweb-service
root@vbox:~# update-rc.d vboxweb-service defaults
 Adding system startup for /etc/init.d/vboxweb-service ...
   /etc/rc0.d/K20vboxweb-service -> ../init.d/vboxweb-service
   /etc/rc1.d/K20vboxweb-service -> ../init.d/vboxweb-service
   /etc/rc6.d/K20vboxweb-service -> ../init.d/vboxweb-service
   /etc/rc2.d/S20vboxweb-service -> ../init.d/vboxweb-service
   /etc/rc3.d/S20vboxweb-service -> ../init.d/vboxweb-service
   /etc/rc4.d/S20vboxweb-service -> ../init.d/vboxweb-service
   /etc/rc5.d/S20vboxweb-service -> ../init.d/vboxweb-service

Congrats, you should be done now. Point a web browser (presumably from a workstation on your network) to your virtualbox server and login as
admin with the password admin. You can change this password once your logged in from the “File” menu (File -> Change Password).

To figure out what the IP address is of your virtualbox server (you really should know this already):

root@vbox:~# ifconfig

There ya go, nice and easy, almost copy and paste like.

Enjoy
-Chris

Troubleshooting

If you are using, or have used KVM the Kernel-based Virtual Machine it does not play nice with VirtualBox, and you’ll need to unload the kernel module before using VirtualBox. Provided you aren’t using KVM currently, give the following a try:

root@vbox:~# rmmod kvm-intel
root@vbox:~# rmmod kvm-amd
root@vbox:~# /etc/init.d/vboxdrv setup

If that helps, and you won’t be using KVM, you can add it to the blacklist

root@vbox:~# nano /etc/modprobe.d/blacklist.conf

Then add the following lines:

blacklist kvm-intel
blacklist kvm-amd
This entry was posted in System Administration. Bookmark the permalink.

3 Responses to VirtualBox 4.1 & phpVirtualBox on Ubuntu 10.04 LTS Server

  1. Joe Febrian says:

    Hai Ethertubes.com.
    vboxwebsrv: error: could not get base directory for logging, i’m stack in now this, can do you help me ?

  2. Eric Janz says:

    Hi,

    congratulatulations for this great HOWTO.

    Just one thing you most likely already know.
    There is already a startup script: /etc/init.d/vboxweb-service
    (at least at Virtualbox version 4.1-7)

    To get it working, you must create the file:
    /etc/default/virtualbox and put inside the username under which the vboxwebsrv will run like this:

    VBOXWEB_USER=virtualbox

    I also found that you must create inside the virtualbox’s home directory the directories .VirtualBox/HardDisks and .VirtualBox/Machines if they are not already there (and of course you did not change the default setups)

    Best regards and congrats again!
    Eric

  3. Chris says:

    Thanks for the comment Eric. I overlooked this. Strangely my /etc/init.d/vboxweb-service looks for /etc/vbox/vbox.cfg though, I’ve updated the HOWTO to reflect that. I’ll likely redo this guide for 12.04 with the latest Virtualbox (not that I expect much has changed). /etc/default/virtualbox would be a more consistent debian-way to do things, I’m not sure why my script differs:

    [ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg

    OH! Nevermind, it looks like further in it looks for /etc/default/virtualbox as well, so apparently either will work. I’ll update the HOWTO again to use /etc/default

    [ -r /etc/default/virtualbox ] && . /etc/default/virtualbox

    Thanks,
    Chris

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.