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

Step 11

Virtual import

You can reuse an older VM from another machine by importing it into VirtualBox on your server. You’ll need to find the relevant machine in the Machines folder in the VirtualBox directory and copy it over to the new directory. Once that’s done, import it like this:

$ VBoxManage registervm Machines/ examplevm/examplevm.xml

Step 12

Headless start

Now we can start the virtual machine from the headless server using the very useful VBoxHeadless tool:

$ VBoxHeadless --startvm “Fedora 17”

This will also start a VRDP service so that you can remotely access the virtual machine from a networked computer.

Virtual Machine VM QEMU
Connect remotely to your VM

Step 13

Remote connect

You’ll notice that the output from the startvm command will comment on what port it’s listening on, in our case 3389. Some RDP clients might automatically see it, but otherwise if you put in the IP address followed by the port into the client, it should pick it up.

Step 14 Headless options

There are some useful VBoxHeadless commands you can use to control the running VM:

$ VBoxManage controlvm “Fedora 17” poweroff
$ VBoxManage controlvm “Fedora 17” pause
$ VBoxManage controlvm “Fedora 17” reset

The commands are fairly straightforward: they power off, pause and reset the VM.

Step 15

PHPVirtualBox

While managing a headless server from the command line may be good enough for some, the existence of a graphical, web-based management system is useful for everyone. PHPVirtualBox is exactly that. We need to do some prep before we start, though. Make sure you’re root on your server and add a new user:

$ useradd -m vbox -G vboxusers

Create a password for the new user:

$ passwd vbox

Finally, edit the file at /etc/default/virtualbox and enter the following:

VBOXWEB_USER=vbox

This makes sure that the web interface runs as user vbox.

Step 16

Web server

For PHPVirtualBox, we need a web server that supports PHP. If you don’t already have one set up, you should install Apache 2 and PHP 5 on your system. If you’re using different versions of Apache and PHP, the tutorial will still work, though.

Step 17

Download PHPVirtualBox

Now we can download PHPVirtualBox. Move to /var/www and download the latest version of the file:

$ wget http://phpvirtualbox. googlecode.com/files/ phpvirtualbox-4.1-10.zip

Check the website for the latest version

Step 18

Install PHPVirtualBox

Once downloaded, unzip the software and move it:

$ unzip phpvirtualbox-4.1-10.zip
$ mv phpvirtualbox-4.1-10 phpvirtualbox

Move to this new directory and then create the config.php file from the example:

$ cp config.php-example config.php

Step 19

Configure PHPVirtualBox

Open up config.php in a text editor and add the details you need for the web server:

/* Username / Password for system user that runs VirtualBox */
var $username = ‘vbox’;
var $password = ‘password’;

Afterwards, restart the server and you should be ready to go.

VM Virtual Machine QEMU
Log In with PHPVirtualBox

Step 20

Log in

To get to your newly installted interface, enter your server’s IP address followed by /phpvirtualbox: for example, 192.168.1.254/phpvirtualbox. From here you’ll need to log in using the default user admin, with the password ‘admin’ as well. Once logged in, you can change this password.

Step 21

Adding VMs

Much like the standard VirtualBox UI, you can add and modify VMs with a series of menus that guide you through creating a hard drive and adding an installation medium. It will also give the same working prompts to let you know how long it will take when performing tasks.

Step 22

VM console

You have some limited use of the actual VMs thanks to the console view, although it’s not as good as using the RDP method from earlier in the tutorial. Simply launch the VM from the web browser and click Console. You can also launch from the web browser and connect via VRDP.

Step 23

Advanced use

Pretty much anything you can do in the standard graphical interface is available in the web interface – including attaching and detaching drives, and importing virtual machines from other places. Of course, you don’t have to abandon the command line if there are specific operations you want to do from there.

Step 24

Headless VMs

You now have a fully operational, and fully featured, headless virtualisation server. There’s plenty more you can do with this setup, which you will be able to discover over time, but for now you should notice no difference from using it locally.

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.