Vagrant で CentOS 6.5 を使っていたら Guest Additions の更新に失敗してハマった

結構ハマってしまったのでメモ。
とりあえず解決はしたけどあまり理屈はわかってない。

## 参考にした記事

- [vagrantでmountエラーの解決方法](http://qiita.com/osamu1203/items/10e19c74c912d303ca0b)
- [Vagrantでフォルダがmountできないエラーが出たときの対応](http://qiita.com/kazu69/items/812b236e84fee1db3900)

## Guest Additions の更新ができなくなった

`vagrant-vbguest` はインストールしていたので、Guest Additions の更新は自動的にやってくれるはずだったのですが `Vagrantfile` を修正して `vagrant reload` したら以下のようなエラーが出た。

```
GuestAdditions versions on your host (4.3.26) and guest (4.3.6) do not match.
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: mirror01.idc.hinet.net
 * extras: www.ftp.ne.jp
 * openvz-kernel-rhel6: ftp.iij.ad.jp
 * updates: www.ftp.ne.jp
Setting up Install Process
No package kernel-devel-2.6.32-431.3.1.el6.x86_64 available.
Package gcc-4.4.7-11.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-136.el6_6.1.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.3.26 - guest version is 4.3.6
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.26 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.26 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
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.3.1.el6.x86_64

Building the main Guest Additions module[FAILED]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the 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.26. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
```

結果、フォルダの同期に失敗した。

```
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /path/to/synced_folder
Failed to mount folders in Linux guest. 
. 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

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device
```

一応、`vagrant ssh` して vbox をリビルドしてみたけど、同じ結果。

```
[vagrant@vagrant-centos65 ~]$ 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.3.1.el6.x86_64

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

## kernel-devel を入れてみる

```
The missing package can be probably installed with
yum install kernel-devel-2.6.32-431.3.1.el6.x86_64
```

とのことなので `yum install` してみる。

```
[vagrant@vagrant-centos65 ~]$ sudo yum install kernel-devel
...
Installed:
  kernel-debug-devel.x86_64 0:2.6.32-504.12.2.el6

Complete!
```

ん？なんか違うバージョンが入った？

## 結局

これでいけた。

```
[vagrant@vagrant-centos65 ~]$ sudo yum install http://vault.centos.org/6.5/updates/x86_64/Packages/kernel-devel-2.6.32-431.3.1.el6.x86_64.rpm
...
Installed:
  kernel-devel.x86_64 0:2.6.32-431.3.1.el6

Complete!
```

kernel とか普段意識しないのでたまにこういうのがあるとよくわからない… :sweat_drops: 

そもそもなんでこんな状態になっていたのかもよくわかってない。