问题描述

当启动Vagrant VM时,会遇到无法正常挂载文件夹的错误。错误信息如下:

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:

stdin: is not a tty
/sbin/mount.vboxsf: mounting failed with the error: No such device

问题原因

当在VM中升级了内核,如运行了

$ yum update

或者

$ sudo apt-get update

当再次开启该VM时,就会遇到无法挂载文件夹的问题。

完整的错误信息如下:

$ vagrant up dockerdev
Bringing machine 'dockerdev' up with 'virtualbox' provider...
==> dockerdev: Checking if box 'ubuntu/trusty64' is up to date...
==> dockerdev: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> dockerdev: have version '20150922.0.0'. The latest is version '20161109.0.0'. Run
==> dockerdev: `vagrant box update` to update.
==> dockerdev: Clearing any previously set forwarded ports...
==> dockerdev: Clearing any previously set network interfaces...
==> dockerdev: Preparing network interfaces based on configuration...
  dockerdev: Adapter 1: nat
  dockerdev: Adapter 2: hostonly
==> dockerdev: Forwarding ports...
  dockerdev: 22 => 2222 (adapter 1)
==> dockerdev: Running 'pre-boot' VM customizations...
==> dockerdev: Booting VM...
==> dockerdev: Waiting for machine to boot. This may take a few minutes...
  dockerdev: SSH address: 127.0.0.1:2222
  dockerdev: SSH username: vagrant
  dockerdev: SSH auth method: private key
  dockerdev: Warning: Connection timeout. Retrying...
  dockerdev: Warning: Remote connection disconnect. Retrying...
==> dockerdev: Machine booted and ready!
==> dockerdev: Checking for guest additions in VM...
  dockerdev: The guest additions on this VM do not match the installed version of
  dockerdev: VirtualBox! In most cases this is fine, but in rare cases it can
  dockerdev: prevent things such as shared folders from working properly. If you see
  dockerdev: shared folder errors, please make sure the guest additions within the
  dockerdev: virtual machine match the version of VirtualBox you have installed on
  dockerdev: your host and reload your VM.
  dockerdev:
  dockerdev: Guest Additions Version: 4.3.10
  dockerdev: VirtualBox Version: 5.0
==> dockerdev: Setting hostname...
==> dockerdev: Configuring and enabling network interfaces...
==> dockerdev: Mounting shared folders...
  dockerdev: /vagrant => E:/vagrant_project
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:

stdin: is not a tty
/sbin/mount.vboxsf: mounting failed with the error: No such device

解决方法

首先,在宿主机运行

$ vagrant plugin install vagrant-vbguest

然后,重新启动VM

$ vagrant halt dockerdev
$ vagrant up dockerdev

正常启动后,VM就可以成功挂载文件夹。

启动的trace如下。

Bringing machine 'dockerdev' up with 'virtualbox' provider...
==> dockerdev: Checking if box 'ubuntu/trusty64' is up to date...
==> dockerdev: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> dockerdev: have version '20150922.0.0'. The latest is version '20161109.0.0'. Run
==> dockerdev: `vagrant box update` to update.
==> dockerdev: Clearing any previously set forwarded ports...
==> dockerdev: Clearing any previously set network interfaces...
==> dockerdev: Preparing network interfaces based on configuration...
  dockerdev: Adapter 1: nat
  dockerdev: Adapter 2: hostonly
==> dockerdev: Forwarding ports...
  dockerdev: 22 => 2222 (adapter 1)
==> dockerdev: Running 'pre-boot' VM customizations...
==> dockerdev: Booting VM...
==> dockerdev: Waiting for machine to boot. This may take a few minutes...
  dockerdev: SSH address: 127.0.0.1:2222
  dockerdev: SSH username: vagrant
  dockerdev: SSH auth method: private key
  dockerdev: Warning: Connection timeout. Retrying...
==> dockerdev: Machine booted and ready!
[dockerdev] GuestAdditions versions on your host (5.0.4) and guest (4.3.10) do not match.
stdin: is not a tty
 * Stopping VirtualBox Additions
  ...done.
