Mounting a symlinked folder in vagrant & virtualbox

1.1k views Asked by At

Okay, so here is my problem: I use vagrant with VirtualBox. The host is Windows 8.1, the guest is Ubuntu (64bit). I am trying to use a symlinked windows folder created by

mklink /j somefolder someotherfolder

as synced folder in Vagrant. In my Vagrantfile I have

# disable the default synced folder
config.vm.synced_folder ".", "/vagrant", disabled: true
# sync my desired folder
config.vm.synced_folder "./somefolder", "/vagrant"

Unfortunately this does not work, but gives the following error:

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3`
vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

stdin: is not a tty
/sbin/mount.vboxsf: mounting failed with the error: Invalid argument

Before you ask: Guest additions are installed, and mounting regular folders works flawlessly.

Is there a way to use symlinked directories as synced folders in vagrant with vbox?

Thanks for your help!

2

There are 2 answers

0
Ivan Castellanos On

Cut the folder to where you need it from the VM, after that create the junction (or symlink) at the original location.

1
Chris On

I was having a similar issue. I couldn't get Symlinks working with vagrant but a Hardlink Clone did. I was trying to have my Dev folder in sync with Google Drive but did not want to relocate the folder.

My Solution: Hardlink Clone

  1. Download and install Linkshell for windows (and the listed prerequisite package) [ direct Link to actual file I downloaded | direct link to prerequisite package I downloaded ] Direct link good for Windows XP64, Windows Vista64, Windows Server , 2003/2008/20012 64bit, Windows 7/8/10 64bit
  2. Right click on source folder (in my case the one I copied to Google drive) and select pick link source

pick link source context option

  1. In location where you want your "symlink", right click and select Drop as -> Hardlink Clone

hardlink clone context option

Thats what it took for me to get it working with vagrant. I originally tried as symbolic link without success.