Vagrant错误:在Linux客户机中无法挂载文件夹

284

我在使用Vagrant共享文件夹时遇到了一些问题,我的基本系统是Ubuntu 13.10桌面版。

我不明白为什么会出现这个错误,是配置不正确吗?是NFS问题还是Virtualbox Guest Additions的问题?我已经尝试过很多不同的boxes,但是问题仍然存在。

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

个性化文件是:

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

这个问题也发生在我身上,是在我更新VirtualBox 5.1.20之后。每次更新我的虚拟机时都会让我感到担忧,因为这不是第一次了 :( - GusDeCooL
@GusDeCooL 你可以在 Vagrantfile 中使用 config.vbguest.auto_update = false 关闭客户机附加组件的自动更新。 - Henrik
22个回答

3

为了以后参考,我在使用Vagrant 1.7.4和VirtualBox 5.0.10 r104061时,出现了一个问题,当我在/中创建共享文件夹并创建指向我的主目录的符号链接时,就会发生这种情况。

/folder
~/folder -> /folder

显然,由于安全原因,Vagrant不允许执行这个操作并抛出上述错误。

我通过将所需的文件夹直接提供到我的home目录中解决了此问题,例如/home/vagrant/folder


1
非常感谢。这也是我的问题。 - Sarcastron
1
正确的,在我的 Vagrant 版本(1.8.1)中,/ 中的共享文件夹也是不允许的。 - Amedee Van Gasse

2
在我的情况下,在之前正常工作的Ubuntu 16.04镜像上安装vagrant-vbguest用于不同的vagrant镜像,并启动Ubuntu VM后出现了错误。它升级了客户机附加组件到5.1.20,从那时起挂载就开始失败了。更新了box,apt更新+升级仍然是一样的,vbguest会安装更新的5.1.20版本。
通过手动运行以下命令解决了问题:
sudo apt-get update
sudo apt-get install virtualbox-guest-dkms 

同时,禁用以下设置:config.vbguest.auto_update = false 对于此虚拟机(可能不是必需的)。


我曾经遇到过完全相同的问题。忽略有关客户机和主机版本不匹配的警告,并关闭自动更新。 - Henrik

1
在Windows作为主机,Linux作为客户机的配置中,我在其他地方找到了相同问题的解决方案。因此,错误消息是“无法在Linux客户机中挂载文件夹。这通常是因为“vboxsf”文件系统不可用。” 这是由于我在客户机内从/vagrant创建了符号链接到/home/vagrant/vagrant时犯了错误。重点是,/vagrant目录是一个正常的Linux目录,有一个符号链接(所以一切正常),但是当通过“vagrant up”启动时,它会尝试在那个位置上挂载Windows目录,而Windows目录不能作为符号链接工作。 Windows主机不支持Linux符号链接。因此,您可以通过ssh进入guest,删除您拥有的符号链接,并重新加载机器。在我的配置中,它是:Vagrant 1.7.2,VBoxGuestAdditions 4.3.28和VBox 4.3.28。

1

目前,在一些机器上(Ubuntu)已经安装成功,而在另一些机器上(CentOS 7)则没有。不过,安装插件可以解决这个问题。

vagrant plugin install vagrant-vbguest

无需进行其他操作,只需如此

vagrant reload

1
我会尽力帮助您翻译。以下是需要翻译的内容:

(来自我的评论)

追根溯源,特别是评论中提到的部分,即:

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

如果你在一个全新创建的虚拟机中必须执行某些操作才能使其正常工作,那么可能存在问题。


1
如果您使用的是Linux系统,我猜您需要将文件复制到/usr/share/virtualbox/VBoxGuestAdditions.iso。但是我没有测试过! - tsusanka

1

这是2017年的情况。以防万一有人遇到同样的问题。

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

Box url: 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)

由于我已经安装了vagrant-vbguest插件,当它发现主机5.0.10和客户端4.3.20中的VBGuestAdditions版本不同时,它会尝试更新centos-7中的VBoxGuestAdditions。

我甚至已经检查了符号链接是否存在。

[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 然后执行vagrant destroy --forcevagrant up

结果:

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>

对于我来说,现在是2017年,仍然存在这个错误。您的修复方法看起来很有希望。我会尝试并报告结果。 - Eric Hepperle - CodeSlayer2010

0

你的日志显示找不到exportfs: sudo: /usr/bin/exportfs: command not found

exportfs 使本地目录可供NFS客户端挂载。


1
我已经通过使用命令 sudo ln -s /usr/sbin/exportfs /usr/bin/exportfs 将符号链接设置为实际路径,解决了关于 sudo: /usr/bin/exportfs: command not found 的问题。然而,在此之后,“在 Linux 客户机中挂载文件夹失败”的错误仍然存在。 - radu c

0

这似乎是由于 vbguest vagrant 插件与最新版本的 vagrant 不兼容所致。它试图更新客户机附加组件,但未能完全/正确地完成。


2
从我所看到的情况来看,vagrant-vbguest 正确地将虚拟机更新到最新的 (4.3.10) GuestAdditions - 不幸的是,最新的 GuestAdditions 对于 Linux 客户端存在一个 bug。 - iheggie

0

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

我的步骤如下:

  • 卸载VirtualBox 5.1.X
  • 安装Vagrant 5.0.40
  • 重新启动我的机器
  • 为我的vagrant运行vagrant up。它会失败。
  • 在我的虚拟机运行时运行vagrant plugin install vagrant-vbguest,以安装vagrant插件。这可以管理主机和客户机之间的VirtualBox Guest版本同步。
  • 运行vagrant reload重新加载我的虚拟机
  • 神奇!

0
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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接