rmmod: ERROR: Module vboxsf is not currently loaded
rmmod: ERROR: Module vboxguest is not currently loaded
stdin: is not a tty
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  dkms fakeroot gcc gcc-4.8 libasan0 libatomic1 libc-dev-bin libc6-dev
  libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfakeroot libfontenc1
  libgcc-4.8-dev libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libgomp1
  libice6 libitm1 libllvm3.4 libpciaccess0 libpixman-1-0 libquadmath0 libsm6
  libtsan0 libtxc-dxtn-s2tc0 libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0
  libxcb-glx0 libxcb-present0 libxcb-sync1 libxcomposite1 libxdamage1
  libxfixes3 libxfont1 libxkbfile1 libxmu6 libxpm4 libxrandr2 libxrender1
  libxshmfence1 libxt6 libxxf86vm1 linux-libc-dev manpages-dev 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 159 not upgraded.
After this operation, 12.1 MB disk space will be freed.
(Reading database ... 71932 files and directories currently installed.)
Removing virtualbox-guest-dkms (4.3.10-dfsg-1ubuntu5) ...

-------- Uninstall Beginning --------
Module: virtualbox-guest
Version: 4.3.10
Kernel: 3.13.0-63-generic (x86_64)
-------------------------------------

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

vboxguest.ko:
 - Uninstallation
  - Deleting from: /lib/modules/3.13.0-63-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.13.0-63-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.13.0-63-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.3.10
completely from the DKMS tree.
------------------------------
Done.
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.6) ...
stdin: is not a tty
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontenc1 libgl1-mesa-dri
  libgl1-mesa-glx libglapi-mesa libice6 libllvm3.4 libpciaccess0 libpixman-1-0
  libsm6 libtxc-dxtn-s2tc0 libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0
  libxcb-glx0 libxcb-present0 libxcb-sync1 libxcomposite1 libxdamage1
  libxfixes3 libxfont1 libxkbfile1 libxmu6 libxpm4 libxrandr2 libxrender1
  libxshmfence1 libxt6 libxxf86vm1 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 extra packages will be installed:
  linux-headers-3.13.0-101
Suggested packages:
  dpkg-dev debhelper
The following NEW packages will be installed:
  linux-headers-3.13.0-101 linux-headers-3.13.0-101-generic
The following packages will be upgraded:
  dkms
1 upgraded, 2 newly installed, 0 to remove and 158 not upgraded.
Need to get 9,629 kB of archives.
After this operation, 77.0 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main dkms all 2.2.0.3-1.1ubuntu5.14.04.9 [65.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main linux-headers-3.13.0-101 all 3.13.0-101.148 [8,867 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty-updates/main linux-headers-3.13.0-101-generic amd64 3.13.0-101.148 [697 kB]
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Fetched 9,629 kB in 45s (210 kB/s)
(Reading database ... 71658 files and directories currently installed.)
Preparing to unpack .../dkms_2.2.0.3-1.1ubuntu5.14.04.9_all.deb ...
Unpacking dkms (2.2.0.3-1.1ubuntu5.14.04.9) over (2.2.0.3-1.1ubuntu5.14.04.2) ...
Selecting previously unselected package linux-headers-3.13.0-101.
Preparing to unpack .../linux-headers-3.13.0-101_3.13.0-101.148_all.deb ...
Unpacking linux-headers-3.13.0-101 (3.13.0-101.148) ...
Selecting previously unselected package linux-headers-3.13.0-101-generic.
Preparing to unpack .../linux-headers-3.13.0-101-generic_3.13.0-101.148_amd64.deb ...
Unpacking linux-headers-3.13.0-101-generic (3.13.0-101.148) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up dkms (2.2.0.3-1.1ubuntu5.14.04.9) ...
Setting up linux-headers-3.13.0-101 (3.13.0-101.148) ...
Setting up linux-headers-3.13.0-101-generic (3.13.0-101.148) ...
Examining /etc/kernel/header_postinst.d.
run-parts: executing /etc/kernel/header_postinst.d/dkms 3.13.0-101-generic /boot/vmlinuz-3.13.0-101-generic
Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
stdin: is not a tty
mount: block device /tmp/VBoxGuestAdditions.iso is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.0.4 - guest version is 4.3.10
stdin: is not a tty
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.4 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 5.0.4. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
stdin: is not a tty
==> dockerdev: Checking for guest additions in VM...
==> dockerdev: Setting hostname...
==> dockerdev: Configuring and enabling network interfaces...
==> dockerdev: Mounting shared folders...
  dockerdev: /vagrant => E:/vagrant_project
==> dockerdev: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> dockerdev: flag to force provisioning. Provisioners marked to run always will still run.

Stackoverflow上相关的问题讨论 -> 链接

本文链接: https://xzdbd.com/blog/solution-of-vagrant-mount-issue-failed-to-mount-folders-in-linux-guest参与评论»

–EOF–