我有一些问题与Vagrant共享文件夹,我的基本系统是Ubuntu 13.10桌面。

我不明白为什么我有这个错误是配置不正确的东西?是NFS问题还是Virtualbox客户附加功能?我尝试了不同的盒子,但同样的问题。

Failed to mount folders in Linux guest. This is usually because
    the "vboxsf" file system is not available. Please verify that
    the guest additions are properly installed in the guest and
    can work properly. The command attempted was:

    mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` /vagrant /vagrant
    mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` /vagrant /vagrant

以下是流浪起来后的完整流程:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'u131032'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant_default_1396020504136_46442
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Error: Connection timeout. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
GuestAdditions versions on your host (4.3.10) and guest (4.2.16) do not match.
 * Stopping VirtualBox Additions
   ...done.
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  dkms libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontenc1
  libgl1-mesa-dri libglapi-mesa libice6 libllvm3.3 libpciaccess0 libpixman-1-0
  libsm6 libtxc-dxtn-s2tc0 libxaw7 libxcomposite1 libxdamage1 libxfixes3
  libxfont1 libxkbfile1 libxmu6 libxpm4 libxrandr2 libxrender1 libxt6
  x11-common x11-xkb-utils xfonts-base xfonts-encodings xfonts-utils
  xserver-common xserver-xorg-core
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  virtualbox-guest-dkms* virtualbox-guest-utils* virtualbox-guest-x11*
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 11.1 MB disk space will be freed.
(Reading database ... 65615 files and directories currently installed.)
Removing virtualbox-guest-dkms ...

-------- Uninstall Beginning --------
Module:  virtualbox-guest
Version: 4.2.16
Kernel:  3.11.0-18-generic (i686)
-------------------------------------

Status: Before uninstall, this module version was ACTIVE on this kernel.

vboxguest.ko:
 - Uninstallation
   - Deleting from: /lib/modules/3.11.0-18-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.


vboxsf.ko:
 - Uninstallation
   - Deleting from: /lib/modules/3.11.0-18-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.


vboxvideo.ko:
 - Uninstallation
   - Deleting from: /lib/modules/3.11.0-18-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.

depmod....

DKMS: uninstall completed.

------------------------------
Deleting module version: 4.2.16
completely from the DKMS tree.
------------------------------
Done.
Removing virtualbox-guest-x11 ...
Purging configuration files for virtualbox-guest-x11 ...
Removing virtualbox-guest-utils ...
Purging configuration files for virtualbox-guest-utils ...
Processing triggers for ureadahead ...
Processing triggers for man-db ...
Reading package lists...
Building dependency tree...
Reading state information...
dkms is already the newest version.
dkms set to manually installed.
linux-headers-3.11.0-18-generic is already the newest version.
linux-headers-3.11.0-18-generic set to manually installed.
The following packages were automatically installed and are no longer required:
  libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontenc1 libgl1-mesa-dri
  libglapi-mesa libice6 libllvm3.3 libpciaccess0 libpixman-1-0 libsm6
  libtxc-dxtn-s2tc0 libxaw7 libxcomposite1 libxdamage1 libxfixes3 libxfont1
  libxkbfile1 libxmu6 libxpm4 libxrandr2 libxrender1 libxt6 x11-common
  x11-xkb-utils xfonts-base xfonts-encodings xfonts-utils xserver-common
  xserver-xorg-core
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Copy iso file /usr/share/virtualbox/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
mount: block device /tmp/VBoxGuestAdditions.iso is write-protected, mounting read-only
Installing Virtualbox Guest Additions 4.3.10 - guest version is 4.2.16
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.10 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
Starting the VirtualBox Guest Additions ...done.
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
An error occurred during installation of VirtualBox Guest Additions 4.3.10. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Exporting NFS shared folders...
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
nfsd running
sudo: /usr/bin/exportfs: command not found
==> default: Mounting NFS shared folders...
==> default: Mounting shared folders...
    default: /vagrant => /home/me/Documents/Work/project/vagrant
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` /vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` /vagrant /vagrant

我的Vagrantfile配置是:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

