Using VirtualBox as a Cloud Computing Server

For when you really just don’t want to pay for vSphere

Outline

  • Introduction
  • Requirements
  • Part 0: Installing VirtualBox and Extension Pack on the Command Line
  • Part 1: Creating and Deleting a VirtualBox VM using “VBoxManage”
  • Part 2: Enabling RDP access for a VirtualBox VM
  • Part 3: Additional Considerations

Introduction

When I was pursuing my undergraduate degree in IT, one of my favorite classes taught me about how cloud computing services worked behind the scenes. The best part was the group project I spent far too much time on. The class was split up into teams and given computers and networking equipment. Each team had to use these to create an AWS-like service on the local network to allow the creation and use of virtual machines over the network.

Because I didn’t want to be a burden to the folks on my team, I decided to start the project a little early and found out that Oracle’s VM VirtualBox had all the features we needed in the backend to our virtualization server: the automated creation of VMs with scripting, easy networking of virtual machines to allow SSH connections, and the ability to display VMs over the network using RDP.

In the following weeks, I created a prototype to show my team including a simple web interface. From then on, I became the main programming/web design guy and wasted hours and hours on features such as: web authentication, copying VMs, getting SSH to work with port forwarding, automating Windows 10 installation, and many more ideas (and dead ends). However, I learned so much about programming, scripting, and Oracle VM VirtualBox that I treasure the experience to this day. It is this experience that I wish to discuss today.

In this blog/tutorial, we will go over the commands needed to automate the creation of a VirtualBox VM using basic shell scripting.

Requirements

A non-virtual computer with, ideally,:

  • Several cores
  • More than 8 GB of memory
  • Plenty of hard drive space
  • Ubuntu 16 or later installed
  • VirtualBox installed with the appropriate version Extension Pack

Part 0: Installing VirtualBox and Extension Pack on the Command Line

If you don’t have VirtualBox installed, here is how to do it on the command line in Ubuntu/any distro that use the apt package manager.

We first update then install VirtualBox which is in the basic Ubuntu repositories. Then we download the right version of the Extension Pack and install it, automating the license agreement. Then, we uninstall an extension that will cause issues in allowing RDP access later unless it is removed.

Part 1: Creating and Deleting a VirtualBox VM using “VBoxManage”

There are many parts to creating a virtual machine and much more than is here can be learned at the official Oracle VM VirtualBox manual, particularly Chapter 8.

  • The first step is creating an XML virtual machine definition file.

This command will create a new directory called “VM_NAME” with the chosen basefolder used as the parent and will create the “*.vbox” settings file. Remember to use an absolute path for the “basefolder” argument or else VirtualBox might use a folder in the ~/.config directory.

  • The second step is setting a few basic options on the VM such as CPU, RAM, VRAM, and setting time to UTC.

The few settings set here can be changed easily and chained into the same command. View more settings you may want to set here at Chapter 8 of the manual.

  • The third step is to create a virtual hard drive and storage contoller and then attach the storage to the VM.

The absolute path can be anywhere where you want the the virtual hard drives to be stored. Additionally, the size here of 10 GB (10000 MB) is customizable. Learn more here with the “createmedium” command which “createhd” internally maps to.

  • The fourth step, techincally optional, is to add an IDE controller to the virtual machine and attach an ISO file to be booted at startup.
  • Finally, you can start the VM.

The image below shows a black screen, but this is because I am running my server inside a VM and it showed me an error. I blacked out the error by hand, but it will definitely work for you.

  • To delete the VM, power it off, unregister, and delete all its files.

Part 2: Enabling RDP access for a VirtualBox VM

To create a RDP-ready VM, start by following Part 1 but DO NOT power on or delete the VM.

NOTE: Remember to disable firewall rules that block access to the port through which you wish to RDP to your virtual machine.

  • With the VM created and ready to be powered on, modify the VM settings to to enable RDP access.
  • Now start the VM headless (without a window).
  • Now, from a different computer on the same network, attempt an RDP connection with software like Remmina Remote Desktop Client. Again, I blacked out an error on the image below, but as you can see, the RDP server is working and shows what you would see on a booted VM.

Part 3: Additional Considerations

Some firewall rules will need to be created to allow RDP connections and security may become an issue for you. Additionally, SSH security will need to be taken into account if you plan on installing an SSH server on any of your VMs (this will require port forwarding on the host machine to work and is easy to set up using “VBoxManage”, check here at Chapter 7). Finally, you may want a web interface to pull everything together and allow easy access to people on the network. This can be done with software like phpvirtualbox (https://github.com/phpvirtualbox/phpvirtualbox) or, with my very own creation, virtualflask (https://github.com/skatt621/virtualflask). Virtualflask requires nothing except an Ubuntu 16+ machine to be set up and comes with an easy setup script and easily editable web pages and code. Development is still active and the “Create New VM from Template” feature still needs testing.

A man with a passion for information technology.