Home > Linux / Unix, Software, Tutorial, Ubuntu > How to setup headless Sun xVM VirtualBox on Ubuntu server

How to setup headless Sun xVM VirtualBox on Ubuntu server

The steps are not too difficult but I did have to find a few places for information. Search on the forum turn up nothing on this subject so hopefully this HOWTO would be helpful to someone out there.

Note: This is not using the OSE version.

VirtualBox has a very good GUI running on the host to manage guest OS. However when running a server, we typically do not want to run X on it. Fortunately VirtualBox has commandline tools to manage guest systems. It also provides the VirtualBox Remote Desktop Protocol (VRDP) to allow connection to the guest remotely.

Clarification of terms used:
Host – refers to the machine we are trying to install VirtualBox.
Guest – the VirtualBox guest system that is setup on the host.
Remote – the PC that we are working on to connect to the host via SSH.

This setup was done on a fresh install of Ubuntu Server 8.04 with openssh-server installed.

All the following steps are done by SSH into the host from a remote (I’m using Windows for now).

1. Get required packages
Download the Ubuntu package for VirtualBox from http://www.sun.com/software/products/virtualbox/get.jsp

wget "download link here" -O virtualbox_1.6.2-31466_Ubuntu_hardy_i386.deb

We are using the non-OSE version here.

The manual from http://www.virtualbox.org/wiki/Downloads is also very useful.

2. Installation

sudo dpkg -i virtualbox_1.6.2-31466_Ubuntu_hardy_i386.deb

This will generate a bunch of dependencies. Fix them with

sudo apt-get -f upgrade

3. Decide on user, disk files location

First decide which user you want to run VirtualBox. Add this user to the vboxusers group.

sudo usermod -a -G vboxusers vboxuser

By default VirtualBox creates the directory .VirtualBox on the user home directory and put all the config and disk file there. In my setup, I put the disk files in /var/vbox as I had created a large partition for this purpose.

4. Install a guest OS

You will need an iso for the guest OS install CD. Copy or download it to the host. For example we will just use ubuntu-8.04-server-i386.iso

-create a vm

VBoxManage createvm -name ubuntu -register

-config vm

VBoxManage modifyvm ubuntu -memory "256MB" -acpi on -boot1 dvd -nic1 nat

-create a disk

VBoxManage createvdi -filename "/var/vbox/ubuntu.vdi" -size 5000 -register

-add disk to vm

VBoxManage modifyvm ubuntu -hda "/var/vbox/ubuntu.vdi"

-register an install iso

VBoxManage registerimage dvd /var/vbox/ubuntu-8.04-server-i38.iso

-mount iso on vm

VBoxManage modifyvm ubuntu -dvd /var/vbox/ubuntu-8.04-server-i38.iso

-start the vm with port

VBoxHeadless -startvm ubuntu -p 3389 &

If you are running just 1 guest, the -p 3389 is optional. For more than 1 guest, it has to listen to different port.

5. Connect from remote

Since my desktop is still Windows, I use Remote Desktop Connection. (On XP, Start>All Programs>Accessories>Communications)

For Mac, use http://www.microsoft.com/mac/products/remote-desktop/
For Ubuntu, look at http://ubuntuforums.org/showthread.php?t=824710

Just fill in the IP of your host (or IP:port if not the default) and you should see the Ubuntu installation waiting for you.

Other useful commands:

VBoxManage controlvm ubuntu poweroff
VBoxManage controlvm ubuntu reset

Getting Ubuntu Server to run in VirtualBox

After installation and restarting, you may find that the boot up hang with this error

This kernel requires the following features not present on the CPU: 0:6

To fix this, do the following:

  1. Reset the guest
  2. Hit F12 to choose to boot from the CD. (It goes by pretty quickly, reset again if you miss it.)
  3. Select Rescue a broken system
  4. After going through the install screens you will get a command prompt. Select to run it on the root system.
  5. Install the virtual linux-virtual kernel
apt-get install linux-virtual

6. Reboot and this should fix the restart.

Upgrading kernel
If the kernel on the host is upgraded, the VirtualBox kernel module need to be re-compiled. Do the following steps:

  1. apt-get install make gcc linux-headers-2.6.24-19-server (other kernel header, check uname -a)
  2. /etc/init.d/vboxdrv setup

It should recompile the VirtualBox module and everything should be working again.

