Building VirtualBox on Mac OS X with VNC Support

I've been using VirtualBox for months for several reasons and recently I've been forced to use only the free version of vbox (without the Extensions Pack), which doesn't include the sweet bits of VRDP server among other things. I wanted to boot my virtual machines headless and access it using VNC which doesn't come by default in Oracle's builds of VirtualBox, so I decided to roll my own build.

VirtualBox is available on MacPorts but doesn't have VNC variant yet, unless my contribution to MacPorts is accepted.

First steps

I searched for a VirtualBox port and I was surprised to find one, but I wasn't quite happy with it, because it doesn't build VirtualBox with VNC support, so I had to hack my way around. I wanted to implement that cleanly by adding a new port variant +vnc to that port.

The following steps will help you do the same; I've tested that on Mac OS X Lion 10.7 64bit but should work exactly the same on Snow Leopard 10.6 too.

Creating your own MacPorts repo:

mkdir -p ~/ports/emulators/  

Then copying the portfile and patches to your new MacPorts repo:

cp -r `port dir virtualbox` ~/ports/emulators/  

Editing MacPorts sources file to include your local repository (assuming your MacPorts prefix is /opt/local as mine)

sudo vim /opt/local/etc/macports/sources.conf  

Add the following line in the beginning of the file (change your_user_name to your real username) file:///Users/your_user_name/ports

Then you are ready to hack the portfile

cd ~/ports/emulators/virtualbox  

Download the patch of the Portfile in that directory and apply the patch

patch -u Portfile < Portfile-virtualbox.diff  

Then build port index

cd ~/ports  

You should be able to see the new variant now:

port variants virtualbox  

You should see two variants now:

virtualbox has the variants:  
  [+]vde2: Enable support for VDE
  [+]vnc: Enable support for VNC

Install virtualbox:

sudo port install virtualbox +vnc  

After quite some long time building dependencies, you should be able to see the new --vnc option in VBoxHeadless command.

Update: You should also check this relevant post if you are interesting in using the Python bindings of VirtualBox on Lion

Enjoy :)

comments powered by Disqus