12.12.2013

How to Solve Vagrant+CentOS+VirtualBox Mount Error

Vagrant+CentOS+VirtualBox: ゲストOS起動時のマウントエラーの調査

 

事象

Vagrant で CentOS 6 の VirtualBox 用イメージを立ち上げようとしたところ、以下のようなエラーが出てしまった。

$ vagrant up <HOSTNAME>

(略)

[HOSTNAME] Mounting shared folders...
[HOSTNAME] -- /vagrant
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 xxxxxxxx`,gid=`getent group xxxxxxxx | cut -d: -f3` /vagrant /vagrant
mount -t vboxsf -o uid=`id -u xxxxxxxx`,gid=`id -g xxxxxxxx` /vagrant /vagrant

このメッセージだけでは、VirtualBox Guest Additions (以下、Guest Additions) の機能である共有フォルダのマウントに失敗していることくらいしか分からない。

ちなみに Guest Additions とは、簡単に言えば VirtualBox ゲストの管理に特化した便利ツールだ。

これを利用しないなら無視しても構わないのだろうが、やっぱり気になるので調べてみる。

 

調査

vagrant status コマンドを実行して、OS自体は起動していることは確認できた。

$ vagrant status

Current machine states:

HOSTNAME                  running (virtualbox)

SSH 接続をしてみよう。

$ vagrant ssh <HOSTNAME>

以下はゲストOS上のプロンプト。
Guest Additions の状態を確認すると、停止状態であることが分かる。

$ service vboxadd status
The VirtualBox Additions are not currently running.

Guest Additions のインストール自体が失敗している可能性があると考え、ログを確認する。

$ 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.

やはりここに答えがあった。
カーネルのソース (kernel-devel) が不足していたために、Guest Additions のビルドが失敗していたのだった。

対応

 

誤った対応

パッケージが足りないなら、yum でインストールすればよいと安直に

$ sudo yum install kernel-devel -y

と実行するのはよくない。

上記のコマンドでは (基本的に) 最新の kernel-devel がダウンロードされるため、
実際のカーネルバージョンと異なるものがインストールされてしまう可能性があるためだ。

カーネルバージョンと kernel-devel が食い違った状態で Guest Additions のセットアップをすると、やはりビルドは失敗となる。

$ 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-358.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  ]

それぞれのバージョンは以下のようなコマンドで確認できる。

$ uname -r
2.6.32-358.el6.x86_64
$ rpm -qa |grep kernel-devel
kernel-devel-2.6.32-431.el6.x86_64

アンインストール。

$ sudo yum remove kernel-devel

 

 

正しい対応

では、適切なバージョンの kernel-devel をインストールするにはどうしたらよいか。

残念ながら、このまま yum でバージョンを指定してもうまくいかない。

$ sudo yum install kernel-devel-$(uname -r) -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
Setting up Install Process
No package kernel-devel-2.6.32-358.el6.x86_64 available.
Error: Nothing to do

古いバージョンのパッケージは CentOS-Vault リポジトリに置かれている。
以下いずれかの方法で対応が可能だ。

  • /etc/yum.repos.d/CentOS-Vault.repo ファイルを編集
    適切なOSバージョンの記載を追加し、「enabled=0」 を「enabled=1」へ書き換える
  • URLを指定して直接ダウンロード
    $ sudo yum install http://vault.centos.org/6.4/os/x86_64/Packages/kernel-devel-$(uname -r).rpm

インストールを終えたらゲストOS上で、Guest Additions のセットアップを再度実行。

$ 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  ]
Starting the VirtualBox Guest Additions                    [  OK  ]

うまくいった。

$ service vboxadd status
The VirtualBox Additions are currently running.

目的は達成できたので、一度ゲストOSから抜け、Vagrant から再起動する。

$ vagrant reload <HOSTNAME>

マウントエラーは晴れて解消された。

 

 

References

0 件のコメント:

コメントを投稿