personalization = File.expand_path("../Personalization", __FILE__)
load personalization

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = $base_box
  config.vm.box_url = $base_box_url

  config.vm.hostname = $vhost + ".dev"

  config.hostsupdater.aliases = ["api." + $vhost + ".dev", "mysql." + $vhost + ".dev"]
  config.hostsupdater.remove_on_suspend = true

  # set auto_update to ture to check the correct 
  # additions version when booting the machine
  config.vbguest.auto_update = true
  config.vbguest.auto_reboot = true

  config.vm.network :private_network, ip: $ip

  config.vm.synced_folder "../", "/srv/www/vhosts/" + $vhost + ".dev", type: "nfs"

  config.vm.provider :virtualbox do |v|
    v.customize ["modifyvm", :id, "--memory", 2048]
    v.customize ["modifyvm", :id, "--cpus", "1"]
    v.customize ["modifyvm", :id, "--cpuexecutioncap", "100"]
    v.customize ["modifyvm", :id, "--ioapic", "off"]
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end

  config.vm.provision "shell" do |s|
    s.path = "vagrant-bootstrap.sh"
    s.args = $vhost + " " + $mysql_password + " " + $application_database
  end
end

Personalization文件是:

# Name of the vhost to create
$vhost = "project"

# Use the Ubunut 32bit or 64bit
$base_box_url = "http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-i386-vagrant-disk1.box"

# VM IP
$ip = "192.168.7.7"

# Base box name
$base_box = "u131032"

# MySQL
$mysql_password = "admin"
$application_database = "project"

在Vagrant中启用了以下插件:

$ vagrant plugin list
vagrant-hostsupdater (0.0.11)
vagrant-login (1.0.1, system)
vagrant-share (1.0.1, system)
vagrant-vbguest (0.10.0)

您的日志抱怨没有找到出口: Sudo: /usr/bin/exportfs:命令不存在

exportfs使NFS客户机可以挂载本地目录。


我发现这个问题在这里解决流浪者问题。有两种方法:

在guest上运行此命令(即在您通过vagrant ssh ssh跳转到vbox之后) sudo ln -s /opt/ vboxguestextensions -4.3.10/lib/ vboxguestextensions /usr/lib/ vboxguestextensions . sudo ln -s /opt/ vboxguestextensions -4.3.10/lib/ vboxguestextensions . txt 然后运行vagrant reload以正确挂载文件夹。 正如@klang指出的,更新VBoxGuestAdditions。mac上的Iso文件: wget https://www.virtualbox.org/download/testcase/vboxguestadditions_4.3.11 - 93070. - iso‌ sudo cp VBoxGuestAdditions_4.3.11-93070.使用实例iso /应用程序/ VirtualBox.app /内容/ MacOS / VBoxGuestAdditions.iso

更新(16 may2014)

