Jonathan's Pancheria

dotcom Thousandaire

In case you actually want to use Vagrant for Linux software development...

I forgot to document this after the 1st Vagrant-based development VM I set up, so I’ll do it now so I do not lose it again.

Virtualbox disables symbolic links on host folders shared into the guest as of 4.1.8

Just stop. and. enjoy. that. for. a. second.

Then peruse this ticket in the Virtualbox bug tracker (but read on in this post before trying to fix the problem because I will point you to the correct fix in a bit). I totally get why, in the general case they needed to do this. If you’re using Virtualbox in any sort of production environment, any issues with privilege escalation or sandbox breakout are bad, bad, bad.

However, I’m using Virtualbox as part of Vagrant to manage development VMs. My use case is a bit different. I want to fire up a VM into which I share my source code folders from my host box into one or more VMs. I do this so I can, for example, just have one text editor open with one source tree on my host, but have it running in a VM. I can build or recreate Vagrant/virtualbox VMs at a whim and not worry about losing my source code in an accidental delete. I can probably think of more use cases.

With the default settings as shipped as of 4.1.8, I can’t do that anymore. The problem is that the chance that any reasonable Linux software development ends up making symlinks around the source dir (which, remember, is shared from the host in my case) approaches 100%. In fact, if you’re using node.js and using most any package via npm it probably defaults to exactly 100%. Symlinks, which are disabled by default.

Fortunately, all is not lost.

How to set Virtualbox settings back so you can share a host folder into a guest and make symlinks

Refer to this comment on the ticket in the ticket I referenced earlier in the Virtualbox bug tracker for instructions on how to fix the problem. The one trick to remember is that the SHARE_NAME is actually the name of the host “Filesystem” within the VM. So consider this example from one of my vagrant VMs:

vagrant@precise64:/vm_src/$ df
Filesystem                 1K-blocks      Used Available Use% Mounted on
/dev/mapper/precise64-root  82711212   3063948  75504980   4% /
udev                          178068        12    178056   1% /dev
tmpfs                          74852       284     74568   1% /run
none                            5120         0      5120   0% /run/lock
none                          187128         0    187128   0% /run/shm
/dev/sda1                     233191     27483    193267  13% /boot
v-data                     344580864 303729368  40851496  89% /directory_you_mounted_from_your_host_with_your_files
v-root                     344580864 303729368  40851496  89% /vagrant
v-csc-1                    344580864 303729368  40851496  89% /tmp/vagrant-chef-1/chef-solo-1/cookbooks

You actually want to run the following command to have symlinks re-enabled on the host folder you’ve shared out as directory_you_mounted_from_your_host_with_your_files, you actually want to issue the following command (replacing vagrant_server_name_plus_random_number with the actual name of your server):

VBoxManage setextradata vagrant_server_name_plus_random_number VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-data 1

You will probably have to look in the Virtualbox admin GUI to find the actual server name because when you create a box with vagrant it sticks an arbitrary number onto the end of the name you give your server. Notice carefully there’s a 1 at the end of that command, which means to set that value to “true”.

Do the above, then (to be safe, I haven’t verified the minimum set of commands to make it work):

vagrant reload _your_vm_name_

and then vagrant ssh back in and symlinks will now work within the guest in the shared host folder.

Published on 14/01/2013 at 11:29PM .

Comment In case you actually want to use Vagrant for Linux software development...

Powered by Typo – Thème Frédéric de Villamil | Photo L. Lemos