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=777 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が適切にインストール・動作することを確認してください」とのこと。
原因
Guest additionsとはVirtualBox上にインストールされているソフトウェアで、ホストOSとゲストOSの連携機能を提供してくれるものです。
ホスト⇔ゲスト間のフォルダ共有機能もGuest Additionsが提供しています。
ホストとゲストでGuest additionsのバージョン不一致があるとマウントエラーが起きるようです。
対処法
vagrant up時に自動的に新しいバージョンのGuest Additionsに更新してくれる「vagrant-vbguest」というプラグインをインストールします。
まずは状況確認
まずは、vagrantを起動している状態で、下記コマンドを実行し状況を確認。
(マウントエラーが出ていても、起動はできるはず。)
$ vagrant vbguest --status
マッチしていない時:
GuestAdditions versions on your host (5.0.16) and guest (5.0.12) do not match.
マッチしている時:
GuestAdditions 5.0.16 running --- OK.
今回はエラーが出ているのでdo not match.のメッセージが表示されるかと思います。
vagrant-vbguestのインストール
以下のコマンドでvagrant-vbguestをインストール。
$ vagrant plugin install vagrant-vbguest
Guest Additionsのアップデート
ホストOS側で以下のコマンドを実行。
$ vagrant vbguest
更新が終わったら、再度以下のコマンドで更新できたことを確認。
$ vagrant vbguest --status
GuestAdditions 5.0.16 running --- OK.のようなメッセージが出れば成功。
自動更新の無効化設定
Vagrantfile内で
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end
の記述を追加。
この設定では、vagrant up
の際にGuest Additionsが自動的にアップデートしないようにします。
起動時にゲストOSだけアップデートされるとバージョン不一致で再度エラーが発生するので、更新は無効にしておきます。
仮想マシンの再起動
$ vagrant reload
$ #省略
$ vagrant status
$ #GuestAdditions 5.0.16 running --- OK.が出ていることを確認。
$ vagrant ssh
で再起動して、問題なく入れていれば、成功です。