Help us understand the problem. What is going on with this article?

Vagrantでマウントエラーが発生したときの解消方法

More than 1 year has passed since last update.

環境

  • MacOS X
  • Vagrant 2.0.1
  • VirtualBox 5.2.4
  • CentOS 6.5

エラー

Vagrant+VirtualBoxにおける仮想マシン(VM)立ち上げ時において、
起動$ vagrant upを実行すると共有フォルダでマウントエラーが発生する。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/centos-6.8' is up to date... 
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
        ・
        ・
        ・
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 5.1.18
    default: VirtualBox Version: 5.2
==> default: Configuring and enabling network interfaces...
      ・
      ・
      ・

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=500,gid=500 vagrant /vagrant

The error output from the command was:

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

しかし、VMの立ち上げは成功し、Vagrantにsshでログイン$ vagrant sshすることが可能である。
⇒ SSH接続は可

$ vagrant status
Current machine states:

default                   running (virtualbox)

The VM is powered off. To restart the VM, simply run `vagrant up`


$ vagrant ssh
Last login: Mon Jan 15 16:39:43 2018 from 10.0.2.2

原因

調べてみたら、同様の実証があったので以下掲載する。

ホスト⇔ゲスト間のフォルダ共有機能はGuest Additionsが提供していますが
ホスト(VirtualBox)とゲスト(Guest Additions)でバージョン不一致があるとマウントエラーが起きるようです。
[参考URL]:https://qiita.com/ozawan/items/9751dcfd9bd4c470cd82

整理すると、

  • VirtualBoxには、VirtualBox Guest Addition がインストールされている。
    ⇒ VirtualBox Guest Addition = ゲスト(Guest Additions)
  • 自分の環境にあるホスト(VirtualBox)には、デフォルトの設定により仮想マシン(VM)起動時にバージョンが古ければ自動更新される。

そのため、起動時にホスト(VirtualBox)のみバージョン更新されるので、
ホスト(VirtualBox)のバージョンとホスト(VirtualBox)にインストールされているゲスト(Guest Additions)のバージョン間に差異が生じバージョン不一致によるマウントエラーが起きる。

解決方法

vagrant-vbguest というプラグインをインストールすることにより、
起動時$ vagrant upに自動的にホスト(VirtualBox)のバージョンに合わせて、ゲスト(Guest Additions)のバージョンを更新してくれるらしい。
$ vagrant plugin install vagrant-vbguest

$ vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching: vagrant-share-1.1.9.gem (100%)
Fetching: micromachine-2.0.0.gem (100%)
Fetching: vagrant-vbguest-0.15.1.gem (100%)
Installed the plugin 'vagrant-vbguest (0.15.1)'!


$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/centos-6.8' is up to date...
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.


$ vagrant status
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

インストールしたことにより、
ホスト(VirtualBox)とゲスト(Guest Additions)のバージョンが同等になりエラーが解消された。  

おまけ

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした