Want to mount VirtualBox folders on Ubuntu under an OSX 10.8 host?  Differences between aptitude packages and the VirtualBox Guest Additions ISO, compounded to  "security fixes" in recent versions of VirtualBox that disable symlinks can be a pain.  Read below, it's actually quite simple.  

Starting, I assume that you have VirtualBox 4.3.4+ installed, and have loaded up your Ubuntu Server VM -- but don't spin it up yet.

Configuring Your Shared Folder

Inside VirtualBox, head to your VM's Settings panel and visit the Shared Folders tab.  Click the Add (+) icon on the right hand side and specify the folder on your host (OSX) that'll get shared in your guest (Ubuntu).  Check Auto-mount & Make Permanent, click Ok. [I noticed a strange thing, "Make Permanent" isn't always visible.  Click "OK" to save & close, then double-click your shared folder entry to make it reappear in the modal dialog.] 

Make a mental note your share's name; you'll need it in the steps that follow.  Mine is webroot in the screenshot affixed.

Screenshot of shared folder config panel

Screenshot of shared folder config panel

 

Enabling Symlinks (optional)

If you need Symlinks in your guest, run this command before you start your VM.  This gotcha was a pain.  Switch out "webroot" for your share's name, and VM_NAME for the actual name you give your VM.

VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/webroot 1

 

Start & Prep Your VM

Start your VM, log in via SSH, and then:

  1. insert the Guest Additions CD image (Devices > Insert Guest Additions CD image in the menu)
  2. mount the CD with: sudo mount /dev/cdrom /media/cdrom
  3. before we can install what's on the CD, we need to build a few requirements:  sudo apt-get install -y dkms build-essential linux-headers-generic linux-headers-$(uname -r)
  4. now we can use what's on the CD, install with: sudo /media/cdrom/VBoxLinuxAdditions.run

Because you are on Ubuntu Server, it'll crap out at the last step where it tries to install X11 dependencies - but don't worry about it - it'll still work(Could not find the X.Org or XFree86 Window System.)

Reboot your VM at this point, then shell back in.

 

Mount Your Folders, Like Magic

I wanted to mount something that'd get used by nginx; so I mounted them under the www-data uid and gid (33).  I also added www-data to vboxsf.

sudo adduser www-data vboxsf

Mount with this command thereafter (recall your share name noted earlier):

sudo mount -t vboxsf -o uid=33,gid=33 webroot /var/www/html/

You can discover a user's  ID with the id command.