HOWTO: Ubuntu VirtualBox Server

In: Linux|VirtualBox


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

  1. 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.
  2. Get latest updates
    1. sudo apt-get update
      sudo apt-get upgrade
    2. Reboot. You will likely get a new kernel version, which requires a reboot.
  3. Install required packages
    All packages should be able to be done all at once, but this is the order that I performed them.

    1. sudo apt-get install linux-source elinks
      sudo apt-get install make gcc build-essential
      sudo apt-get install linux-headers-$(uname -r)
  4. 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.

    1. elinks virtualbox.org
    2. Navigate to the download link for the x64 version.
    3. Download VirtualBox. As of the writing of this guide, the current was version was 1.6.4
  5. Install VirtualBox
    1. sudo dpkg -i virtualbox_*.deb
    2. Ignore the warnings that dpkg throws out. We’ll fix them in the next step
  6. Fix the broken dependencies
    1. sudo apt-get -f install
  7. Add vboxuser to the “vboxusers” group
    1. sudo usermod -a -G vboxusers vboxuser
    2. Log out and log back in as vboxuser. This is so that the new group is picked up.
  8. Change permissions on TUN/TAP driver
    This allow us to start up the virtual machines as a normal user

    1. sudo chown root:vboxusers /dev/net/tun
  9. Create virtual interfaces
    Because I had 3 VMs, I created an extra interfaces for room to grow

    1. sudo VBoxAddIF vbox0 vboxuser
      sudo VBoxAddIF vbox1 vboxuser
      sudo VBoxAddIF vbox2 vboxuser
      sudo VBoxAddIF vbox3 vboxuser
  10. Update network settings
    Take special note of the br0 settings. Please match these to your network environment.

    1. sudo nano /etc/network/interfaces.conf
    2. 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
  11. 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.

    1. sudo nano /etc/resolv.conf
    2. 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
  12. Restart networking
    1. sudo /etc/init.d/networking restart
  13. Create directory for virtual machine disks
    1. mkdir ~/.VirtualBox/VDI
  14. 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.

    1. mv ~/Windows XP.vdi ~/.VirtualBox/VDI/Windows XP.vdi
  15. 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.

    1. VBoxManage createvm -name "Windows XP" -register
  16. 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 Device

    What 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

    1. VBoxManage modifyvm "Windows XP" -memory 256MB -acpi on -hwvirtex on -pae on -hda "Windows XP.vdi" -vrdp on -vrdpport 3390 -nic1 hostif -hostifdev1 vbox0
  17. Verify your virtual machine settings
    1. VBoxManage showvminfo "Windows XP"
  18. Start the virtual machine
    1. 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.

  • Share/Bookmark

1 Response to HOWTO: Ubuntu VirtualBox Server

Avatar

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 [...]

Comment Form

  • shiva ramani: good instruction. How to push data to MySQL from SQL 2005 [...]
  • Winkey: I've created a linked server for mysql successfully, and also can do Insert, Select. But when I try [...]
  • RaghuRam: Thanks a lot buddy it helped me to change the root password when I got the error trying to c [...]
  • Taylor Gerring: If you're on a 64-bit OS, did you run the 32-bit version of ODBC applet? Run: odbcad32 [...]
  • Taylor Gerring: If the issue is the guest sync'ing to the host, can't you just force time sync the host if you can't [...]


This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States.