[Vagrant & VirtualBox] Vagrant: The guest additions on this VM do not match the installed version of VirtualBox!

vagrant up 時にこんな表示が出るので、気になって調べました。

[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 prevent things such as shared folders from working properly. If you see shared folder errors, please make sure the guest additions within the virtual machine match the version of VirtualBox you have installed on your host and reload your VM.
Guest Additions Version: 4.2.12
VirtualBox Version: 4.3

Contents

Guest Additions とは

VirtualBox で、ゲストOSとホストOSの仲立ちをしてくれるよう。
VMware でいうところの VMware Tools みたいなものでしょうか。

手動アップデート

手動ではこんな形で進めるようで、毎回これをするのはなかなか大変。

% wget -c http://download.virtualbox.org/virtualbox/4.1.8/VBoxGuestAdditions_4.1.8.iso
% sudo umount /mnt
% sudo mount VBoxGuestAdditions_4.1.8.iso -o loop /mnt
% sudo sh /mnt/VBoxLinuxAdditions.run

vagrant-vbguest plugin

これを楽する vagrant-vbguest というプラグインがあるそうなので導入します。

インストール

プラグインをインストールします。

% vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Installed the plugin 'vagrant-vbguest (0.10.0)'!

設定

特に設定は必要なく使えるそう。
例えば auto update を止めたいとか動作を細かく指定したい場合は、Vagrantfile に設定する。

Vagrantfile
Vagrant::Config.run do |config|
  # we will try to autodetect this path.
  # However, if we cannot or you have a special one you may pass it like:
  # config.vbguest.iso_path = "#{ENV['HOME']}/Downloads/VBoxGuestAdditions.iso"
  # or
  # config.vbguest.iso_path = "http://company.server/VirtualBox/%{version}/VBoxGuestAdditions.iso"
  # set auto_update to false, if you do NOT want to check the correct
  # additions version when booting this machine
  config.vbguest.auto_update = false
  # do NOT download the iso file from a webserver
  config.vbguest.no_remote = true
end

Global Configuration

~/.vagrant.d/Vagrantfile を使うとグローバルセッティングができる。

~/.vagrant.d/Vagrantfile
Vagrant.configure("2") do |config|
  config.vbguest.auto_update = false
end

つかいかた

vagrant up 時に、自動でアップデートしてくれるようなので、再度立ち上げます。

% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
    :
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
GuestAdditions versions on your host (4.3.6) and guest (4.2.12) do not match.
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
Setting up Install Process
    :
    :
Dependency Updated:
  cpp.x86_64 0:4.4.7-4.el6
  gcc-c++.x86_64 0:4.4.7-4.el6
  libgcc.x86_64 0:4.4.7-4.el6
  libgomp.x86_64 0:4.4.7-4.el6
  libstdc++.x86_64 0:4.4.7-4.el6
  libstdc++-devel.x86_64 0:4.4.7-4.el6
  perl-Module-Pluggable.x86_64 1:3.90-136.el6
  perl-Pod-Escapes.x86_64 1:1.04-136.el6
  perl-Pod-Simple.x86_64 1:3.13-136.el6
  perl-libs.x86_64 4:5.10.1-136.el6
  perl-version.x86_64 3:0.77-136.el6
Complete!
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Installing Virtualbox Guest Additions 4.3.6 - guest version is 4.2.12
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.6 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.2.12 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules[  OK  ]
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules[  OK  ]
Doing non-kernel setup of the Guest Additions[  OK  ]
You should restart your guest to make sure the new modules are actually used
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.3.6. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
    :

なかなか起動までに時間がかかりました。

auto update をつかわない場合

普段は、config.vbguest.auto_update = false とし、auto_update を止めておいた方が都合が良さそうです。
その場合は、以下のように手動でアップデートできました(仮想マシンが起動している必要があります)。

バージョンが合っているか確認する。

% vagrant vbguest --status
GuestAdditions 4.3.6 running --- OK.

バージョンが合っていない場合は、以下のように表示されました。

% vagrant vbguest --status
GuestAdditions versions on your host (4.3.12) and guest (4.2.12) do not match.

アップデートします。

% vagrant vbguest --do install
    :
An error occurred during installation of VirtualBox Guest Additions 4.3.12. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
% vagrant vbguest --status
GuestAdditions 4.3.12 running --- OK.

完了しました。