由于iso不再可用,您可以使用4.3.12版本(http://dlc.sun.com.edgesuite.net/virtualbox/4.3.12/VBoxGuestAdditions_4.3.12.iso)

注意:针对os X的二进制vbox4.3.12目前还不可用


(来自我上面的评论)

追踪问题的根源,特别是评论中的部分是这样说的:

wget https://www.virtualbox.org/download/testcase/VBoxGuestAdditions_4.3.11-93070.iso‌​ 
sudo cp VBoxGuestAdditions_4.3.11-93070.iso /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso

在这之后,我和往常一样处理我所有的虚拟机(当然还有它们当前的Vagrantfiles)

当您必须在新创建的虚拟机中执行某些操作以使其工作时,一定是出了问题。


这似乎是由于与vbguest vagrant插件和最新版本的vagrant不兼容。它试图更新客户添加,但未能完全/正确地做到这一点。


正如在流浪者问题#3341中提到的,这是一个Virtualbox错误#12879。

它只影响VirtualBox 4.3.10,并在4.3.12中完全修复。


在遵循kenzie提出的第一个建议之后,我必须完成的另一个步骤是使用Ubuntu命令行[14.04 Server]中的sudo运行错误消息中列出的mount命令。从那以后,一切都好了!


插件vagrant-vbguest解决了我的问题:

$ vagrant plugin install vagrant-vbguest

输出:

$ vagrant reload
==> default: Attempting graceful shutdown of VM...
...
==> default: Machine booted and ready!
GuestAdditions 4.3.12 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Exporting NFS shared folders...
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
==> default: Mounting NFS shared folders...
==> default: VM already provisioned. Run `vagrant provision` or use `--provision` to force it

只要确保你运行的是最新版本的VirtualBox


我在寻找相同的错误消息时到达了这个页面。 对我来说,原因是不同的:我在系统上运行了yum更新,安装了一个新内核。附加的客人已经过时了,所以它不能加载他们。

我用

sudo /etc/init.d/vboxadd setup 

后来我的客人又重新装弹了。

我只是把它加在这里,以防有人和我一样来这里。

编辑(根据KCD的评论): 你可能会得到这样一个错误:

未找到当前运行内核的头文件

这可以通过安装kernel-devel来解决。


步骤:

如果你没有vbguest插件,安装它:

$ vagrant plugin install vagrant-vbguest

运行的流浪汉

它显示一个错误。

$ vagrant up

虚拟机登录

$ vagrant ssh

Fix!

在客户端(虚拟机有日志记录)。

$ sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions

回到主机,重新加载流浪者

$ vagrant reload

在配置中,windows是主机,linux是客户,我在其他地方找到了相同问题的解决方案。

同样,错误消息是“在Linux客户中挂载文件夹失败。”这通常是因为“vboxsf”文件系统不可用。(…)

这是因为我犯了一个错误,在客户系统中从/vagrant到/home/vagrant/vagrant进行符号链接。关键是,目录/vagrant是一个正常的linux目录,它有一个符号链接(所以都ok),但是当通过“vagrant up”引导时,它会尝试在那个地方挂载windows目录,而windows目录不能作为符号链接工作。Windows主机不支持linux符号链接。

所以你能做的是,ssh进入guest,删除符号链接,然后重新加载机器。

在我的配置中是:Vagrant 1.7.2, VBoxGuestAdditions 4.3.28和VBox 4.3.28。


我相信这是现在更新的答案,它为我工作(客户添加版本:5.0.6,VirtualBox版本:4.3.16,Ubuntu 14.04 LTS)

https://github.com/mitchellh/vagrant/issues/3341#issuecomment-144271026

基本上i说:

Simple and Quick Solution for Failed to mount folders in Linux guest issue.

Add the following line to your Homestead/Vagrantfile:

config.vbguest.auto_update = false
Your Homestead/Vagrantfile should looks like this:

/...

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

   # To avoid install and uninstall VBoxGuessAdditions during vagrant provisioning.
    config.vbguest.auto_update = false

.../
Save it and execute

$ vagrant destroy --force
$ vagrant up

仅供将来参考,这个问题发生在我身上,使用Vagrant 1.7.4和VirtualBox 5.0.10 r104061时,我在/中提供了一个共享文件夹,并创建了到我的主文件夹的符号链接。就像这样:

/folder
~/folder -> /folder

显然,出于安全考虑,Vagrant不允许该操作,并抛出上述错误。

我解决了这个问题,把所需的文件夹直接提供给我的主目录,比如/home/vagrant/folder。


2016年2月更新

我花了好几个小时独立解决这个问题。是的,这个问题在最新的Vagrant和Virtual Box安装中仍然存在:

△  vagrant -v
Vagrant 1.8.1
△  vboxmanage -v
5.0.14r105127

对我来说,症状是这样的信息:

检查客户添加在VM…此虚拟机上的客户添加程序与安装的VirtualBox版本不匹配!

随之而来的是NFS驱动器挂载失败。

1).安装vagrant-vbguest插件。

根据您正在使用的Vagrant版本,发出以下命令之一:

# For vagrant < 1.1.5
$ vagrant gem install vagrant-vbguest

# For vagrant 1.1.5+
$ vagrant plugin install vagrant-vbguest

接下来,做流浪者暂停,然后流浪者向上-机会是你仍然有问题。

2). ssh到您的客户端,并设置一个软链接到正确版本的客户添加(这里,5.0.14)。

$ vagrant ssh

$ sudo ln -s /opt/VBoxGuestAdditions-5.0.14/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
$ exit

$ vagrant reload

你应该会没事的。默认情况下,guest上挂载的驱动器位于/vagrant

最后的评论:

如果您仍然存在与挂载NFS驱动器相关的问题,那么这里有一个对我有用的解决方法。我有一个vagrantfile配置如下:

只需删除挂载类型信息,并精简mount_options设置,以便它们可以通用。Vagrant现在会自动为您的环境选择最佳的同步文件夹选项。


我在使用Centos 7时也遇到了同样的问题,我认为这是由于一个过时的内核加上更新版本的VirtualBox造成的。基于blizzard的更新,这对我来说是有效的(vagrant-vbguest插件已经安装):

vagrant ssh
sudo yum -y install kernel-devel
sudo yum -y update
exit
vagrant reload --provision

安装vagrant-vbguest插件:

