VagrantでCentOS5.1の開発環境を作る

CentOSの5系で開発してくれって言うお客さんがいたので、
四苦八苦しながら環境構築したときのメモの書き起こし。
1年くらい前の作業メモなので今でもこの通りいくか不明。
※自己責任で試しましょう。

環境

Windows 7
VirtualBox 5.0.14
Vagrant 1.8.1

CentOS5.1のboxを持ってくる。

$ mkdir vagrant
$ cd vagrant
$ mkdir centos5
$ cd centos5
$ vagrant box add centos5.1 http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-5.10_chef-provisionerless.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos5.1' (v0) for provider:
    box: Downloading: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-5.10_chef-provisionerless.box
    box:
==> box: Successfully added box 'centos5.1' (v0) for 'virtualbox'!

//boxが追加されたか確認
$ vagrant box list
centos5.1        (virtualbox, 0)
//立ち上げる
$ vagrant init centos5.1
$ vagrant up

(長いので略)

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

なんかマウントが失敗したっぽいエラー。
下記の記事がそのまま参考になりました。
qiita.com

よくわからんがカーネルのソースへのパス設定しなおさないとダメっぽい。

カーネルの設定。

//vagrant sshでログイン
$ vagrant ssh
//kernel-develインストールする
[vagrant@localhost ~]$ sudo yum install kernel-devel -y
[vagrant@localhost ~]$ ls /usr/src/kernels/
2.6.18-412.el5-x86_64
[vagrant@localhost ~]$ uname -r
2.6.18-371.el5
[vagrant@localhost ~]$ su -
[root@localhost ~]# echo "KERN_DIR=/usr/src/kernels/2.6.18-406.el5-x86_64" >> .bash_profile
[root@localhost ~]# yum info kernel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.nara.wide.ad.jp
 * extras: ftp.nara.wide.ad.jp
 * updates: ftp.nara.wide.ad.jp
Installed Packages
Name       : kernel
Arch       : x86_64
Version    : 2.6.18
Release    : 371.el5
Size       : 99 M
Repo       : installed
Summary    : The Linux kernel (the core of the Linux operating system)
URL        : http://www.kernel.org/
License    : GPLv2
Description: The kernel package contains the Linux kernel (vmlinuz), the core of any
           : Linux operating system.  The kernel handles the basic functions
           : of the operating system:  memory allocation, process allocation, device
           : input and output, etc.

Available Packages
Name       : kernel
Arch       : x86_64
Version    : 2.6.18
Release    : 412.el5
Size       : 22 M
Repo       : updates
Summary    : The Linux kernel (the core of the Linux operating system)
URL        : http://www.kernel.org/
License    : GPLv2
Description: The kernel package contains the Linux kernel (vmlinuz), the core of any
           : Linux operating system.  The kernel handles the basic functions
           : of the operating system:  memory allocation, process allocation, device
           : input and output, etc.
[root@localhost ~]# yum update kernel -y
[root@localhost ~]# shutdown -r now

vbGuest Additionsのアップデート

$ vagrant vbguest
Guest-specific operations were attempted on a machine that is not
ready for guest communication. This should not happen and a bug
should be reported.
$ vagrant reload

たぶんこれでうまく立ち上がるはず。