For a recent client project I needed to install a FreeBSD 8.1 guest on VirtualBox from the command line, using VBoxManage. It's actually pretty straightforward, the only setback I found was the networking, which didn't work with the defaults.

Let's start by creating a new virtual machine, configured to run FreeBSD with 256Mb of RAM:

% VBoxManage createvm -name 'FreeBSD81' -register
% VBoxManage modifyvm FreeBSD81 --ostype FreeBSD --memory 256

And we'll create a new 16Gb disk image and attach this to the VM:

% VBoxManage createhd --size 16384 --filename ~/.VirtualBox/HardDisks/FreeBSD81.vdi
% VBoxManage storagectl FreeBSD81 --name "IDE Controller" --add ide
% VBoxManage modifyvm "FreeBSD81" --hda ~/.VirtualBox/HardDisks/FreeBSD81.vdi

Networking proved to be problematic. Eventually I found that the default network adapter type doesn't work on FreeBSD. I had more luck with the 82540EM. You can run this in either bridged or nat mode. If bridged, make sure you specify the host machine's network interface instead of em0:

% VBoxManage modifyvm FreeBSD81 --nic1 bridged --bridgeadapter1 em0 --nictype1 82540EM

That's the basic virtualbox setup done. All that's left is to grab a FreeBSD boot image, and configure the machine to boot from this:

% wget ftp://ftp.uk.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/8.1/FreeBSD-8.1-RELEASE-i386-disc1.iso
% VBoxManage storageattach FreeBSD81 --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /tmp/FreeBSD-8.1-RELEASE-i386-disc1.iso
% VBoxManage modifyvm "FreeBSD81" --boot1 dvd

Now you can start up the machine and use VNC access the console of the FreeBSD Guest OS:

% VBoxHeadless --startvm FreeBSD81 --vnc
% vncviewer localhost:5900

With luck you'll see the FreeBSD installer. Work through the install procedure as usual, then once you have your operating system installed, you can remove the dvd image:

% VBoxManage modifyvm "FreeBSD81" --dvd none

If everything worked then you should have a working FreeBSD guest OS running under VirtualBox.