vagrant plugin install vagrant-vbguest

现在是2017年。以防有人遇到同样的问题。

对于bento/centos-6.7,我得到了同样的错误。通过添加插件vagrant-vbguest(0.13.0)解决了这个问题。 C:> vagrant plugin install vagrant-vbguest

邮箱网址:http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.0_chef-provisionerless.box

这个centos-7版本也给出了同样的错误

错误:

==> build: Mounting shared folders...
    build: /vagrant => C:/projects/
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

我的配置:

C:\projects>vagrant -v
Vagrant 1.9.1

C:\projects> vboxmanage -v
5.0.10r104061

C:\projects>vagrant plugin list
vagrant-cachier (1.2.1)
vagrant-hostmanager (1.8.5)
vagrant-hosts (2.8.0)
vagrant-omnibus (1.5.0)
vagrant-share (1.1.6, system)
vagrant-vbguest (0.13.0)
vagrant-vbox-snapshot (0.0.10)

因为我已经有流浪者-vbguest插件,它试图更新VBoxGuestAdditions在centos-7当它看到不同版本的VBGuestAdditions安装在主机5.0.10和客户4.3.20。

我甚至检查了符号链接存在。

[root@build VBoxGuestAdditions]# ls -lrt /usr/lib
lrwxrwxrwx.  1 root root   53 Jan 14 12:06 VBoxGuestAdditions -> /opt/VBoxGuestAdditions-5.0.10/lib/VBoxGuestAdditions
[root@build VBoxGuestAdditions]# mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant
/sbin/mount.vboxsf: mounting failed with the error: No such device

这没有按照user3006381的建议工作

vagrant ssh
sudo yum -y install kernel-devel
sudo yum -y update
exit
vagrant reload --provision

centos-7的解决方案:psychok7给出的有效

见鬼的自动更新。config.vbguest。Auto_update = false 然后流浪汉破坏——强迫和流浪汉起来

结果:

javareport: Guest Additions Version: 4.3.20
javareport: VirtualBox Version: 5.0
==> javareport: Setting hostname...
==> javareport: Configuring and enabling network interfaces...
==> javareport: Mounting shared folders...
javareport: /vagrant => C:/projects

C:\project>

对我来说,与VBoxGuestAdditions 5.1.20,问题是/sbin/mount.Vboxsf指向错误的位置。

sudo ln -sf /opt/ vboxguestextensions -5.1.20/lib/ vboxguestextensions /mount. shvboxsf /sbin/mount.vboxsf

为我修正了


在我之前使用的Ubuntu 16.04镜像中,错误是在为不同的vagrant镜像安装vagrant-vbguest后开始的,然后启动Ubuntu虚拟机。它升级了客户附加到5.1.20,从那时起,坐骑开始失败。更新框,apt更新+升级和相同,vbguest将安装更新的5.1.20版本。

通过手动运行来解决:

sudo apt-get update
sudo apt-get install virtualbox-guest-dkms 

同时禁用:config.vbguest。Auto_update = false (可能不需要)。


试着这样做:

vagrant plugin install vagrant-vbguest

在Vagrantfile中添加:

config.vbguest.iso_path = "http://download.virtualbox.org/virtualbox/VERSION/VBoxGuestAdditions_VERSION.iso"
config.vbguest.auto_update = false
config.vbguest.installer_arguments = %w{--nox11 -- --force}

Run:

vagrant vbguest --do install -f -b

vagrant reload

我用VirtualBox 5.1运行Vagrant。X,不得不降级到VirtualBox 5.0.40,并安装vbguest插件来解决这个问题。

我的步骤是:

卸载VirtualBox 5.1.X 安装Vagrant 5.0.40 重启我的机器 为我的流浪汉跑个流浪汉。它会失败。 在我的虚拟机运行时运行vagrant plugin install vagrant-vbguest,安装vagrant插件。这管理同步VirtualBox客户版本之间的主机和客户。 运行vagrant reload来重载我的虚拟机 魔法!


到目前为止,安装在一些机器(ubuntu)上可以工作,而一些机器则不能(centos 7) 但是安装插件可以解决这个问题

vagrant plugin install vagrant-vbguest

除此之外什么都不用做,只要

vagrant reload

vagrant plugin install vagrant-vbguest
vagrant destroy #clean rhel/yum repos
vagrant up

在配置文件中:

config.vbguest.auto_update = false #important so that any changes to the base image don't affect on reload