HOWTO: Ubuntu VirtualBox Server
In: Linux|VirtualBox
Written by: Taylor Gerring
24 Aug 2008 Not long ago, I took upon the task of setting up a dedicated virtualization server. I knew I wanted to maximize hardware by keeping the OS slim, so I decided to go with my Linux distro of choice: Ubuntu. This works out very well, because the current version is a Long Term Support release, which means I’ll have access to security patches for a full 5 years. As for the actual virtualization software? There are multiple choices for Linux, but I really liked several aspects of VirtualBox: cross-platform support, the VRDP feature, and I had already been running it in a headless configuration on Windows. For your enjoyment, I documented the entire procedure. So here goes:
UPDATE: Please note that a newer version of both Ubuntu and VirtualBox have superseded those used in this HOWTO. Specifically, VirtualBox 2.1 includes substantive changes to host networking.
UPDATE 2: I having (finally) posted a new guide, utilizing Ubuntu 9.10 Karmic Koala and VirtualBox 3.1.2. As this HOWTO is sorely out-of-date, please follow Ubuntu VirtualBox Server Redux
- Download and install Ubuntu Server 8.04.1 x64.
Installation is outside the scope of this post, but it is very simple – just follow the wizard-style prompts. When prompted on which packages to install, select only SSH Server. When selected for a user, enter “vboxuser”, as this is the username I will reference the guide.
After installation is complete, feel free grab a laptop and cold drink. We can now SSH directly into the server. Windows users can download PuTTY to connect. Mac and Linux users should be able to just “ssh vboxuser@servername” from the terminal directly. - Get latest updates
sudo apt-get update
sudo apt-get upgrade
- Reboot. You will likely get a new kernel version, which requires a reboot.
- Install required packages
All packages should be able to be done all at once, but this is the order that I performed them.sudo apt-get install linux-source elinks
sudo apt-get install make gcc build-essential
sudo apt-get install linux-headers-$(uname -r)
- Download VirtualBox
You have an option here. If you are happy with the open source edition of virtualbox, you can get them from the repositories. Because I want VRDP, which is only available in the pre-built binaries, I downloaded directly from Sun.- Navigate to the download link for the x64 version.
- Download VirtualBox. As of the writing of this guide, the current was version was 1.6.4
- Install VirtualBox
sudo dpkg -i virtualbox_*.deb
- Ignore the warnings that dpkg throws out. We’ll fix them in the next step
- Fix the broken dependencies
- Add vboxuser to the “vboxusers” group
sudo usermod -a -G vboxusers vboxuser
- Log out and log back in as vboxuser. This is so that the new group is picked up.
- Change permissions on TUN/TAP driver
This allow us to start up the virtual machines as a normal usersudo chown root:vboxusers /dev/net/tun
- Create virtual interfaces
Because I had 3 VMs, I created an extra interfaces for room to growsudo VBoxAddIF vbox0 vboxuser
sudo VBoxAddIF vbox1 vboxuser
sudo VBoxAddIF vbox2 vboxuser
sudo VBoxAddIF vbox3 vboxuser
- Update network settings
Take special note of the br0 settings. Please match these to your network environment.sudo nano /etc/network/interfaces.conf
- Assuming your physical network card is etc0, match your interfaces.conf to look like mine:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
up ifconfig $IFACE 0.0.0.0 up
up ip link set $IFACE promisc on
down ip link set $IFACE promisc off
down ifconfig $IFACE down
auto vbox0
iface vbox0 inet manual
auto vbox1
iface vbox1 inet manual
auto vbox2
iface vbox2 inet manual
auto vbox3
iface vbox3 inet manual
auto br0
iface br0 inet static
address 192.168.1.40
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge_ports eth0 vbox0 vbox1 vbox2 vbox3
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
- Update DNS configuration
Because we are giving our physical box a static IP address, we should ensure it has DNS entries so that you can still access servers by name.sudo nano /etc/resolv.conf
- My resolv.conf looks like this. If you are not in a domain environment, you may omit the first line that starts with “search”. The rest of the lines are simply my local nameserver and a couple of backup entries that use OpenDNS servers.
search domainname
nameserver 192.168.1.41
nameserver 208.67.222.222
nameserver 208.67.220.220
- Restart networking
sudo /etc/init.d/networking restart
- Create directory for virtual machine disks
- Copy VDI to permanent location
In this particular situation, I am migrating existing virtual machines from Windows Server 2003 to Ubunu Server 8.04.1. Therefore, I already have the virtual disk images I need sitting in my home directory. If you need to create fresh installs, please check the official VirtualBox Documentation.mv ~/Windows XP.vdi ~/.VirtualBox/VDI/Windows XP.vdi
- Create and register your first Virtual Machine
I am creating a Windows XP installation here, but feel free to change as your needs deem. You’ll need to repease this and the next step for each virtual machine.VBoxManage createvm -name "Windows XP" -register
- Set virtual machine settings
Any of these settings can be set individually or in whole. If you’re getting an error, try separating them to determine the problem. A couple other thigns to pay attention to, is the VRDP Port, Hard Drive Image, and Host Networking DeviceWhat does it do?
Memory: 256MB
ACPI: ON
Hardware Virtualization: ON
Physical Address Extension: ON
Hard Drive Image: Windows XP.vdi
VRDP: ON
VRPD Port: 3390
Networking: Host Interface
Host Networking Device: vbox0
VBoxManage modifyvm "Windows XP" -memory 256MB -acpi on -hwvirtex on -pae on -hda "Windows XP.vdi" -vrdp on -vrdpport 3390 -nic1 hostif -hostifdev1 vbox0
- Verify your virtual machine settings
VBoxManage showvminfo "Windows XP"
- Start the virtual machine
VBoxHeadless -s "Windows XP" &
So, I hope that helps. I know the use case is very specific, but I couldn’t find any other guides that spelled out everything that needed to be done. The VirtualBox forums are a great resource, just be sure to search before posting.
1 Response to HOWTO: Ubuntu VirtualBox Server
Ubuntu VirtualBox Server Redux | Idea Excursion
March 16th, 2010 at 11:12 am
[...] VirtualBox and Ubuntu have drastically changed since I wrote HOWTO: Ubuntu VirtualBox Server. In fact, they’ve change to such a degree that the previous article isn’t [...]