Official website for Linux User & Developer
FOLLOW US ON:
Nov
3

Build a headless virtualisation server

by Rob Zwetsloot

Use VirtualBox on a headless server to create and manage remote virtual machines that can be accessed from anywhere

Virtualisation tools are now pretty much ubiquitous. This is thanks to current technology and the power of modern computing allowing for host-like performance with the right setup. And, of course, virtualisation is especially useful in the cloud. Whether you’re testing distros, software compatibility, or any number of other tasks, a virtual machine can help you make the most of your time.

While host performance is not too difficult these days, it can still take a toll on the host system if you’re wanting to multitask. You also may not have the resources on your main PC to get decent performance, let alone host. If you have access to a powerful server, though, and want to take advantage of this resource, you can set it up to run virtual machines from the terminal.

Using headless VirtualBox over SSH, you can easily install, modify and run virtual machines which you can then connect to via RDP. You can even manage them via a web interface to make the process a little more human. A lot of these commands will work for any machine, so if you like to do as much as possible in the terminal, you can pick up a few tips from this tutorial.

Step by Step

Virtual Machine VM qemu
Download VirtualBox

Step 01

Virtual Install

Install VirtualBox to your server.
The website offers binaries for most major distributions, and some distros have it in the repository. For Debian-based distros, you may have to add the official Virtual Box repo:

deb http://download.virtualbox.org/ virtualbox/debian [distro] contrib

…with ‘[distro]’ replaced by your version of Ubuntu, eg ‘precise’.

Step 02

Virtual Extensions

It’s best to get the extensions set up now. Download them using wget:

$ wget http://download.virtualbox.org/virtualbox/4.1.22/Oracle_VM_VirtualBox_Extension_Pack-4.1.22-80657.vbox-extpack

Make sure it’s the latest version, and that it matches up with the version you have.

Step 03

Extension install

Once that’s downloaded, you can unpack it and install it to VirtualBox using this command:

$ sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack- 4.1.22-80657.vbox-extpack

Again, make sure you use the correct version of your extension pack that you downloaded.

Step 04

Add User

We’ll need to add the relevant user to the VirtualBox user group. To do this we have to use something like this:

sudo adduser administrator vboxusers

…where ‘administrator’ is the user you’ll be connecting to the headless server with.

Step 05

Virtual create

To begin with, we’re going to be using the VboxManage tool to start creating and modifying virtual machines. Our first command will be:

$ VBoxManage createvm --name “Name of VM Here” --register

In our example we’re going to be using a Fedora virtual machine.

Step 06

Virtual modify

We’re going to now add some system information for the VM:

$ VBoxManage modifyvm “Fedora 17” --memory 1024 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0

We’re setting the memory to 1024MB above, as well as setting the boot priority to disc first.

Step 07

Virtual storage

Time to set up a virtual hard drive for our new VM to use. Create it using a command like this:

$ VBoxManage createhd --filename Fedora_17.vdi --size 10000

…where 10000 is the amount of storage in megabytes, so roughly 10GB in this example.

Step 08

Virtual IDE

The hard drive needs to be attached to the VM, and to do this the VM needs to have an IDE controller attached to it. We add one like this:

$ VBoxManage storagectl “Fedora 17” --name “IDE Controller” --add ide

We can also use this to add a virtual optical drive for the installation medium.

Step 09

Virtual attach

Attaching the hard drive requires a little more info than just pointing it towards the VDI:

$ VBoxManage storageattach “Fedora 17” --storagectl “IDE Controller”
 --port 0 --device 0 --type hdd --medium Fedora_17.vdi

The ports and type are important to remember when adding further virtual devices.

Step 10

Virtual DVD

Finally, attach the installation medium to your virtual machine:

$ VBoxManage storageattach “Fedora 17” --storagectl “IDE Controller”
 --port 1 --device 0 --type dvddrive --medium fedora17.iso

Port 1 is the first port after the hard drive.

Pages: 1 2
  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.
    • sandra

      Hello,
      I discovered your site via facebook.
      your journey is immeasurable copy your courage.
      You have touched me, and I’m admiring,
      I commend you for all your work and I wish you a bright future full of colors

      vrai voyante

    • Tom

      I do this at home and it works great.
      However, at work, I do not add the extension pack. It is free for personal use, but you must license it for business use.

      The only time & need the RDP access is to get to the BIOS and startup messages from the VM. Once the VM is up, I can RDP/SSH or remotely access the VM’s remote services. For the few cases when I need to debug the BIOS, I’ll have to login to the host and run the VirtualBox GUI. Once the startup is debugged, I can go back to the headless startup.

    • http://www.mentesanas.com David

      Hi Rob,

      While using your very detailed instructions in a new install of Ubuntu 12.04 LTS I am getting an error in
      Step 5, Virtual Create

      when I attempt to enter this line in terminal:

      $ VBoxManage createvm –name “Name of VM Here” –register

      May I ask what alternatives other than “Fedora 17″ are possible instead of “Name of VM Here” as using
      Fedora 17 leads to this message:

      Oracle VM VirtualBox Command Line Management Interface Version 4.1.12_Ubuntu
      (C) 2005-2012 Oracle Corporation
      All rights reserved.

      Usage:

      VBoxManage createvm –name
      [--ostype ]
      [--register]
      [--basefolder ]
      [--uuid ]

      Syntax error: Invalid parameter ’17″ invalid

      Regards
      David

    • Pingback: Links 6/11/2012: OEMs Explore Linux (HP Included), Linux 3.7 RC4 is Out, Red Hat Explores China, GNOME 3.8 Features Outlined | Techrights

    • Pingback: Create a headless virtualization server « 0ddn1x: tricks with *nix

    • Anon Y Mouse

      Try: $ VBoxManage createvm –name “Fedora17” –type –ostype Linux –register

      My experience indicates space characters are not allowed in the name of the VM. Also, if you want the VMs installed somewhere other than the home subdirectory of the user you should add –basefolder /srv/VirtualBox/ (for example).

    • Dan White

      Great subject Rob.

      Here are some additional commands I use:

      # Modify the NIC type, to one which supports PXE booting
      VBoxManage modifyvm ldap –nictype1 Am79C973

      # Configure a MAC address for the NIC – Useful for DHCP environments with host statements
      VBoxManage modifyvm ldap –macaddress1 080027000001

      # Power it up
      VBoxManage startvm “ldap” –type headless

      # Verify it’s running
      VBoxManage list runningvms

      # Power off a VM
      VBoxManage controlvm “ldap” poweroff

      # Delete a VM *** Warning, this will delete your VM’s data ***
      # Useful in testing environments, where you might wish to automate creating, testing, and removing a VM
      VBoxManage storageattach ldap –storagectl sata0 –device 0 –port 0 –type hdd –medium none
      VBoxManage unregistervm ldap –delete
      VBoxManage closemedium disk /.VirtualBox/HardDisks/ldap-root.vdi –delete

      Combined with Fai Server, VirtualBox headless makes for an excellent automated testing rig.