流浪汉中的符号链接和同步文件夹

我想使用 Vagrant 为我的团队提供一个通用的开发环境:

  • 有些使用 OS X,有些使用 Linux,有些使用 Windows。
  • 有些使用 VMware,有些使用 VirtualBox。

在虚拟机内部,我们想要运行 Linux。

目前为止,一切正常。

现在我们的想法是,每个开发人员都可以使用自己选择的 IDE,因此我们引入了一个同步文件夹,在主机和 VM 之间共享源代码。这基本上也可以... 除了符号链接。

在我们的源代码中,我们实际上有一些符号链接,这在 VM 中的 Linux 中不是问题,但是在作为主机的 Windows 中会导致问题。我们唯一能做的就是去掉这些符号链接,所以我们需要另一种方法来处理这个问题。

到目前为止,我们已经尝试了很多选择:

  • 在 Vagrant 的 问题中提到了一个变通方法,不幸的是,这只是 VirtualBox,并不能帮助那些运行 VMware 的人。到目前为止,我们还没有找到一种根据所使用的提供程序在 流浪汉档案中运行代码的方法。
  • 我们现在尝试使用 Rsync类型来代替使用标准的共享文件夹。这在 Windows 上可以工作,但是在 OS X 上崩溃时会出现一些错误,告诉我们 symlink has no referent(每个符号链接一个错误)。
  • 我们考虑过 NFS,但是只有在不使用 Windows 作为主机的情况下才能实现。
  • 我们也想到了 中小企业,但这也只能在 Windows 上作为主机使用。

我无法想象我们是这个星球上唯一或第一个在共享文件夹中遇到多平台主机和象征性链接问题的人。

如何解决这个问题,使我们可以保持符号链接,但仍然使用不同的主机操作系统?

75521 次浏览

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.

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.

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"

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).

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.

Add the following line to Vagrantfile:

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

This worked for me ONLY after i downgraded virtualbox 6.0.8 to 6.0.4 and vagrant 2.2.4 to 2.2.1.

when you open terminal ( i use git bash on windows 10) with "Run as Admin".

also try in git bash changing : in project file: $ vim .git/config change to symlinks = true

[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = true
ignorecase = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master