Bobbie Smulders Freelance Software Developer


During a recent cleaning of my workstation’s operating system, I noticed that I had quite a few background applications running. These applications ranged from Apache, MySQL, PHP, GlassFish to some downloading applications. All of these applications are running all the time and clutter the file-system, the workstations’s performance and the launch-daemons. So what did I do about it?

I created a couple of small virtual machines. One to host Apache with MySQL and PHP, one to host my build-server, one to host my downloading applications. When I want to do some web-development, all I have to do is start one of the virtual machines and the server is fully functioning in about 10 seconds.

So what are the advantages of such a system?

  • Portability: I can easily copy these virtual machines to any of my workstations or servers
  • Seperation of responsiblity: Each virtual machine has its own purpose
  • Safety: I can return to a snapshot when I want to undo a certain change
  • Storage: It is very easy to move the application storage to a different location
  • Development: Extremely easy to use DTAP by cloning virtual machines

The only disadvantage is the fact that a virtualized server will use more resources compared to a background process, but I can easily turn off virtual servers when I don’t need them. With my usage, the virtual servers are a clear winner.

I want to give a few pointers on how I configured my system:

Use headless virtualization
I used VirtualBox to create and host the virtual machines. Compared to Vmware and Parallels it may not have the most advanced features, but I find the fact that it’s stable, fast and free very important.

After creating a virtual machine, I can start it headless (without a GUI) by using:

VBoxHeadless -s [nameofserver] &

I usually shut the machines down using SSH, but you can also use VirtualBox to send an ACPI signal (similar to pressing the power button on a computer) by using:

VBoxManage controlvm [nameofserver] acpipowerbutton

When using Ubuntu Server on the virtual machine, you do need to install the ACPI event daemon to get this working. This is very simple using APT:

sudo apt-get install acpid

Use two network adapters
In each of my virtual machines, I added two network interfaces. One adapter is set to NAT and is used to connect to the internet, the other is set to host-only and is used to connect to the host.

One advantage of using two network adapters in this situation is the clear separation between internal and external networking. When my host is not connected to an internet connection, I can still access the virtual machine using the host-only network adapter.

Another advantage is that I can also manage firewall rules based on the network adapters, closing down all the ports on the NAT adapter (eth1) and allowing some ports on the host-only adapter (eth0).

It also eliminates the need for messy port-forwarding, something you’ll need to do when using NAT to connect to the virtual machine.

I used the following network configuration on my Ubuntu Server virtual machine:

/etc/network/interfaces (for Ubuntu Server)


# The loopback network interface
auto lo
iface lo inet loopback

# The host-only interface
auto eth0
iface eth0 inet static

# The NAT interface
auto eth1
iface eth1 inet dhcp

I also changed the SSH daemon to not use DNS. There is no DNS server between the virtual machine and host, and with UseDNS enabled it took almost a minute to connect to the virtual machine because it kept trying to find a DNS server. But please do remember that disabling this option is not very safe. Do not change this option other than this specific network configuration or your server will be vulnerable to attacks.

/etc/ssh/sshd_config (for Ubuntu Server)


UseDNS no

Lastly, because there is no DNS between the virtual machine and the host, I also changed my the hosts-file on my workstation so that I can connect to the virtual machine using the hostname.

/private/etc/hosts (for OS X) lamp.lan

Seperate storage
Every virtual machine has two virtual hard-drives. One for the operating system and applications, which is just big enough to fit all the data. The second is for temporary data. Long-term data is stored on a shared folder on my workstation, so I can also access the data when the virtual machine is turned off.

One advantage of using this system is the portability. The first hard-drive is usually about 1-2 gigabyte and is stored on my workstation. The second hard-drive can be as large as needed. I can move the second virtual drive around without having to reconfigure anything, I just have to change one line the VirtualBox config file.

The second advantage about using a separate hard-drive for temporary data is that you can change it to an immutable drive. This means that after every reboot, the hard-drive is changed to its original contents. Not only does this help in keeping the temporary-data disk clean, a nice side-effect is that I never have to compact the disk. It uses a differencing disk for the changes made to the temporary disk, and throws it away after shutting down the virtual machine.

Minimize resources
I initially gave every virtual machine 1GB of memory, and after running them for a while, I scaled back to the amount of RAM needed at peak-performance. The same can be said for the hard-drives, at first I used an 8GB virtual hard-drive for the operating system and applications, but I cloned it to a much smaller hard-drive after the installation was complete. The hard-drive for temporary data is dynamically allocated, so I don’t have to worry about it.