what are you waiting for ?

Vagrant で VirtualBoxの Guest Additionsをインストールし直す際のメモ

vagrant を使ってVMを管理する際に、yum updateなどを実行してカーネルのバージョンが変わった場合、 VirtualBoxのGuest Additionsを再インストールしないといけない場合がある。

その場合は、vagrant up すると vboxsf によるホストとゲストのフォルダ共有が動かないため以下のエラーが出る。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'chef/centos-6.5' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address:
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/tanacasino/vagrant/centos65
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` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

手動でGuest Additionsを入れなおす作業はツラいので、vagrantプラグインを使ってこの作業を簡単にする。

# プラグインのインストール
$ vagrant plugin install vagrant-vbguest

# VMのVagrantfileのあるディレクトリに移動して以下を実行
$ vagrant vbguest
GuestAdditions versions on your host (4.3.12) and guest (4.3.8) do not match.
... その他色々なメッセージが出る ...
Starting the VirtualBox Guest Additions [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
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.

上記のような "Window System drivers" installation failed. が出るが、X使ってない場合は無視してOK。 以下のコマンドで Guest Additionsの状態が確認できる。

$ vagrant vbguest --status
GuestAdditions 4.3.12 running --- OK.


$ vagrant version
Installed Version: 1.6.3
Latest Version: 1.6.3

You're running an up-to-date version of Vagrant!