LoginSignup
104

More than 5 years have passed since last update.

Vagrantのmountエラーを解決しようとしたらvboxのリビルドがこける

Last updated at Posted at 2014-11-01

vagrantのmountエラー

自分でvagrant packageして作成したboxからvagrant upした際にこんなエラーが出る。

Failed to mount folders in Linux guest. This is usually beacuse
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 apache | cut -d: -f3`,dmode=777,fmode=777 /vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g apache`,dmode=777,fmode=777 /vagrant /vagrant

このエラーは、エラーメッセージの通りゲストOS側で共有フォルダがマウント出来ないときに発生するエラーメッセージ。

対処法その1:macアドレスのマッピングを無効にする

以前にこのエラーでハマったことがあったけど、そのときはこれで治った。
パッケージングする前のmacアドレスのマッピングを覚えてしまってるので、macアドレスのマッピングを無効にしてからパッケージングする。

こちらを参考。

$ vagrant ssh # ゲストOSにログイン
[vagrant@localhost ~]$ sudo ln -s -f /dev/null /etc/udev/rules.d/70-persistent-net.rules

結果

vagrant reloadしたり色々してもエラーが解消しない。
というか、もちろんvagrant packageする前にやってるはずなので……。

対処法その2:vboxのバージョンを上げる

Guest Additionsのバージョンが古いからかもしれない、という可能性に気づいたのでvagrant-vbguestを使ってvboxのバージョンをアップ。
案の定バージョンが古かったので、バージョンアップしたあとで再度vagrant packagevagrant upしてみる。

vagrant-vbguestはこちらを参考に。

結果

やっぱりコケる。あるぇー?

対処法その3:vboxをリビルドする

いろいろ調べてみつつ、こちらを参考にsudo /etc/init.d/vboxadd setupを実行したところ、リビルドがコケる。

$ sudo /etc/init.d/vboxadd setup
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-2.6.32-431.29.2.el6.x86_64

Building the main Guest Additions module                   [失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions              [  OK  ]

エラーログを出力した結果。

$ cat /var/log/vboxadd-install.log
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  中止.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

どうもこれが原因っぽい。

vbox setupのエラーを解決する

こちらこちらを参考に、エラーを解決しました。

カーネルのバージョンアップと必要なパッケージのインストール

まず、カーネルのバージョンアップとインストールに必要なパッケージのインストールを行います。
カーネルのバージョンアップをしていないと、必要なパッケージをインストールしても同じエラーでコケます。

$ sudo yum -y update kernel

必要なパッケージをインストール。

$ sudo yum -y install kernel-devel kernel-headers dkms gcc gcc-c++

この後、仮想マシンの再起動をする必要があるそうなので、ホストOS側からvagrant reloadで再起動をかけました。

vbox setupを行う

詳細はメモり忘れてしまいましたが、このままvbox setupしてもコケます。
確かcat /var/log/vboxadd-install.logしたときにSpecify KERN_DIR=<directory>というエラーが出てたはず。
エラーメッセージとこちらを参考に、環境変数にカーネルのディレクトリを指定して再度実行。

$ export KERN_DIR=`ls -t /usr/src/kernels/|head -1`
$ sudo /etc/init.d/vboxadd setup
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                         [  OK  ]
Doing non-kernel setup of the Guest Additions              [  OK  ]
You should restart your guest to make sure the new modules are actually used

成功しました。この後、vagrant reloadで再起動。
マウントのエラーメッセージも出ることなく起動成功しました。

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
104