Last Updated: February 25, 2016
· themichael'tips

VirtualBox sharing folder on Os X with Linux


Sharing a filesystem folder between Os X and a VirtualBox's linux operative system is not so easy at first glance. The easy part is define the folder to share, but for enable the sharing you have to install something named 'Gust Additions' into your virtual linux os. Let's show how do it.

Define the shared folder (the easy part :)

Run Virtual Box App -> select your Linux Virtual Machine -> Setting -> Shared Folder <br>
Add your folder

example: in my case is /Users/heyhey/Workspace with auto-mount & make permanent checked.

Add a fake 'CD/DVD'

Setting -> Storage -> into the Storage Tree select 'Controller: IDE'<br>
Click on Leave empty

Install the guest additions

1 Run your Linux Virtual Machine and login.

2 In the menu select Device -> Insert Guest Additions CD images...<br>(Note: With this operation VirtualBox automatically add the VBoxGuestAdditions.iso located in /Applications/VirtualBox.app/Contents/MacOS/)

3 Use the linux terminal for search the device:

$ls -l /dev/disk/by-id/

The first one looks good. With ls -l you can get the real path, and in my case is /dev/sr0.

4 Now mount and install

sudo mount -o loop /dev/sr0 /mnt
cd /mnt
sudo ./VBoxLinuxAdditions.run

5 Play with it:

sudo touch /media/sf_Workspace/my_first_file.woow


Here some tips in order to exploit your virtual machine.

Tip 1: VirtualBox Symlinks

If you want use symlink into the shared folders, just type within the Os X terminal

VBoxManage setextradata Ubuntuv14-64bit  VBoxInternal2/SharedFoldersEnableSymlinksCreate/Workspace 1

Where Ubuntuv14-64bit is the name of your machine, and the Workspace the name of your shared folder.

To check if the command was successfull, type:

$VBoxManage getextradata  Ubuntuv14-64bit enumerate
Key: GUI/LastCloseAction, Value: PowerOff
Key: GUI/LastGuestSizeHint, Value: 640,480
Key: GUI/LastNormalWindowPosition, Value: 41,144,640,501
Key: GUI/MiniToolBarAlignment, Value: bottom
Key: GUI/SaveMountedAtRuntime, Value: yes
Key: GUI/ShowMiniToolBar, Value: yes
Key: VBoxInternal2/SharedFoldersEnableSymlinksCreate/Workspace, Value: 1

You should see the shared folder enabled.<br>
Reboot the virtual machine and the entire VirtualBox app.

Tip 2: apt-get instead of port

The apt-get package manager is much more powerful, and it has much more packages than the port utility.<br>
So, you can use your linux environment and your shared folder to get access to all available linux packages.

Tip 3: demons in NAT

Using NAT routing you can move all the services/demons you want from Os X to your virtual Linux. Some benefits are:

  • don't be afraid about eventually installation mess
  • easy installation of many kind of same services (like apache httpd, mysqld...) with different configuration and version.
  • debugging with Linux (using strace, ddd, etc..) could be much more easy
  • emulate a real external server
  • keep your Os X clean and safe from unexpected demon's behavior that are in developping stage