Symbolic links and synced folders in Vagrant

2019-01-09 23:46发布

I want to use Vagrant to provide a common development environment to my team. The hosts are completely different:

  • Some use OS X, some Linux, and some Windows.
  • Some use VMware, some use VirtualBox.

Inside of the VM we want to run Linux.

So far, everything is fine.

Now our idea was that each developer shall be able use the IDE of their choice, and hence we have introduced a synced folder that shares the source code between the host and the VM. This basically, works as well … except for symbolic links.

Inside of our source code we actually do have a few symbolic links, which is not a problem within the Linux inside the VM, but on Windows as host this causes problems. The only thing that we can not do is get rid of the symbolic links, so we need another way to deal with this.

So far, we have tried a number of options:

  • There is a workaround mentioned in an issue of Vagrant, unfortunately this is VirtualBox-only and does not help those who run VMware. So far, we haven't found a way of running code in the Vagrantfile depending on the provider used.
  • Instead of using a standard shared folder we now have tried using the rsync type. This works on Windows, but crashes on OS X with a number of errors telling us that the symlink has no referent (one error per symbolic link).
  • We thought about NFS, but that only works if you do not use Windows as host.
  • We also though about SMB, but this again only works on Windows as host.

I can not imagine that we are the only or the first persons on this planet to experience problems with multi-platform hosts and symbolic links within the shared folder.

How can you solve this issue, so that we can keep symbolic links, but still use different host operating systems?

5条回答
我命由我不由天
2楼-- · 2019-01-10 00:27

After fussing around for an hour and trying a few different solutions (vagrant-vbguest, Marvin's suggested fix), I wasn't able to get symlinks in shared folders to work with VirtualBox 4.8.10, Vagrant 1.5.1.

I found that a simpler solution is to configure a separate shared folder and then use Ruby's File.readlink to read in the underlying path:

config.vm.synced_folder File.readlink('SYMLINK'), "/mount/path"
查看更多
淡お忘
3楼-- · 2019-01-10 00:33

The default synced folder type is vboxsf has known performance issue with large number of files / directories, and lacks support for symbolic links and hard links (see ticket 818 - a 7+ year old bug). Avoid using it.

rsync type synced folder may be your best choice.

You mentioned that it crashed, what version of rsync are you running? Try to update it to 3.1.0 via brew, I know the OOTB one is way too old (2.x), which could be causing issues.

查看更多
贪生不怕死
4楼-- · 2019-01-10 00:45

The accepted answer is no good. The question describes an issue with synced folders, not shared folders. The proposed solution would have no effect on an rsynced (not shared) folder. And even if the OP was using a shared folder, the accepted answer's suggestion is something that had already been integrated into vagrant as of 1.1, released 15 months before the OP posted the question (not to mention VirtualBox's shared folders are abysmally slow).


I encountered this same issue: on OS X, I got the symlink has no referent rsync error. I was personally able to solve it by adding particular rsync args to my vagrantfile:

config.vm.synced_folder ".", "/var/www", type: "rsync", rsync__args: ["--verbose", "--archive", "--delete", "-z"]

I also opened this issue on vagrant's github to point out something that appears to be wrong with their default value for rsync__args (specifically, that one of the default args, --copy-links, seems to be breaking another, --archive, at least as far as copying broken symlinks is concerned).

查看更多
神经病院院长
5楼-- · 2019-01-10 00:45

I tried all these options in order to resolve an error running npm install.

Simply running vagrant in an admin prompt and loading the vm (vagrant reload), resolved the issue.

I went back and removed the SharedFoldersEnableSymlinksCreate configuration from the Vagrantfile, and everything was still fine.

查看更多
地球回转人心会变
6楼-- · 2019-01-10 00:50

Virtualbox does not allow symlinks on shared folders for security reasons. To enable symlinks the following line needs to be added to the vm provider config block in the Vagrantfile:

config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end

Additionally, on windows vagrant up needs to be executed in a shell with admin rights. No workarounds necessary.

查看更多
登录 后发表回答