LoginSignup
283
249

More than 5 years have passed since last update.

Vagrantで共有フォルダのマウントに失敗するときの対処方法

Last updated at Posted at 2016-03-28

現象

vagrant upで仮想マシンを起動するときに以下のようなメッセージが出て、共有フォルダのマウントに失敗することがあります。

エラーメッセージ
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`,dmode=777,fmode=666 vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant`,dmode=777,fmode=666 vagrant /vagrant

The error output from the last command was:

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

原因

ホスト⇔ゲスト間のフォルダ共有機能はGuest Additionsが提供していますが
ホスト(VirtualBox)とゲスト(Guest Additions)でバージョン不一致があるとマウントエラーが起きるようです。

対策

vagrant up時に自動的に新しいバージョンのGuest Additionsに更新してくれる「vagrant-vbguest」というプラグインがあるので、こちらをインストールしておくと良いです。

インストール手順

コマンドプロンプト
vagrant plugin install vagrant-vbguest

マウント失敗している仮想マシンの状態確認 (起動している状態で)

コマンドプロンプト
cd \path\to\vagrant_project\
vagrant vbguest --status
実行結果
GuestAdditions versions on your host (5.0.16) and guest (5.0.12) do not match.

ホストの方が古い場合は、VirtualBoxの最新版をダウンロードしてインストールします。

ゲストの方が古い場合は、vbguestプラグインで更新します。

Guest Additions更新

コマンドプロンプト
vagrant vbguest
実行結果
Installing Virtualbox Guest Additions 5.0.16 - guest version is 5.0.12
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.16 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 5.0.12 of VirtualBox Guest Additions...
Stopping VirtualBox Additions [  OK  ]
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module[  OK  ]
Building the shared folder support module[  OK  ]
Building the OpenGL support module[失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong. The module is not built but the others are.)
Doing non-kernel setup of the Guest Additions[  OK  ]
Starting the VirtualBox Guest Additions [  OK  ]
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.16. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.

Building the shared folder support module[ OK ] と出ていればOK。
(Building the OpenGL support moduleのエラーは無視して良いらしい)

更新確認

コマンドプロンプト
vagrant vbguest --status
実行結果
GuestAdditions 5.0.16 running --- OK.

仮想マシンを再起動

コマンドプロンプト
vagrant reload

vagrant reload = halt → upで、up時に更新処理が実行されるので、vagrant vbguestではなくて最初からvagrant reloadを実行すれば良いはずです。

解消しない場合

逆にvagrant-vbguestが悪影響している場合もありそうです。

boxが古い場合は更新する

vagrant upした時に、新しいバージョンがありますよとメッセージが出る場合は、vagrant box updateでboxを更新すると、Guest Additionsのバージョン不一致が解消する場合があります。

コマンドプロンプト
vagrant up
実行結果
Bringing machine 'web1' up with 'virtualbox' provider...
==> web1: Importing base box 'bento/centos-6.7'...
==> web1: Matching MAC address for NAT networking...
==> web1: Checking if box 'bento/centos-6.7' is up to date...
==> web1: A newer version of the box 'bento/centos-6.7' is available! You currently
==> web1: have version '2.2.3'. The latest is version '2.2.5'. Run
==> web1: `vagrant box update` to update.

現在2.2.3だけど、2.2.5がありますよとのこと。

コマンドプロンプト
vagrant box list
実行結果
bento/centos-6.7 (virtualbox, 2.2.3)

vagrant box updateで更新します。

コマンドプロンプト
vagrant box update
実行結果
==> web1: Checking for updates to 'bento/centos-6.7'
    web1: Latest installed version: 2.2.3
.
.
.
==> web1: Successfully added box 'bento/centos-6.7' (v2.2.5) for 'virtualbox'!
コマンドプロンプト
vagrant box list
実行結果
bento/centos-6.7 (virtualbox, 2.2.3)
bento/centos-6.7 (virtualbox, 2.2.5)

2個出てくるけど、Guest Additionsのバージョン不一致は解消しました。
box remove → vagrant upを実行した方が最新だけ残って良いかも?

その他

vagrant up時に毎回確認すると遅くなって嫌だという人は、自動更新するかどうかをVagrantfile内に記述できるので必要に応じて設定可能です。

Vagrantfile
  # vagrant-vbguestプラグインが入っている場合、自動更新を無効にする設定
  if Vagrant.has_plugin?("vagrant-vbguest") then
    config.vbguest.auto_update = false
  end

グローバルのVagrantfileに記述しても良いみたいです。
場所:ユーザーのホームディレクトリ/.vagrant.d/Vagrantfile
(存在しない場合は自分で作成してOK)

283
249
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
283
249