停止或重新加载后流浪错误 "Failed to mount folders in Linux guest"

Vagrant error "Failed to mount folders in Linux guest" after halt or reload

我正在尝试使用其他人的 Vagrant 盒子,当我第一次启动它时它工作正常,但是在我停止它并使用 vagrant haltvagrant up 重新启动它之后,或 vagrant reload,我收到以下错误消息:

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

The error output from the last command was:

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

现在,搜索此错误消息会发现很多人都遇到了 Virtual Box 4.3.10 错误的问题,但这不是我遇到的问题。

事实证明,升级 Linux 内核会导致 Virtual Box Guest Additions 停止工作,直到它们被 运行 虚拟机中的以下命令重建

sudo /etc/init.d/vboxadd setup

当我运行yum update(类似于apt-get upgrade)获取其他软件的更新时,我没有考虑就升级了内核。

或者,如果您按照 here 所述安装 dkms 软件包,那么当内核更新时,内核模块应该会自动更新。

遇到同样的问题,但修复方法不同:我已经安装了 dkms(Debian Jessie 下的 virtualbox-guest-dkms)。

问题是模块 «vboxsf» 没有自动加载,运行 mount shared_directory 没有工作(No such file or directory 错误)。

但是在运行modprobe vboxsf之后,安装就没问题了

所以我编辑了 /etc/modules 并在新行中附加了 vboxsf:问题已解决!

旁注:如果 运行 modprobe vboxsf 以错误结束,则您没有安装 vboxsf 模块,因此您应该先安装 DKMS 模块。

要解决此问题,必须安装虚拟框添加。比如我用的是Centos 7,先下载centos 7 minimal然后安装guest addition,具体步骤请看下面

  1. 下载centos 7

    流浪者初始化 centos/7

    流浪起来

    vagrant ssh

  2. 为虚拟盒子安装Guest addition

    百胜更新

    重启

    无业游民 ssh

    yum 更新内核

    重启

    无业游民 ssh

    yum groupinstall "Development tools"

    百胜安装kernel-devel

    yum 安装 wget

    wget http://download.virtualbox.org/virtualbox/5.0.2/VBoxGuestAdditions_5.0.2.iso

    须藤 mkdir /media/VBoxGuestAdditions

    sudo mount -o loop,ro VBoxGuestAdditions_5.0.2.iso /media/VBoxGuestAdditions

    sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run rm VBoxGuestAdditions_5.0.2.iso

    sudo 卸载 /media/VBoxGuestAdditions

    sudo rmdir /media/VBoxGuestAdditions

    sudo /etc/init.d/vboxadd 设置

    sudo chkconfig --add vboxadd

    sudo chkconfig vboxadd on

    退出

  3. 包装新盒

    流浪包--base my-virtual-machine

我在使用 Vagrant 1.8.1、VirtualBox 5.0.18、Chef 12.10.10 主机 MacOSX El Capitan 和访客 CentOS7 时遇到了同样的错误。 我尝试在来宾中安装 kernel-devel,安装最新的 GuestAdittions 并更新 yum,但其中 none 对我有用,所以我在我的自定义同步文件夹和 chef 中更改了 "nfs" 的挂载类型临时文件夹,它成功了!

在 Vagrantfile 中,我同步的文件夹:

config.vm.synced_folder ".", "/vagrant", type: "nfs"

和我的 chef_solo 配置:

chef.cookbooks_path = ["chef/cookbooks/"]
chef.synced_folder_type = "nfs"

只需安装 Vagrant 插件 vagrant-vbguest,它可以使您的 VirtualBox Guest Additions 保持最新。

vagrant plugin install vagrant-vbguest

在我遇到同样的错误之后我做了这个:

$ vagrant ssh
$ sudo apt-get update
$ exit

然后安装了vagrant-vbguest

$ vagrant plugin install vagrant-vbguest

然后

$ vagrant halt
$ vagrant up

成功了!

查看日志,似乎 vagrant-vbguest 对来宾(VM)上的 vbguest 添加进行了一些清理。

[default] GuestAdditions versions on your host (4.3.38) and guest (4.3.10) do not match.
 * Stopping VirtualBox Additions
   ...done.
rmmod: ERROR: Module vboxsf is not currently loaded
rmmod: ERROR: Module vboxguest is not currently loaded
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
  virtualbox-guest-dkms* virtualbox-guest-utils* virtualbox-guest-x11*
0 upgraded, 0 newly installed, 3 to remove and 12 not upgraded.
After this operation, 12.1 MB disk space will be freed.
(Reading database ... 113238 files and directories currently installed.)
Removing virtualbox-guest-dkms (4.3.10-dfsg-1ubuntu5) ...
Error! Could not locate dkms.conf file.
File:  does not exist.
Removing virtualbox-guest-x11 (4.3.10-dfsg-1ubuntu5) ...
Purging configuration files for virtualbox-guest-x11 (4.3.10-dfsg-1ubuntu5) ...
Removing virtualbox-guest-utils (4.3.10-dfsg-1ubuntu5) ...
Purging configuration files for virtualbox-guest-utils (4.3.10-dfsg-1ubuntu5) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.9) ...
Reading package lists...
Building dependency tree...
Reading state information...
dkms is already the newest version.
linux-headers-3.13.0-91-generic is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/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.38 - guest version is 4.3.10
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.38 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.

P.S。我在 OS X 上使用以下软件版本:

$ vagrant plugin list
solve (0.8.2)
  - Version Constraint: 0.8.2
vagrant-berkshelf (4.1.0)
vagrant-hostmanager (1.5.0)
  - Version Constraint: 1.5.0
vagrant-hostsupdater (1.0.2)
vagrant-omnibus (1.3.1)
  - Version Constraint: 1.3.1
vagrant-proxyconf (1.2.0)
  - Version Constraint: 1.2.0
vagrant-share (1.1.5, system)
vagrant-vbguest (0.12.0)

$ VBoxManage --version
4.3.38r106717

$ vagrant --version
Vagrant 1.8.4

希望对您有所帮助。

VirtualBox 5.18 修复了这个问题。它存在于 5.16 中,无法通过任何常规方法修复。最新版本 5.18 完美运行。

MAC 上的以下问题显然是由 vagrant 插件版本 vagrant-vbguest-3.0 引起的。

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

umount /mnt

Stdout from the command:

umount: /mnt: not mounted

Stderr from the command:

要解决重新安装 0.21 版本的插件

# uninstall
vagrant plugin uninstall vagrant-vbguest

# install with version 0.21
vagrant plugin install vagrant-vbguest --plugin-version 0.21