106

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?

Golo Roden
  • 140,679
  • 96
  • 298
  • 425
  • Discussion here: https://github.com/mitchellh/vagrant/issues/713#issuecomment-4416384 – Steve Bennett Aug 11 '14 at 07:36
  • @SteveBennett, that issue (which the current accepted answer references) was resolved in Vagrant 1.1, which was released 15 months before the OP posted the question. And it's about VirtualBox shared folders anyway, not rsync'd folders. See my answer below (the accepted answer is wrong). – jdunk Mar 13 '15 at 02:01

6 Answers6

97

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

jdunk
  • 2,738
  • 2
  • 17
  • 25
  • 1
    Good call - thanks @jdunk. Yes, according to Vagrant docs, the `--copy-links` option is set by default. This was my problem. By removing that (using your answer above) - that takes care of it. – Phil Birnie Apr 06 '15 at 19:50
  • 1
    Very useful, thanks. Although I would wish for Windows alternative. – Aleksandr Makov Jun 03 '15 at 13:43
  • 5
    Note that according to the Vagrant docs, Shared folders are the default type of synced folder for VirtualBox users: "If you're using the VirtualBox provider, then VirtualBox shared folders are the default synced folder type." (http://docs.vagrantup.com/v2/synced-folders/virtualbox.html) The OP's question also seems to imply that VirtualBox shared folders are a concern, so the accepted answer does attempt to address at least part of the problem (and indeed did fix the problem for me). – Ajedi32 Aug 25 '15 at 01:22
  • 1
    Thank you so much for saving my ass, I've looked everywhere on the internet and finally someone who understands this problem! – Dovizu Sep 23 '15 at 21:29
  • 1
    Thank you. This is what solved my issue (the one in the title, and the one which I arrived here looking for a solution to, and which confusingly is not the one being asked). – johncip May 27 '16 at 02:04
  • This is probably common knowledge, but it's my first time using Vagrant and it took me a bit to figure this out. The answer uses ".", "/var/www/" but if you are using a different location for the project, make sure you replace /var/www with that. By default for me, /vagrant. If you're on a Mac and getting the referent error, you can update the host and guest paths from reading it from the error message: `There was an error when attempting to rsync a synced folder. Please inspect the error message below for more info Host path: /Users/// Guest path: /vagrant` – intrepid_em Nov 07 '17 at 15:59
  • 1
    Thank you so much for the tip. It works. The only problem is that when I make changes in files in my host machine these changes are not reflected in the guest machine like it used to be earlier. Any advice would be helpful. Thanks – Phantom007 Nov 14 '17 at 12:25
  • Nice, solved my problem too – Saurab Dulal Feb 21 '23 at 18:21
68

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.

Laurence
  • 58,936
  • 21
  • 171
  • 212
Marvin
  • 1,009
  • 7
  • 3
  • 9
    I suspect the OP and many people viewing this question were using the term "shared" and "synced" interchangeably. Note the OP's second bullet point which strongly implies he was using shared folders, but tried switching to an rsynced folder because they didn't work. IIRC, the solution provided here solved the problem I was having, in any case. – Steve Bennett Mar 13 '15 at 02:47
  • 2
    @SteveBennett, agreed re: potential confusion. All the more reason to clarify. It's hard to imagine this suggestion would have solved your issue when it refers to such an old [long-since-resolved] issue, unless you were using a considerably old version of vagrant. And even if it did, IMO it would have been of very little help considering VBox's abysmal filesystem performance for shared dirs (e.g. "git status" taking several seconds), though it's possible you were sharing only a small project with very few files. http://mitchellh.com/comparing-filesystem-performance-in-virtual-machines – jdunk Mar 15 '15 at 08:06
  • 6
    Running `vagrant up` in a shell with admin rights is all that is required. As @jdunk pointed out, this config option is already set by default in Vagrant, as of [this commit](https://github.com/mitchellh/vagrant/commit/387692f9c8fa4031050646e2773b3d2d9b2c994e) which happened almost a year before this answer was posted. That said, running `vagrant up` in a shell with admin rights did resolve my problem. – Ajedi32 Aug 25 '15 at 01:18
  • 2
    Does not respond to the question. Its not working on synced folders. – Manel Nov 14 '16 at 22:11
  • This answer is wrong for 2 major reasons. 1. It refers to VBox shared folders, not rsynced directories--two completely different things. 2. This setting was already a default anyway in Vagrant 1.1, released 15 months before the OP's question. See my answer below for more info. – jdunk Mar 02 '17 at 12:48
  • Vagrant up needs to be executed in a shell with admin rights on windows. – Muhammad Usama Oct 03 '19 at 23:34
8

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.

gameweld
  • 1,319
  • 15
  • 21
  • `npm update` was not working in my vagrant shared folder. This solution fixed it for some reason. – Emre Feb 11 '17 at 03:56
  • 1
    After more research, it turns out creating a symbolic link requires admin permission in windows by default. To modify permissions, see answer here: https://superuser.com/a/125981 – gameweld Jan 18 '18 at 02:49
  • Running the Vagrant and command promt as Administrator in Window 10 machine worked for me on npx create-react-app 'project_name'. – sybozz Sep 10 '20 at 18:16
2

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.

Terry Wang
  • 13,840
  • 3
  • 50
  • 43
  • `[wdd@localhost ~]$ sudo mount -t rsync node share mount: unknown filesystem type 'rsync'` – Musa Haidari Apr 07 '16 at 04:02
  • 1
    I was glad when I read this answer, thinking it would solve my problem but I get the same as above when I do `sudo mount -t rsync shared /var/www` the error being `mount: unknown filesystem type 'rsync'` – samayo Dec 14 '16 at 22:58
  • `rsync` is never a file system type so you won't be able to mount it. – Terry Wang Dec 15 '16 at 09:35
  • @samyo refer to https://www.vagrantup.com/docs/synced-folders/rsync.html you need to configure in the `Vagrantfile` and manually run `vagrant rsync` or `vagrant rsync-auto`. Otherwise it'll be only synced at up and reload. – Terry Wang Dec 15 '16 at 10:22
1

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"
1

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
Batchen Regev
  • 685
  • 1
  • 7
  • 28