[Vagrant] VirtualBoxのバージョンとGuest additionsのバージョンが合わない場合の対処法

遅ればせながらvagrantを触り始めました。今のところ単純なことしかしてないのでほとんど詰まるところはありませんが、仮想マシンを起動した際にVirtualBoxのバージョンとGuest additionsのバージョンが一致しないと怒られたのでその解決方法です。

環境

  • Mac OS X 10.8
  • vagrant 1.2.2
  • ruby 1.9.3 (rbenv)

アラート内容

1
2
3
4
5
6
7
8
[default] The guest additions on this VM do not match the installed version of
VirtualBox! In most cases this is fine,   but in rare cases it can
cause things such as shared folders to not work properly. If you see
shared folder errors,   please update the guest additions within the
virtual machine and reload your VM.

Guest Additions Version: 4.1.18
VirtualBox Version: 4.2

vagrant-vbguest

vagrant-vbguest は自動的にGuest Additionsを更新してくれるプラグインです。

このプラグインをインストールし up or reload で自動的に新しいバージョンのGuest Additions がインストールされます。

Install

1
$ vagrant plugin install vagrant-vbguest

Configuration

vagrant-vbguestはインスタンス起動時に毎回自動で更新の確認を行うようなのでグローバルはOFFにして 利用するプロジェクト場合はOnに設定します。

Global Configuration

~/.vagrant.d/ 以下にVagrantfileが存在する場合、この設定ファイルを読みに行くようなのでglobalの設定として vagrant-vbguest の自動更新をOFFになるよう設定します。

1.2.2ではDocumentに記載されている方法でエラーが発生したので変更を加えます。

1
$ vi ~/.vagrant.d/Vagrantfile
1
2
3
4
5
6
7
8
9
# 1.2.2ではエラーになった
require 'vagrant-vbguest' unless defined? VagrantVbguest::Config
VagrantVbguest::Config.auto_update = false

# こっちだとうまくいく
Vagrant.configure("2") do |config|
  require 'vagrant-vbguest' unless defined? config.vbguest
  config.vbguest.auto_update = false
end

ruby殆ど知らないのですがvbguestのconfigを初期化して値を設定してる感じでしょう。

Project Configuration

プロジェクト固有の設定です。auto_updateが有効になるよう設定を加えます。

1
$ vi /path/to/vagrant_project/Vagrantfile
1
2
3
# set auto_update to false,  if do NOT want to check the correct additions
# version when booting this machine
config.vbguest.auto_update = true

Vagrant up or reload

1
2
3
$ vagrant up
or
$ vagrant reload

すると自動的にGuest Additionsをupdateしてる!素晴らしい。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
GuestAdditions versions on your host (4.2.12) and guest (4.1.18) do not match.
Loaded plugins: fastestmirror,  presto
Loading mirror speeds from cached hostfile
 * base: mirror.fairway.ne.jp
  * extras: mirror.fairway.ne.jp
   * updates: mirror.fairway.ne.jp
   Setting up Install Process
   Package kernel-devel-2.6.32-358.6.2.el6.x86_64 already installed and latest version
   Package gcc-4.4.7-3.el6.x86_64 already installed and latest version
   Package 1:make-3.81-20.el6.x86_64 already installed and latest version
   Package 4:perl-5.10.1-131.el6_4.x86_64 already installed and latest version
   Nothing to do
   Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
   Installing Virtualbox Guest Additions 4.2.12 - guest version is 4.1.18
   Verifying archive integrity... All good.
   Uncompressing VirtualBox 4.2.12 Guest Additions for Linux............
   VirtualBox Guest Additions installer
   Removing installed version 4.1.18 of VirtualBox Guest Additions...
   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[  OK  ]
   Doing non-kernel setup of the Guest Additions[  OK  ]
   Starting the VirtualBox Guest Additions [  OK  ]
   Installing the Window System drivers[FAILED]
   (Could not find the X.Org or XFree86 Window System.)
   An error occurred during installation of VirtualBox Guest Additions 4.2.12. Some functionality may not work as intended.
   [default] Configuring and enabling network interfaces...
   [default] Mounting shared folders...
   [default] -- /vagrant

念のためvagrant sshでログインして確認する。

1
2
$ ls /opt
VBoxGuestAdditions-4.2.12

無事新しいバージョンのGuest Additionsがインストールされたことが確認できます。

補足

Vagrant1.2.2から1.3.2にあげたらvagrant-vbguestが動作しない

参考

vagrant-vbguest

Note To Self: What to Do When a Vagrant Machine Stops Working (Destroy or Up Failing)

Comments