Vagrant: Vagrant not mounting shared folder

Created on 4 Mar 2018  ·  12Comments  ·  Source: hashicorp/vagrant

Please note that the Vagrant issue tracker is reserved for bug reports and
enhancements. For general usage questions, please use the Vagrant mailing list:
https://groups.google.com/forum/#!forum/vagrant-up. Thank you!

Vagrant version

Vagrant 2.0.2
VirtualBox 5.2.8

Host operating system

MacOSx 10.11.6

Guest operating system

ubuntu/trusty64

Vagrantfile

  config.vm.synced_folder "html", "/var/www/html"

The issue also appears with /vagrant folder

Debug output

https://gist.github.com/hutger/93daedc78a0a6ffa9004b25805952feb

Expected behavior

/vagrant and /var/www/html be mounted.

Actual behavior

The folders are not mounted. However, after a vagrant reload the shares appears.

Steps to reproduce

  1. Execute vagrant up
  2. Check if the /vagrant folder was mounted
waiting-reply

Most helpful comment

@briancain , indeed, when I bring up a VM with the minimal, /vagrant dir is mounted. It seems to be a issue with my provision script. I should have tested with a minimal before open the issue. I apologize about that and thank you for the support.

All 12 comments

Hello! Thanks for opening an issue. When opening a new issue on the Vagrant project, we ask that everyone provide a gist containing the behavior you're seeing with the --debug flag included. This helps us figure out what's actually going on. Thanks!

@thiagorcdl - Please open a new issue. Thanks!

I see this in the debug output:

DEBUG subprocess: Exit status: 0
 INFO interface: output: Mounting shared folders...
 INFO interface: output: ==> default: Mounting shared folders...
==> default: Mounting shared folders...
 INFO interface: detail: /vagrant => /Users/lucasjr/teste/vagrant
 INFO interface: detail:     default: /vagrant => /Users/lucasjr/teste/vagrant
    default: /vagrant => /Users/lucasjr/teste/vagrant
