VirtualBox で Scientific Linux 7.0 を起動しようとしたら Guest Additions のインストールに失敗

Scientific Linux 7.0 の Docker用ベースイメージをつくろうと思い、
 `vagrant up` をしたらエラーが発生してうまく行かなかった。人生は厳しい。
おかげで、 `/vagrant` がマウントされなかった。

## 環境

```bash
$ vagrant --version
Vagrant 1.7.4
$ VBoxManage --version
4.3.28r100309
```

## 忙しい人のための

こんなエラーが出たら

```bash
The missing package can be probably installed with
yum install kernel-devel-3.10.0-123.el7.x86_64

Building the main Guest Additions module[FAILED]
```

こうする。

```bash
host $ vagrant ssh
vagrant # sudo yum install -y ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/7.0/x86_64/os/Packages/kernel-devel-3.10.0-123.el7.x86_64.rpm
vagrant # exit
host $ vagrant reload
```

## 詳細

エラーは以下のような感じ。

```bash
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-3.10.0-123.el7.x86_64

Building the main Guest Additions module[FAILED]
(Look at /var/log/vboxadd-install.log to find out what went wrong)

...

An error occurred during installation of VirtualBox Guest Additions 4.3.28. 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: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/yoshiki_aoki/work/github.com/ringohub/docker-base-image/sl70-base
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

The error output from the last command was:

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

どうやら、virtual box guest additions のインストールが失敗してる模様。
気になるログはここらへん。

```bash
The missing package can be probably installed with
yum install kernel-devel-3.10.0-123.el7.x86_64

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

ここでわかるのは、`kernel-devel-3.10.0-123.el7.x86_64` をインストールしなきゃいけなさそうっていうのと、`/var/log/vboxadd-install.log` のログを見ようってこと。

ログから見てみる。

```bash
[root@localhost ~]# 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.  Stop.
```

`KERN_DIR` を指定しろよって言ってる。カーネルのディレクトリをしてしようと思って、みてみる。

```bash
[root@localhost vagrant]# ls /usr/src/kernels/
[root@localhost vagrant]#
```

何もなかった。
ここで、`yum install -y kernel-devel` でインストールしてしまうと `kernel-devel-3.10.0-123.el7.x86_64` が入らない。
なので、[ここから](http://rpm.pbone.net/index.php3/stat/4/idpl/26590070/dir/scientific_linux_7/com/kernel-debug-devel-3.10.0-123.el7.x86_64.rpm.html) rpmを指定バージョンをインストールした。

```bash
yum install -y ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/7.0/x86_64/os/Packages/kernel-devel-3.10.0-123.el7.x86_64.rpm
```

一応確認。

```bash
[root@localhost vagrant]# ls /usr/src/kernels/
3.10.0-123.el7.x86_64
```

`KERN_DIR` を指定しなきゃだめかなと思ったんだけど、ためにしログアウトして `vagrant reload` したら無事インストールされた。

```bash
...
Installing Virtualbox Guest Additions 4.3.28 - guest version is
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.28 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.28 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  ]
...
```

## References

- [Vagrant box: Scientifi Linux 7.0](https://atlas.hashicorp.com/ringo/boxes/scientific-linux-7.0)
- [Vagrant で CentOS 6.5 を使っていたら Guest Additions の更新に失敗してハマった - Qiita](http://qiita.com/a-suenami/items/3b04151ce6e7d5b72a3e)
- [Vagrantのmountエラーを解決しようとしたらvboxのリビルドがこける - Qiita](http://qiita.com/wakaba260/items/b5c87b7815b710f303a0)
- [CentOSへGuest Additionsをインストールしたときのエラー対処方法](http://little-braver.com/536/)
- [kernel-devel rpm build for : Scientific Linux 7.  3.10.0 123.el7](http://rpm.pbone.net/index.php3/stat/4/idpl/26590071/dir/scientific_linux_7/com/kernel-devel-3.10.0-123.el7.x86_64.rpm.html)
- [VirtualBox に CentOS6.0 をインストール](http://ikekobo.com/2011/09/virtualbox-%E3%81%AB-centos6-0-%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/)