Remote Server Virtualization with VBoxHeadless

VirtualBox is an excellent tool for running a virtual machine either for testing or production environments.  The default setting, however, is for a desktop computer, requiring a graphical interface to run it.  On your Linux server, there usually is no graphical interface.  For that reason, VirtualBox has a feature called VBoxHeadless, which allows you to use the virtualization software from the command line.

Using VBoxHeadless, you can start a virtual server within your currently running server.  It supports a wide range of operating systems and has the same basic features you can find in the graphical interface.

To create a virtual machine, run the following command:

VBoxManage createvm --name "CentOS" --register

It should give you an output that looks like this:

Virtual machine ‘CentOS’ is created and registered.
UUID: 712fd001-e65c-4232-882f-e24b4ce6dec5
Settings file: ‘/home/user/VirtualBox VMs/CentOS/CentOS.vbox’

You can then apply settings to the new virtual machine to suit your needs.  For a list of all of the options, type:

VBoxManage --help

Here is an example of a command string:

VBoxManage modifyvm "CentOS" --memory "1024" --acpi on --boot1 dvd --nic1 nat

You will also need to create a virtual hard disk with this command:

VBoxManage createhd --filename "CentOS.vdi" --size 10000 --remember

Like other virtualization software, VirtualBox allows you to create an actual working environment for a virtual server.  This means that, if you allow it, a user could even SSH into a virtual machine and use it without any indication that it is not a server all by itself.  For more complete information about setting up VBoxHeadless, see this tutorial.