Thursday, November 19, 2009

Running VirtualBox in Headless Mode

I first started using Parallels on Mac OS X, later switched to VMware, and now use VirtualBox, which I love. But I have to say that I don't particularly fancy its UI. I find it inconvenient that you need to first hit special key (by default command) to escape the VirtualBox environment. Frankly, I'd rather use Remote Desktop to connect to VirtualBox. And now I do.

The process is rather simple. I'll start assuming that you already have a working VM setup in VirtualBox:

  1. You can have multiple VMs setup in VirtualBox. In my case, I have only one, named "Windows 7". To know the name of your VM, from the command line run:
    VBoxManage list vms
  2. Once you know the name of your VM (which I'll assume to be "Windows 7"), start the VM with:
    VBoxHeadless -s "Windows 7" &
    I like to start VirtualBox in the background, hence the & at the end of the command line. This is because VBoxHeadless doesn't output anything to the standard output after it has started, and you don't want to stop it by mistake by hitting ctrl-c, as you would loose the state of you VM. Instead you'll want to save the VM state (more on this below).

  3. Start Remote Desktop. If you are on a Mac, Microsoft has a free Remote Desktop for OS X. Connect to the VM using Remote Desktop using the host name or IP of the machine running VirtualBox. For instance, if you are running VirtualBox and Remote Desktop on the same machine, that would be localhost.

  4. To stop VirtualBox while saving the state of the VM, run:
    VBoxManage controlvm "Windows 7" savestate
    Next time you start VirtualBox (as in step 2 above), it will used that saved state.