Tuesday, April 23, 2013

Run VirtualBox VMs in the background - headless mode using VboxManage

I love virtualbox for my virtualization needs for its ease of use and low resource utilization. I have a bunch of VMs created to install and test SQL Server high availability features like AlwaysOn, Clustering etc. Working with these VMs I always wished if there was a way to just run these VMs in the background instead of keeping a window open for each VM. I googled around a bit and it is possible to start a VM in background mode, in virtualbox speak, its called headless mode.

How do you do that?

If you have VirtualBox installed its likely that you have VBoxManage executable installed as well. Check the installation directory. Mine was at: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe.

In order for you to invoke this from cmd, add it to environment variables. You can do that using powershell:

Get-ChildItem Env:Path | format-list
# adding path to PATH
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";C:\Program Files\Oracle\VirtualBox", "Machine")

If the above was successful, you should be able to run VBoxManage as a command from cmd.

Make sure that your guest VMs are connected to the Host via network adapter and enable remote display on each VM as shown below:

You can now start your VMs from command line, using below command:

VBoxManage startvm VMNAME --type headless

This will start the VM in the background and you can RDP to it when needed.

There are many more options to play with and automate for VBoxManager. For more details, check HERE and HERE