VirtualBox Guest Additions with Shared Folders for Linux Virtual Machines on Mac OS X

In order to access certain aspects of a virtual machine in VirtualBox, you will need to install Guest Additions (similar to VMWare Tools I guess)

There is a manual page for installing Guest Additions but not all of it is self-explanatory…

First you need to log into your Linux virtual machine (VM) and install/configure x, y and z.

Install DKMS

This part is relatively straightforward, just install using whatever package manager your Linux distribution has. The below example uses APT that comes with Debian-based distros:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install dkms

Where to find VBoxGuestAdditions.iso

Usefully Oracle don’t tell you in their guide, but it is available with the rest of the downloads at http://download.virtualbox.org/virtualbox/

So for example for version 4.1.6 the VBoxGuestAdditions_4.1.6.iso is located at http://download.virtualbox.org/virtualbox/4.1.6/VBoxGuestAdditions_4.1.6.iso

You need this image to install the VirtualBox Guest Additions themselves onto your VM, so you can either download it to your Linux VM and mount it there, or (which is what I did) download it to your Mac OS X host and mount it in the DVD drive using the VirtualBox Manager.

How to mount the image

You need to mount the image on the Linux VM, so that you can install VirtualBox Guest Additions from it. If you have mounted it in the VirtualBox Manager in the DVD drive then you will still need to mount it in the Linux VM; Since I can’t remember the last time I had to mount something in *nix from the command-line, here’s a quick way.

sudo mkdir /dev/dvd
sudo mount /dev/dvd1 /mnt/dvd/
cd /mnt/dvd

Then you should see VBoxLinuxAdditions in that directory, which you need to run as per the manual. If the above doesn’t work it might be because your DVD drive in VirtualBox is called something else, like dvd (instead of dvd1) which probably differs depending on which distro you’re using.

Then you need to run the installer.

sudo sh ./VBoxLinuxAdditions.run

Once that’s done you can restart.

sudo reboot now

Everything should be finished now installation/configuration-wise, but you might encounter some problems… (otherwise skip to Mount the host folder)

Kernel header problems

I got some missing kernel header problems when trying to install Guest Additions, which if building the main Guest Additions module fails will be logged.

cat /var/log/vboxadd-install.log

If you see something like this…

Error! Your kernel headers for kernel 2.6.35-28-generic cannot be found at
/lib/modules/2.6.35-28-generic/build or 
/lib/modules/2.6.35-28-generic/source.
You can use the --kernelsourcedir option to tell DKMS where it's located,
or you could install the linux-headers-2.6.35-28-generic package.

So you can do just that!

sudo apt-get install linux-headers-2.6.35-28-generic
sudo ./VBoxLinuxAdditions.run

Hopefully this should install now (although the XFree86 bit will fail, assuming you’re using the command-line) and you may need to restart the VM, although I’m not sure.

Mount the host folder

You can create the host folder in the VirtualBox Manager in the Shared Folders tab on the Settings for that VM. If you add it on the command-line it’ll appear under the machine folders anyways. If you want to type it though, here’s what you’d type into the Mac OS X terminal (note this is the only thing that you’d type into the host itself)

VBoxManage sharedfolder add "my-ubuntu-vm" \
--name "websites" --hostpath "/Users/andrew/pizza"

To mount the Shared Folder from within the guest, the instructions from Ubuntu (as my guest is Ubuntu, although I think this is a better way to mount it anyways) were very useful.

sharename="whatever.you.want.to.call.it";
sudo mkdir /mnt/$sharename \
sudo chmod 777 /mnt/$sharename \
sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename \
ln -s /mnt/$sharename $HOME/Desktop/$sharename

Just change the target to be wherever you want the Shared Folder to be mounted in the guest. Now in theory if you go to that path in the guest, it should be the same as the directory you shared from the host!

12 comments

  • Hi,
    1. How to install the apt-get in OSX? OSX does not have the apt-get in the terminal.
    2. I mount the Guest Additions iso and try to run the VBoxLinuxAdditions.run command. It returns ‘Unable to determine the Linux distribution’ message. Is it able to ‘simulate’ Linux under OSX.

    Thanks for your reply in advance

  • Oh, I got the things the other way round. I try to install guest addition in my Lion guest in PC host. However, I searched all Internet and got the answer that guest addition is not yet availale for OSX guest.

  • From the Virtualbox site (in case it helps someone out there):

    Guest Additions for OS/2

    VirtualBox also ships with a set of drivers that improve running OS/2 in a virtual machine. Due to restrictions of OS/2 itself, this variant of the Guest Additions has a limited feature set; see Chapter 14, Known limitations for details.

    The OS/2 Guest Additions are provided on the same ISO CD-ROM as those for the other platforms. As a result, mount the ISO in OS/2 as described previously. The OS/2 Guest Additions are located in the directory \32bit\OS2.

    As we do not provide an automatic installer at this time, please refer to the readme.txt file in that directory, which describes how to install the OS/2 Guest Additions manually.

  • Great guide to sharing folder between an OSX host and Linux in VirtualBox. You might want to add how to make the mount exist across reboots.