...
...
INFO guest: Execute capability: mount_virtualbox_shared_folder [#<Vagrant::Machine: default (VagrantPlugins::ProviderVirtualBox::Provider)>, "vagrant", "/vagrant", {:guestpath=>"/vagrant", :hostpath=>"/Users/lucasjr/teste/vagrant", :disabled=>false, :__vagrantfile=>true, :owner=>"vagrant", :group=>"vagrant"}] (ubuntu)
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: id -u vagrant (sudo=false)
DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: getent group vagrant (sudo=false)
DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: mkdir -p /vagrant (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: chown 1000:1000 /vagrant (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: if command -v /sbin/init && /sbin/init 2>/dev/null --version | grep upstart; then
  /sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=/vagrant
fi
 (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
INFO interface: detail: /var/www/html => /Users/lucasjr/teste/vagrant/html
 INFO interface: detail:     default: /var/www/html => /Users/lucasjr/teste/vagrant/html
    default: /var/www/html => /Users/lucasjr/teste/vagrant/html
...
...
 INFO guest: Execute capability: mount_virtualbox_shared_folder [#<Vagrant::Machine: default (VagrantPlugins::ProviderVirtualBox::Provider)>, "var_www_html", "/var/www/html", {:guestpath=>"/var/www/html", :hostpath=>"/Users/lucasjr/teste/vagrant/html", :disabled=>false, :__vagrantfile=>true, :owner=>"vagrant", :group=>"vagrant"}] (ubuntu)
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: id -u vagrant (sudo=false)
DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: getent group vagrant (sudo=false)
DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: mkdir -p /var/www/html (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: mount -t vboxsf -o uid=1000,gid=1000 var_www_html /var/www/html (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: chown 1000:1000 /var/www/html (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: if command -v /sbin/init && /sbin/init 2>/dev/null --version | grep upstart; then
  /sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=/var/www/html
fi
 (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0

Are you sure they aren't mounted?

@briancain ... spite of the output, the directories aren't mounted. When I execute a ls, it doesn't show anything, as you can see below:

vagrant@BBHost-dev:~$ ls /vagrant
vagrant@BBHost-dev:~$ ls /var/www/html

However, if I reload vagrant, both shares are mounted.

@hutger - There might be something wrong with the box. If you use a different box, say "bento/ubuntu-14.04" or "bento/ubuntu-16.04" does it work?

@briancain , The issue persists even with bento/ubuntu-14.04 and bento/ubuntu-16.04 boxes.

@briancain , I've recorded a video showing the issue in action: https://youtu.be/brbhcZQefes

I see in your video on the first vagrant up, vagrant doesn't actually print that it's mounting the folders you defined. Was that machine already created? I've also attempted to reproduce this using the bento box and it works as expected:

Vagrant.configure("2") do |config|
  config.vm.define "bork" do |b|
    b.vm.box = "bento/ubuntu-16.04"
    b.vm.provider :virtualbox
    b.vm.provision "shell", inline: <<-SHELL
    echo hello
    SHELL

    b.vm.synced_folder "html", "/var/www/html"
  end
end
brian@localghost:vagrant-sandbox % be vagrant up bork                                                   ±[●●][master]
You appear to be running Vagrant outside of the official installers.
Note that the installers are what ensure that Vagrant has all required
dependencies, and Vagrant assumes that these dependencies exist. By
running outside of the installer environment, Vagrant may not function
properly. To remove this warning, install Vagrant using one of the
official packages from vagrantup.com.

Bringing machine 'bork' up with 'virtualbox' provider...
==> bork: Importing base box 'bento/ubuntu-16.04'...
==> bork: Matching MAC address for NAT networking...
==> bork: Checking if box 'bento/ubuntu-16.04' is up to date...
==> bork: Setting the name of the VM: vagrant-sandbox_bork_1520377043719_79808
==> bork: Clearing any previously set network interfaces...
==> bork: Preparing network interfaces based on configuration...
    bork: Adapter 1: nat
==> bork: Forwarding ports...
    bork: 22 (guest) => 2222 (host) (adapter 1)
==> bork: Booting VM...
==> bork: Waiting for machine to boot. This may take a few minutes...
    bork: SSH address: 127.0.0.1:2222
    bork: SSH username: vagrant
    bork: SSH auth method: private key
    bork:
    bork: Vagrant insecure key detected. Vagrant will automatically replace
    bork: this with a newly generated keypair for better security.
    bork:
    bork: Inserting generated public key within guest...
    bork: Removing insecure key from the guest if it's present...
    bork: Key inserted! Disconnecting and reconnecting using new SSH key...
==> bork: Machine booted and ready!
==> bork: Checking for guest additions in VM...
==> bork: Mounting shared folders...
    bork: /vagrant => /Users/brian/code/vagrant-sandbox
    bork: /var/www/html => /Users/brian/code/vagrant-sandbox/html
==> bork: Running provisioner: shell...
    bork: Running: inline script
    bork: hello
brian@localghost:vagrant-sandbox % be vagrant ssh bork                                                  ±[●●][master]
You appear to be running Vagrant outside of the official installers.
Note that the installers are what ensure that Vagrant has all required
dependencies, and Vagrant assumes that these dependencies exist. By
running outside of the installer environment, Vagrant may not function
properly. To remove this warning, install Vagrant using one of the
official packages from vagrantup.com.

Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.


vagrant@vagrant:~$ ls /var/www/html
index.html
vagrant@vagrant:~$ cat /var/www/html/index.html
<h1>hello</h1>
vagrant@vagrant:~$

@hutger I recommend trying to bring up a regular vm with a minimal vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-16.04"
end

SSH into that guest, and see if it properly mounted the /vagrant dir. If that works, I suggest looking at your chef provisioners. It could potentially be failing, thus skipping the shared folder step. When you vagrant reload it won't run provisioners if the guest is already created, and could be why it's able to mount the folders during the reload but not the up step.

@briancain , indeed, when I bring up a VM with the minimal, /vagrant dir is mounted. It seems to be a issue with my provision script. I should have tested with a minimal before open the issue. I apologize about that and thank you for the support.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings