Vagrant错误:无法安装VirtualBox共享文件夹(Guest Additions,vboxsf)

34

问题

我在Windows 10上安装了Vagrant,以便在虚拟机中创建个人本地开发环境。我读到的有关Vagrant的所有信息都说我甚至可以启动多个系统,并使用NAT端口转发测试它们之间的通信。但是首先,我只想创建一个开发环境的虚拟机,在进行其余操作之前。

按照SitePoint教程:https://www.sitepoint.com/getting-started-vagrant-windows/,我安装了VirtualBox、Vagrant、PuTTy和PuTTYGen。接下来,我在C:驱动器上创建了一个vagrant项目文件夹,执行了vagrant init,删除了Vagrantfile,最后执行了vagrant init ubuntu/trusty64。然后我执行了vagrant up,但是该过程失败并显示以下错误:

Vagrant无法挂载VirtualBox共享文件夹。这通常是因为文件系统“vboxsf”不可用。此文件系统通过VirtualBox Guest Additions和内核模块提供。请验证这些Guest Additions是否已正确安装在guest中。这不是Vagrant中的错误,通常是由于有缺陷的Vagrant box引起的。针对此命令的上下文是:

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

命令的错误输出为:

: No such file or directory

这是我的Windows命令行的屏幕截图:

Vagrant/VirtualBox错误截图

以下是文本版本:

C:\vagrant\sitepoint-test-2017-02-05>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> default: have version '20160602.0.0'. The latest is version '20170202.0.0'. Run
==> default: `vagrant box update` to update.
==> default: Setting the name of the VM: sitepoint-test-2017-02-05_default_1486399403587_55255
==> 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: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> 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: Warning: Remote connection disconnect. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => C:/vagrant/sitepoint-test-2017-02-05
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:

: No such file or directory

我的设置

OS: Microsoft Windows [Version 10.0.14393]
VirtualBox Version: 4.3.10 r93012
GuestAdditions Version: ???
Vagrant Version: 1.9.1 (Latest)
PuTTy Version: 0.67
PuTTYGen Version: 0.67

已安装的插件和扩展

Vagrant:
- vagrant-share (1.1.6, system)
- vagrant-vbguest (0.13.0)

我已经尝试过的方法

这篇文章在我的研究中似乎是最有希望的。

不幸的是,提供的解决方案以及提供的链接都没有解决问题。我已经尝试了很多东西,但我不是系统管理员(我猜想这是需要解决问题的技能集)。特别令人不安的是,许多2013/2014年的“解决方案”最近被指示为不再起作用。这些解决方案涉及到符号链接无法工作、安装像vagrant-vbguest这样的插件,以及关于vbox添加不能匹配某些内容的问题。我并不完全理解这一切,但我尽力了。以下是我已经尝试过但仍未解决问题的内容:

  1. vagrant plugin install vagrant-vbguest。Vagrant显示插件已安装,但我在vagrant up时仍然遇到同样的错误。

  2. 我阅读的与此问题相关的链接列表,没有提供有效的解决方案。

我的问题

  1. 我怀疑问题出在VirtualBox上,而不是Vagrant。这是真的吗?

  2. 我该如何解决此问题以便能够继续进行教程?

  3. 自2014年左右以来,在Stack Overflow上回答有关Vagrant的问题数量似乎已经大幅减少。这是什么原因呢?Vagrant/VirtualBox不再被认为是“最佳实践”了吗?是否有更好的解决方案,以至于用户正在忽略Vagrant问题?

再次声明,我不是系统管理员,但我在技术方面很有经验,并且可以遵循技术指导。


嘿,Eric,你找到任何解决方案了吗?我的朋友也遇到了这个问题,我正在帮他寻找解决方案,但是我找到的所有方法都对他没用。 - Rizki Pratama
@softtama 最好且最简单的解决方案是将VirtualBox降级至5.1.14版本。此问题相关链接:https://github.com/mitchellh/vagrant/issues/8352 - Hype
11个回答

1

摘要

同步/共享文件夹突然停止工作的问题在于VirtualBox客户附加内核模块未加载。

问题与VirtualBox版本没有直接关联!过去可能是这种情况,但以下解释涵盖了此问题约95%的发生率。


说明

这主要是由Linux内核的自动更新引起的,例如在虚拟机中运行。

如果内核有新版本,则在虚拟机重新启动后无法重新启动用于增强客户机的dkms模块。 服务文件/etc/init.d/virtualbox-guest-utils检查是否存在一个内核模块。

/lib/modules/`uname -r`

vboxguestvboxsf的文件夹。

让增强功能初始设置时的内核版本为:1.2.3

更新后的内核版本为:1.2.4

uname -r将导致1.2.4,而dkms模块是使用内核版本1.2.3安装的。这将导致虚拟机增强服务中止执行并失败,并显示类似于modprobe xxxx failed....的错误消息。

解决方案

我们需要做的是,与新的内核版本一起安装内核头文件,以便虚拟机增强功能的dkms模块可以自动重建。

幸运的是,有一个元包让我们安装最新版本的内核头文件。

在不同的Linux版本中,它的名称似乎有所不同。以下是其中的一些。

Debian

sudo apt install linux-headers-amd64

Ubuntu

sudo apt install linux-headers-generic

CentOS(未经测试)

感谢@Jayen Chondigara

sudo yum -y install kernel-headers kernel-devel


我认为这是非常好的解释和正确的解决方案! - elb98rm

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