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.
Background:
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:
- Reset the guest
- Hit F12 to choose to boot from the CD. (It goes by pretty quickly, reset again if you miss it.)
- Select Rescue a broken system
- After going through the install screens you will get a command prompt. Select to run it on the root system.
- 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:
- apt-get install make gcc linux-headers-2.6.24-19-server (other kernel header, check uname -a)
- /etc/init.d/vboxdrv setup
It should recompile the VirtualBox module and everything should be working again.
[ Source: kcnnc from Ubuntu Forum ]
Enabling PAE/NX on virtualbox solved my ubuntu server boot error.
thanks for all steps of this process
@Ron Sebastian: Correct, by enabling the PAE/NX it will solve the boot error.
@Ron Sebastian & max: Just to confirm: The exact same thing is mentioned in section 3.7.1.2 of the VirtualBox manual under “Enable PAE/NX”. It explicitly mentions Ubuntu Server as an example.
This is a good tip but by Virtual OS becomes very unstable, crashes very frequently. greetings
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..
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?
Cheers
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 !
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.
how to fill provide real ip to the virtual box in headless environment 😐
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
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?
@Limey – no only libs for qt (fortunately)
I like this content so much.Imagination is more important than knowledge.
Fucking kernel ruins everything. Both for this VirtualBox and for VMware.
A very helpful article.II’ll bookmark your weblog .
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?
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.
Thanks!
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 😉