Vagrant shared and synced folders
Asked Answered
T

2

68

I created a Vagrantfile with the following content:

Vagrant::Config.run do |config|

  config.vm.define :foo do |cfg|
    cfg.vm.box     = 'foo'
    cfg.vm.host_name = "foo.localdomain.local"
    cfg.vm.network :hostonly, "192.168.123.10"
  end

  Vagrant.configure("2") do |cfg|
    cfg.vm.customize [ "modifyvm", :id , "--name", "foo" , "--memory", "2048", "--cpus", "1"]
    cfg.vm.synced_folder "/tmp/", "/tmp/src/"
  end

end

After vagrant up or vagrant reload I get:

[foo] Attempting graceful shutdown of VM...
[foo] Setting the name of the VM...
[foo] Clearing any previously set forwarded ports...
[foo] Fixed port collision for 22 => 2222. Now on port 2200.
[foo] Creating shared folders metadata...
[foo] Clearing any previously set network interfaces...
[foo] Preparing network interfaces based on configuration...
[foo] Forwarding ports...
[foo] -- 22 => 2200 (adapter 1)
[foo] Booting VM...
[foo] Waiting for VM to boot. This can take a few minutes.
[foo] VM booted and ready for use!
[foo] Setting hostname...
[foo] Configuring and enabling network interfaces...
[foo] Mounting shared folders...
[foo] -- /vagrant

My questions are:

  1. Why is Vagrant mounting the /vagrant shared folder? I read shared folders are deprecated in favour of synced folders, and I never defined any shared folder in my Vagrantfile.
  2. Why is the synced folder not set up?

I'm using Vagrant version 1.2.7 on MacOX 10.8.4.

Thus answered 30/8, 2013 at 8:50 Comment(0)
I
113

shared folders VS synced folders

Basically shared folders are renamed to synced folder from v1 to v2 (docs), under the bonnet it is still using vboxsf between host and guest (there is known performance issues if there are large numbers of files/directories).

Vagrantfile directory mounted as /vagrant in guest

Vagrant is mounting the current working directory (where Vagrantfile resides) as /vagrant in the guest, this is the default behaviour.

See docs

NOTE: By default, Vagrant will share your project directory (the directory with the Vagrantfile) to /vagrant.

You can disable this behaviour by adding cfg.vm.synced_folder ".", "/vagrant", disabled: true in your Vagrantfile.

Why synced folder is not working

Based on the output /tmp on host was NOT mounted during up time.

Use VAGRANT_INFO=debug vagrant up or VAGRANT_INFO=debug vagrant reload to start the VM for more output regarding why the synced folder is not mounted. Could be a permission issue (mode bits of /tmp on host should be drwxrwxrwt).

I did a test quick test using the following and it worked (I used opscode bento raring vagrant base box)

config.vm.synced_folder "/tmp", "/tmp/src"

output

$ vagrant reload
[default] Attempting graceful shutdown of VM...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Available bridged network interfaces:
1) eth0
2) vmnet8
3) lxcbr0
4) vmnet1
What interface should the network bridge to? 1
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Running 'pre-boot' VM customizations...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/src

Within the VM, you can see the mount info /tmp/src on /tmp/src type vboxsf (uid=900,gid=900,rw).

Infamous answered 30/8, 2013 at 9:38 Comment(4)
vagrant up --debug or vagrant reload --debug might be usefullShalon
cfg.vm.synced_folder ".", "/vagrant", disabled: true to disable the default mount is very helpful, thanksPublishing
I had a host folder outside of the vm "public" folder, correctly set to sync, but it would not mount when the machine boot. The VAGRANT_INFO=debug vagrant reload did the trick for me and now it mounts every time. Thanks!Despairing
I had to add config.vm.synced_folder ".", "/vagrant", disabled: false to Vagrantfile to make it work. I guess the default has changed.Universalist
P
0

Adding

config.vm.synced_folder ".", "/vagrant", disabled: false

to Vagrantfile worked for me for a FreeBSD 13.1 guest provided by bento/freebsd-13.

The host was running macOS 12.5.1, Vagrant 2.3.0, and VirtualBox 6.2.36.

Permeate answered 12/9, 2022 at 10:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.