[ Source: kcnnc from Ubuntu Forum ]

  1. Ron Sebastian
    September 5, 2008 at 11:17 am

    Enabling PAE/NX on virtualbox solved my ubuntu server boot error.

  2. max
    September 5, 2008 at 5:40 pm

    thanks for all steps of this process

  3. September 5, 2008 at 8:48 pm

    @Ron Sebastian: Correct, by enabling the PAE/NX it will solve the boot error.

  4. September 12, 2008 at 4:16 pm

    @Ron Sebastian & max: Just to confirm: The exact same thing is mentioned in section of the VirtualBox manual under “Enable PAE/NX”. It explicitly mentions Ubuntu Server as an example.

  5. October 26, 2008 at 10:05 am

    This is a good tip but by Virtual OS becomes very unstable, crashes very frequently. greetings

  6. Jay
    October 30, 2008 at 5:10 pm

    Interesting tutorial! I just install one in my server and now waiting for my 1st vm installation to finish. What I don’t understand, why you don’t use the supplied debian package? I put virtualbox repository and install one using apt-get and so far found no problem..

  7. Justin
    February 28, 2009 at 7:38 pm

    Thanks for this awesome tutorial!

    One quick question,

    When running the VBoxHeadless -startvm command, my ssh session sits on the command. if I press ctrl-C, it exits…

    How do get it start the vm, then run it in the background?


  8. JF
    April 8, 2009 at 2:45 am

    Justin :

    Just add & at te end of your command line to tell linux to run the process in background; this way you will keep you session. Alternatively use ctrl-z instead of ctrl-c this will pause the process end give you the session back. In order to restart the process un bacground just type bg and press enter. bg will tell linux to resume the last stoped process in background.

    You might want to look into the following man pages : fg, bg, jobs

    Hope this helps !

  9. RDF
    May 11, 2009 at 3:03 pm

    No, don’t use ‘&’ or Ctrl-Z, that’s not a good way to put things in the background if you want to disconnect.

    Use ‘screen’ instead, like this (I’ve made the prompt reflect where the commands are issued. “screen” means “inside the screen session).

    local> ssh user@remote
    remote> screen
    screen> VBoxHeadless [args]

    Now, “Ctrl-A Ctrl-D” will disconnect from the screen session, and all the processes you started in the screen session will think they are still connected to a controlling terminal.

    Say you now want to reconnect to the server:

    local> ssh user@remote
    remote> screen -r

    This will reopen the existing screen session. If you have the screen session open from somewhere else, you might have to give the command “screen -rd” to “steal” the session.

    You can also use the following useful commands:

    – Ctrl-A C creates a new screen shell in addition to the one you are already in (say, for starting a new VirtualBox instance);
    – Ctrl-A N goes to the next screen shell;
    – Ctrl-A P goes to the previous one

    Some caveats:

    – If you’re used to emacs key bindings, screen steals these (Ctrl-A for start of line will no longer work). You can reconfigure the bindings to avoid this.
    – Try not to forget you’re in a screen session, because it’s possible to get all confused and try to steal your current session from within the session and there will be much scratching of heads.
    – Inside a screen session, connecting to a remote server via ssh and using screen there will also confuse you, as Ctrl-A N will switch to the next local session, not the next remote session.

    Hope this helps. The easiest way to learn about screen is just to dive in and try it out.

  10. August 4, 2009 at 5:16 pm

    how to fill provide real ip to the virtual box in headless environment 😐

  11. moodsey211
    August 18, 2009 at 2:03 pm

    Configure it using bridge network.

    For example:

    VBoxManage modifyvm myvm –nic1 bridged –bridgeadapter1 eth0

    where myvm is a registered vm. I’m currently using 3.X and I don’t know if this would work to versions before 3.X

  12. Limey Guy
    August 28, 2009 at 1:37 am

    When you do ‘sudo apt-get -f upgrade’ doesn’t that install all the missing dependencies, i.e. all the X stuff that you don’t want on the headless server?

  13. static
    April 18, 2010 at 1:35 am

    @Limey – no only libs for qt (fortunately)

  14. May 3, 2010 at 11:22 pm

    I like this content so much.Imagination is more important than knowledge.

  15. Marwelln
    July 5, 2010 at 4:26 am

    Fucking kernel ruins everything. Both for this VirtualBox and for VMware.

  16. April 7, 2011 at 10:44 pm

    A very helpful article.II’ll bookmark your weblog .

  17. agrdsn
    May 8, 2011 at 10:04 pm

    it’s not work.
    how could the guest OS obtain an IP Address without gui.
    even it run on CLI, you have to determine first the IP address.
    without ip address you can’t access remotely both vnc and vrde.
    any solution bro?

  18. November 22, 2011 at 7:11 am

    Thanks for a great article. I’m curious…

    How would one go about making the headless server start the guest without any interaction on startup? I would like my VMs to start automatically if the host server needs to be rebooted, but this article would suggest that “VBoxManage -startvm” needs to be run in a logged-in user’s userspace.


  19. December 25, 2014 at 4:30 pm

    I must thank you for the efforts you have put in penning this website.
    I really hope to view the same high-grade content by you later on as well.
    In truth, your creative writing abilities has motivated
    me to get my very own site now 😉

  1. June 13, 2010 at 1:08 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: