page_adsence

ラベル VirtualBox の投稿を表示しています。 すべての投稿を表示
ラベル VirtualBox の投稿を表示しています。 すべての投稿を表示

2015年7月22日水曜日

vagrantのバージョンアップしてみた

同僚の人がansible-playbookがうまくいかないとの事だったので、その人と環境を揃える為にvagrantのバージョンを1.6.5から最新の1.7.3に上げてみた。
vagrant自体のバージョンアップは簡単だけど、ちょっと面倒臭い。
旧バージョンをアンインストールして再起動、新バージョンをインストールして再起動すれば完了。
作業自体は単純ですが、Windowsの再起動が遅すぎてすごく時間が掛かった。
SSDに換装してほしい・・・。

Virtualboxのバージョンアップも行ったがこちらはインストーラーを使ってインストールするだけでバージョンアップされる。
両方のバージョンアップが終わった所で、諸々確認していく。
最終的に確認する内容としては、ansible-playbookを実行して、VM上の環境がきちんと出来上がるかどうかを確認する。

まず、1.6.5の時に作ったVMは不要になったので、一度削除して作りなおす事にした。
Cygwin上から下記のコマンドを実行。
$ vagrant destroy
Vagrant is attempting to interface with the UI in a way that requires
a TTY. Most actions in Vagrant that require a TTY have configuration
switches to disable this requirement. Please do that or run Vagrant
with TTY.

今までは普通に削除出来たのに、vagrantのバージョンを上げた途端に削除出来なくなってしまった・・・。
原因はまだ調べていないが、下記の様にオプションをつけることで削除することは可能。
$ vagrant destroy --force
==> default: Destroying VM and associated drives...

Vagrantfile自体は特に変更する必要がなかったので、vagrant upした。
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos64-100g'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vm-test
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2231 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2231
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/cygwin64/home/user_name/VirtualBoxMachines/vm-test

赤い文字の部分が多分バージョンアップ後に新しくデータメッセージで、
安全じゃない鍵があったから、より安全な新しい鍵ペアに置き換えるよというメッセージが出ていた。
今まで使っていた1.6系だと、1ユーザーに付き1個の鍵が生成されていて、複数のVMを作ってもその1つの鍵を使いまわして接続ができたが、1.7系にすると1台に付き1個の鍵が生成される(vagrant up時)。
設定を今まで通りの状態でPlaybookを実行すると、下記の様なエラーが出てしまう。

.ssh/configに書かれている鍵情報が古いバージョンの時の鍵のままになっている場合に出るエラー

$ ansible-playbook setup.yml

PLAY [vm-grp] *************************************************************

GATHERING FACTS ***************************************************************
fatal: [vm] => SSH Error: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
    while connecting to 192.168.33.10:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

TASK: [check selinux off] *****************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/user_name/setup.retry

vm                  : ok=0    changed=0    unreachable=1    failed=0

新しい鍵を使うために、.ssh/configを書き換える

Host vm-test
  HostName 192.168.33.10
  Port 22
  User vagrant
  #IdentityFile C:\Users\user_name\.vagrant.d\insecure_private_key <- コメントアウト
  IdentityFile /home/user_name/VirtualBoxMachine/vm1/.vagrant/machines/default/virtualbox/private_key <- 追記

ファイルのパーミッションで出るエラー

$ ansible-playbook setup.yml

PLAY [vm-grp] *************************************************************

GATHERING FACTS ***************************************************************
fatal: [vm] => SSH Error:     while connecting to 192.168.33.10:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

TASK: [check selinux off] *****************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/user_name/setup.retry

vm                  : ok=0    changed=0    unreachable=1    failed=0

上記の様なパーミッションのエラーになったら確認する場所としては、下記が挙げられる。
※下記のパーミッションになっていることを確認する
~/.ssh -> 700
~/.ssh/config -> 744
.vagrant/machines/default/virtualbox/private_key -> 700

上記の対応をしたらちゃんとansible-playbookが実行できた。

2015年6月30日火曜日

vagrantのbox容量を拡張する方法

Vagrantでboxファイルをダウンロードしてくると基本的に容量が少なくて困ることが多かったので、boxのサイズを拡張してみた。
とは言ったものの、サクッと出来る感じではなく、結構手順が面倒くさいです。
何故かと言うと、Vagrantで使われる仮想ディスクイメージはvmdk形式と言われるもので、一度作成したディスクのサイズを変更することが出来ない。
なので、一度変換可能な形式(vdi)に変換して、拡張してから元のvmdk形式に戻すという手順が必要になる。
また、注意点としてVirtualBoxでスナップショット等を使っていた場合、スナップショットで保存されている内容は一切移行出来ない。
(出来る方法があるのかもしれないが、現時点ではわからなかった)

VirtualBoxをインストールしたディレクトリ内に「VBoxManage.exe」というファイルがあるので、それを使って拡張する。
C:\Program Files\Oracle\VirtualBox\VBoxManage.exe

以下、拡張のための手順。

1.VirtualBoxマネージャーで拡張したいVMを選択し、設定画面を開く

拡張したいVMを選択し、右クリック押して、コンテキストメニューの中の設定をクリック。
もしくは拡張したいVMを選択した状態で、設定ボタンを押す。


2.設定画面で拡張したいvmdkファイルの場所を調べる。

ストレージ → XXXXX.vmdk → 場所にマウスカーソルを合わせる。
そうするとフルパスが出てくるので、それを確認する。場所を右クリックするとコピー出来る。
コピーした値は「C:\Users\UserName\VirtualBox VMs\jenkins-laravel\box-disk1.vmdk」とする。


3.コマンドプロンプトを立ち上げて下記のディレクトリへ移動

cd C:\Program Files\Oracle\VirtualBox\

4.VBoxManage.exeがあるか確認

C:\Program Files\Oracle\VirtualBox> dir VBoxManage.exe

5.仮想HDDのUUIDを調べる

先ほど確認したvmdkファイルのパスと、下記のリストの中のLocationが一致するものを探す。
該当のvmdkファイルのUUIDの項目をコピーする。
C:\Program Files\Oracle\VirtualBox> VBoxManage.exe list hdds

UUID:           6e50fc33-ab05-4ca5-9740-ad708e335e11 ← これをコピーする
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       C:\Users\UserName\VirtualBox VMs\jenkins-laravel\box-disk1.vmdk
Storage format: VMDK
Capacity:       30720 MBytes

UUID:           acd294ea-6844-4121-b66f-85f848bcecec
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       C:\Users\UserName\VirtualBox VMs\jenkins-laravel-2\box-disk1.vmdk
Storage format: VMDK
Capacity:       30720 MBytes

6.vmdk形式からvdi形式にしてコピーする

vmdkファイルと同じ内容の仮想ディスクをvdi形式で作成する。
$ VBoxManage.exe clonehd "C:\Users\UserName\VirtualBox VMs\jenkins-laravel\box-disk1.vmdk" "C:\Users\UserName\VirtualBox VMs\jenkins-laravel\clone.vdi" --format vdi

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'vdi'. UUID: 152e5d9f-e66a-4212-84d6-dbe05c1f8ceb

7.vdi形式の仮想ディスクのサイズを変更する。100GBにしたい場合は下記の通り。単位はMB

$ VBoxManage.exe modifyhd "C:\Users\UserName\VirtualBox VMs\jenkins-laravel\clone.vdi" --resize 102400
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

8.拡張したvdi形式をvmdk形式にしてコピーする

$ VBoxManage clonehd "C:\Users\UserName\VirtualBox VMs\jenkins-laravel\clone.vdi" "C:\Users\UserName\VirtualBox VMs\jenkins-laravel\box-disk1.vmdk" --format vmdk

※上書きするのが怖い場合は別名にして保存し、VirtualBox上でストレージを変更することで対応出来る。
仮想ハードディスクファイルの選択をクリックして、新しく作ったvmdkファイルを選択することで、過去のファイルを残した状態で拡張出来る。
もし拡張したvmdkファイルに何か不都合があった場合は、元の仮想ハードディスクファイルに戻せば元の状態に戻る。


9.vdiファイルをVBoxManger上の管理から外す

ここに記載しているUUIDはvdi形式のファイルのUUID。
$ VBoxManage closemedium disk 152e5d9f-e66a-4212-84d6-dbe05c1f8ceb

ここまでで、vmdkファイルのディスク拡張作業は完了。
ここからは拡張したディスクを使用できるようにする。


10.拡張したVMにログインして、現状を確認する

使用出来る容量は変わっていない事を確認。
# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/mapper/vg_vagrantcentos64-lv_root
                       28G  1.8G   24G   7% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot
vagrant               459G  358G  102G  78% /vagrant

11.VMWareを立ち上げて状態を確認

ディスク容量自体が増えていることを確認する
# fdisk -l

ディスク /dev/sda: 107.4 GB, 107374182400 バイト
ヘッド 255, セクタ 63, シリンダ 13054
Units = シリンダ数 of 16065 * 512 = 8225280 バイト
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O size (minimum/optimal): 512 bytes / 512 bytes
ディスク識別子: 0x00054ab8

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *           1          64      512000   83  Linux
パーティション 1 は、シリンダ境界で終わっていません。
/dev/sda2              64        3917    30944256   8e  Linux LVM

ディスク /dev/mapper/vg_vagrantcentos64-lv_root: 29.6 GB, 29569843200 バイト
ヘッド 255, セクタ 63, シリンダ 3594
Units = シリンダ数 of 16065 * 512 = 8225280 バイト
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O size (minimum/optimal): 512 bytes / 512 bytes
ディスク識別子: 0x00000000


ディスク /dev/mapper/vg_vagrantcentos64-lv_swap: 2113 MB, 2113929216 バイト
ヘッド 255, セクタ 63, シリンダ 257
Units = シリンダ数 of 16065 * 512 = 8225280 バイト
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O size (minimum/optimal): 512 bytes / 512 bytes
ディスク識別子: 0x00000000

12.パーティションを作成する

先ほど、fdiskコマンドで出てきた「ディスク /dev/sda」と書かれているところの「/dev/sda」の部分を入れる。(青文字の部分)
# fdisk /dev/sda

警告: DOS互換モードは廃止予定です。このモード (コマンド 'c') を止めることを
      強く推奨します。 and change display units to
         sectors (command 'u').

コマンド (m でヘルプ): n
コマンドアクション
   e   拡張
   p   基本パーティション (1-4)
p
パーティション番号 (1-4): 3
最初 シリンダ (3917-13054, 初期値 3917): Enter
初期値 3917 を使います
Last シリンダ, +シリンダ数 or +size{K,M,G} (3917-13054, 初期値 13054): Enter
初期値 13054 を使います

コマンド (m でヘルプ): t
パーティション番号 (1-4): 3
16進数コード (L コマンドでコードリスト表示): 8e ← fdiskコマンドの黄文字のとこの値を入れる
領域のシステムタイプを 3 から 8e (Linux LVM) に変更しました

コマンド (m でヘルプ): wq
パーティションテーブルは変更されました!

ioctl() を呼び出してパーティションテーブルを再読込みします。

警告: パーティションテーブルの再読込みがエラー 16 で失敗しました: デバイスもしくはリソースがビジー状態です。
カーネルはまだ古いテーブルを使っています。新しいテーブルは
次回リブート時か、partprobe(8)またはkpartx(8)を実行した後に
使えるようになるでしょう
ディスクを同期しています。

13.状態を再び確認

/dev/sda3が追加され、そこに空き容量が割り当てられていることを確認する
# fdisk -l

ディスク /dev/sda: 107.4 GB, 107374182400 バイト
ヘッド 255, セクタ 63, シリンダ 13054
Units = シリンダ数 of 16065 * 512 = 8225280 バイト
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O size (minimum/optimal): 512 bytes / 512 bytes
ディスク識別子: 0x00054ab8

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *           1          64      512000   83  Linux
パーティション 1 は、シリンダ境界で終わっていません。
/dev/sda2              64        3917    30944256   8e  Linux LVM
/dev/sda3            3917       13054    73398975   8e  Linux LVM

ディスク /dev/mapper/vg_vagrantcentos64-lv_root: 29.6 GB, 29569843200 バイト
ヘッド 255, セクタ 63, シリンダ 3594
Units = シリンダ数 of 16065 * 512 = 8225280 バイト
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O size (minimum/optimal): 512 bytes / 512 bytes
ディスク識別子: 0x00000000


ディスク /dev/mapper/vg_vagrantcentos64-lv_swap: 2113 MB, 2113929216 バイト
ヘッド 255, セクタ 63, シリンダ 257
Units = シリンダ数 of 16065 * 512 = 8225280 バイト
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O size (minimum/optimal): 512 bytes / 512 bytes
ディスク識別子: 0x00000000

14.リブートもしくはpartprobeを実行する

今回はrebootで反映させる。
# reboot

15.物理ボリュームを作成する

# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created

16.既存のボリュームグループ(VG) に新しいパーティションを追加する

# vgextend vg_vagrantcentos64 /dev/sda3
  Volume group "vg_vagrantcentos64" successfully extended

17.既存の論理ボリューム(LV) を追加したパーティションの分を拡張する

既存のLV は lvdisplay で確認。「lv_root」が既存で、LSizeが既存のディスク容量
# lvdisplay -C
  LV      VG                 Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root vg_vagrantcentos64 -wi-ao--- 27.54g
  lv_swap vg_vagrantcentos64 -wi-ao---  1.97g

18.拡張できるサイズを確認する

# vgdisplay
  --- Volume group ---
  VG Name               vg_vagrantcentos64
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               99.50 GiB
  PE Size               4.00 MiB
  Total PE              25473
  Alloc PE / Size       7554 / 29.51 GiB
  Free  PE / Size       17919 / 70.00 GiB
  VG UUID               f4eZwV-24wK-49T7-oERF-da3e-cwoW-gPtAdu

19.指定したサイズにディスクを拡張する

[PE Size] * [Free PE] の値が拡張できるサイズとなるので、4MB * 17919 = 71676MiB を拡張する。
# lvextend -L +71676MiB /dev/vg_vagrantcentos64/lv_root
  Extending logical volume lv_root to 97.54 GiB
  Logical volume lv_root successfully resized

20.ファイルシステムを拡張する

ディスク容量が大容量になると時間が掛かる。
# resize2fs /dev/vg_vagrantcentos64/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_vagrantcentos64/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 7
Performing an on-line resize of /dev/vg_vagrantcentos64/lv_root to 25568256 (4k) blocks.
The filesystem on /dev/vg_vagrantcentos64/lv_root is now 25568256 blocks long.
※CentOS7では「resize2fs」は利用出来ないので、「xfs_growfs」を使う。
# xfs_growfs /dev/vg_vagrantcentos64/lv_root

21.容量が増えていることを確認する

# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/mapper/vg_vagrantcentos64-lv_root
                       97G  1.8G   90G   2% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot

2015年5月27日水曜日

vagrantからVirtualBoxが起動出来なくなる問題の解決方法

Windows + Cygwin + Vagrant + VirtualBoxという環境で開発をしているのですが、
たまに、VirtualBoxを立ち上げていない状態で、Cygwinから「vagrant resume」してしまう事がある。
そうすると下記の様なメッセージが出てきて、VMが立ち上がらない状態になってしまう。(人によってはVirtualBoxが立ち上がってくれる?)

$ vagrant resume
==> default: VM not created. Moving on...

VirtualBoxを後から起動させてみると、VirtualBox上はsuspend状態のまま。
しかしvagrantコマンドでステータスを確認してみると

$ vagrant status
Current machine states:

default                   not created (virtualbox)

The environment has not yet been created. Run `vagrant up` to
create the environment. If a machine is not created, only the
default provider will be shown. So if a provider is not listed,
then the machine is not created for that environment.

VMは作成されていない状態になっている。
ちなみにこの状態で「vagrant up」してもすでに同名のVirtualBox名(Vagrantfile内のvb.name)が存在しているためエラーになる。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos6.4'...
==> default: Matching MAC address for NAT networking...
A VirtualBox machine with the name 'centos' already exists.
Please use another name or delete the machine with the existing
name, and try again.

なぜこんな状態になっているかというと、vagrantとVirtualBoxの関連付けをしているファイルが無い、もしくは中身が空の状態になっている事が原因らしい。
下記のファイルがあるか、中身が書かれているかを確認してみる。(Vagrantfileが置いてある所がvagrant_home)

/path/to/vagrant_home/.vagrant/machines/default/virtualbox/id

試しに確認してみたら、

$ ls -la .vagrant/machines/default/virtualbox/
合計 4
drwxr-xr-x+ 1 kusagaya-naoki Domain Users 0 5月  26 15:31 .
drwxr-xr-x+ 1 kusagaya-naoki Domain Users 0 5月  18 13:11 ..

案の定ファイルは存在していなかった。
なので、ここにファイルを作成してやればいいのですが、VirtualBox側のVMのUUIDを調べる必要がある。
UUIDの調べ方は以下の通り。

VirtualBoxのVMのUUIDの調べ方


1.コマンドプロンプトを立ち上げて、VirtualBoxのインストールディレクトリへ移動

cd C:\Program Files\Oracle\VirtualBox

2.VBoxManageでVirtualBoxにあるVMのUUIDの一覧を確認する。
※vm_nameにはvb.nameの名前が書かれている

C:\Program Files\Oracle\VirtualBox> VBoxManage.exe list vms
"vm_name" {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}

これでVMのUUIDがわかったので、下記のディレクトリ配下にidファイルを作成する。

$ vi /path/to/vagrant_home/.vagrant/machines/default/virtualbox/id

ファイルの先頭に調べたUUIDを書いて保存する。

XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

vagrant側のステータスを確認してみる。

$ vagrant status
Current machine states:

default                   saved (virtualbox)

To resume this VM, simply run `vagrant up`.

not createdからsavedに変わった事を確認して起動してみる。

$ vagrant resume
==> default: Resuming suspended VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2223
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection refused. Retrying...
==> default: Machine booted and ready!

ちゃんと起動しました。
よかった・・・。

2014年12月5日金曜日

VagrantのVirtualBox用BaseBoxファイルを一から作ってみる

前提条件として、VirtualBoxがインストールされており、動く状態になっていること。

VirtualBox 4.3.12
Vagrant 1.6.5
VirtualBoxにインストールするOSはCentOS 6.4とする。

0.事前準備

■CentOS 6.4のisoファイルをダウンロードしてくる。
http://vault.centos.org/

上記のサイトに各バージョンが落ちているので、そこから必要なものを選んでダウンロードしてくる。
ちなみに今回落としてきたファイルは以下の2ファイル
http://vault.centos.org/6.4/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso
http://vault.centos.org/6.4/isos/x86_64/CentOS-6.4-x86_64-bin-DVD2.iso

■VirtualBox Guest Additionsのisoファイルをダウンロードしてくる。

http://download.virtualbox.org/virtualbox/

インストールされているVirtualBoxに対応したものを落とす必要がある。
今回の場合は4.3.12なので、それ用のファイルをダウンロードする。
http://download.virtualbox.org/virtualbox/4.3.12/VBoxGuestAdditions_4.3.12.iso


1.VirtualBoxを起動させ、新規ボタンを押して、新しい仮想マシンを作成しCentOSをインストールする。

http://blog.livedoor.jp/yoka3/archives/3861638.html

2.CentOS側の初期設定をする

■minimalでインストールすると初期状態ではNICが起動時にupしていないので、まずはそこを直す。eth0をDHCPで動作させる。
# sed -i -e "s:^ONBOOT=no$:ONBOOT=yes:" /etc/sysconfig/network-scripts/ifcfg-eth0
# service network restart
# ip addr show eth0

■MAC アドレスの記憶を無効化して、NIC に振られた UUID も消しておく。 これは Vagrant のドキュメントには無いものの、忘れると NIC のナンバリングが eth1 からになったりして苦労する。
# ln -f -s /dev/null /etc/udev/rules.d/70-persistent-net.rules 
# sed -i -e "s:HWADDR=.*::g" /etc/sysconfig/network-scripts/ifcfg-eth0
# sed -i -e "s:UUID=.*::g" /etc/sysconfig/network-scripts/ifcfg-eth0

■ssh デーモンの設定を行う。 UseDNS を無効にして起動する。
# sed -i -e "s:^#UseDNS yes:UseDNS no:" /etc/ssh/sshd_config
# service sshd start
# chkconfig sshd on

■これ以降は SSH を使って VirtualBox を動作させているホスト経由で操作できる。
※但し、VirtualBoxでポートフォワードの設定が必要。(VMを一度停止させて、設定→ネットワーク→高度→ポートフォワーディング)
名前にssh、プロトコルはTCP、ホストポートは適当なポート(2222とか)、ゲストポートは22として保存する。
$ ssh root@127.0.0.1 -p 2222

■vagrant グループ&ユーザを追加してノーパスワードで sudo できるようにする。 ついでに requiretty を無効にする。
# groupadd vagrant
# useradd vagrant -g vagrant -G wheel
# echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# sed -i -e "s:^.*requiretty:#Defaults requiretty:" /etc/sudoers

■vagrant ユーザが公開鍵を使ってログインできるように鍵を設置する。 パーミッションには注意する。
# su - vagrant
$ mkdir ~/.ssh
$ chmod 0700 ~/.ssh
$ curl -L -o ~/.ssh/authorized_keys  https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
$ chmod 0600 ~/.ssh/authorized_keys

ここまでは流れ作業だったが、ここからが大変だった。

3.VirtualBoxのGuest Additionsをインストールする

最後に VirtualBox の Guest Additions をインストールするのだが、なかなかうまくいかなかった。

■VirtualBoxにVBoxGuestAdditions_4.3.12.isoをセットする。
CentOSをインストールした時と同様で、該当のVMの光学ドライブにダウンロードしてきたVBoxGuestAdditionsのisoファイルをセットする。

■まずディスクをマウントするためのディレクトリを作成。
一応Vagrantの公式サイトの手順を参考にやった。
http://docs.vagrantup.com/v2/virtualbox/boxes.html

To install via the command line:の部分を参照

$ sudo mkdir /media/VBoxGuestAdditions
$ sudo mount -o loop,ro /dev/cdrom /media/VBoxGuestAdditions
$ sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.12 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
The make utility was not found. If the following module compilation fails then
this could be the reason and you should try installing it.

The gcc utility was not found. If the following module compilation fails then
this could be the reason and you should try installing it.

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-358.el6.x86_64

Building the main Guest Additions module                   [失敗]
(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.

「The missing package can be probably installed with yum install kernel-devel-2.6.32-358.el6.x86_64」
と出ていたので、以下のファイルをインストール

$ sudo yum install http://vault.centos.org/6.4/os/x86_64/Packages/kernel-devel-2.6.32-358.el6.x86_64.rpm
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
kernel-devel-2.6.32-358.el6.x86_64.rpm                                                                                                                                                                                                                                                                | 8.2 MB     00:13
Examining /var/tmp/yum-root-UTuUDk/kernel-devel-2.6.32-358.el6.x86_64.rpm: kernel-devel-2.6.32-358.el6.x86_64
Marking /var/tmp/yum-root-UTuUDk/kernel-devel-2.6.32-358.el6.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package kernel-devel.x86_64 0:2.6.32-358.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================================================================================================
Package                                                                 Arch                                                              Version                                                                      Repository                                                                                      Size
=============================================================================================================================================================================================================================================================================================================================
Installing:
kernel-devel                                                            x86_64                                                            2.6.32-358.el6                                                               /kernel-devel-2.6.32-358.el6.x86_64                                                             24 M

Transaction Summary
=============================================================================================================================================================================================================================================================================================================================
Install       1 Package(s)

Total size: 24 M
Installed size: 24 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : kernel-devel-2.6.32-358.el6.x86_64                                                                                                                                                                                                                                                                        1/1
  Verifying  : kernel-devel-2.6.32-358.el6.x86_64                                                                                                                                                                                                                                                                        1/1

Installed:
  kernel-devel.x86_64 0:2.6.32-358.el6

Complete!

もう一回インストールしてみたが、結局失敗。
ログファイルを確認してみると、今度は下記のようなエラーが出ていた。
$ less /var/log/vboxadd-install.log
/opt/VBoxGuestAdditions-4.3.12/src/vboxguest-4.3.12/build_in_tmp: line 62: make: コマンドが見つかりません
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

ググってみたら下記のサイトがあった。
dkmsが必要そうな雰囲気があったので、インストールしてみる。
https://forums.virtualbox.org/viewtopic.php?f=7&t=50786

既存のリポジトリにはなかったので、リポジトリを追加
まずはファイルをダウンロード
$ wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
--2014-11-06 15:37:56--  http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
ftp-srv2.kddilabs.jp をDNSに問いあわせています... 202.255.47.226
ftp-srv2.kddilabs.jp|202.255.47.226|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 14540 (14K) [application/octet-stream]
`epel-release-6-8.noarch.rpm' に保存中

100%[===================================================================================================================================================================================================================================================================================>] 14,540      --.-K/s 時間 0s

2014-11-06 15:37:56 (1.01 GB/s) - `epel-release-6-8.noarch.rpm' へ保存完了 [14540/14540]

インストール。
$ sudo rpm -ivh epel-release-6-8.noarch.rpm
警告: epel-release-6-8.noarch.rpm: ヘッダ V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
準備中...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

dkmsがあるか確認。
$ yum info dkms
Loaded plugins: fastestmirror
Determining fastest mirrors
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

エラー・・・。
ミラーサイトの証明書が変わったかららしい。
とりあえず本家のサイトから取ってくるように修正する。

$ sudo vi /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

問題ないか確認。
$ sudo yum info dkms
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
epel                                                                                                                                                                                                                                                                                                  | 4.4 kB     00:00
epel/primary_db                                                                                                                                                                                                                                                                                       | 6.3 MB     00:02
Available Packages
Name        : dkms
Arch        : noarch
Version     : 2.2.0.3
Release     : 28.git.7c3e7c5.el6
Size        : 77 k
Repo        : epel
Summary     : Dynamic Kernel Module Support Framework
URL         : http://linux.dell.com/dkms
License     : GPLv2+
Description : This package contains the framework for the Dynamic Kernel Module Support (DKMS)
            : method for installing module RPMS as originally developed by Dell.

行けたので、インストール
$ sudo yum install dkms
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
Resolving Dependencies
--> Running transaction check
---> Package dkms.noarch 0:2.2.0.3-28.git.7c3e7c5.el6 will be installed
--> Processing Dependency: gcc for package: dkms-2.2.0.3-28.git.7c3e7c5.el6.noarch
--> Running transaction check
---> Package gcc.x86_64 0:4.4.7-11.el6 will be installed
--> Processing Dependency: libgomp = 4.4.7-11.el6 for package: gcc-4.4.7-11.el6.x86_64
--> Processing Dependency: cpp = 4.4.7-11.el6 for package: gcc-4.4.7-11.el6.x86_64
--> Processing Dependency: libgcc >= 4.4.7-11.el6 for package: gcc-4.4.7-11.el6.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.4.7-11.el6.x86_64
--> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-11.el6.x86_64
--> Processing Dependency: libgomp.so.1()(64bit) for package: gcc-4.4.7-11.el6.x86_64
--> Running transaction check
---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be installed
--> Processing Dependency: libppl_c.so.2()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
--> Processing Dependency: libppl.so.7()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
---> Package cpp.x86_64 0:4.4.7-11.el6 will be installed
--> Processing Dependency: libmpfr.so.1()(64bit) for package: cpp-4.4.7-11.el6.x86_64
---> Package glibc-devel.x86_64 0:2.12-1.149.el6 will be installed
--> Processing Dependency: glibc-headers = 2.12-1.149.el6 for package: glibc-devel-2.12-1.149.el6.x86_64
--> Processing Dependency: glibc = 2.12-1.149.el6 for package: glibc-devel-2.12-1.149.el6.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.12-1.149.el6.x86_64
---> Package libgcc.x86_64 0:4.4.7-3.el6 will be updated
---> Package libgcc.x86_64 0:4.4.7-11.el6 will be an update
---> Package libgomp.x86_64 0:4.4.7-11.el6 will be installed
--> Running transaction check
---> Package glibc.x86_64 0:2.12-1.107.el6 will be updated
--> Processing Dependency: glibc = 2.12-1.107.el6 for package: glibc-common-2.12-1.107.el6.x86_64
---> Package glibc.x86_64 0:2.12-1.149.el6 will be an update
---> Package glibc-headers.x86_64 0:2.12-1.149.el6 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.12-1.149.el6.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.12-1.149.el6.x86_64
---> Package mpfr.x86_64 0:2.4.1-6.el6 will be installed
---> Package ppl.x86_64 0:0.10.2-11.el6 will be installed
--> Running transaction check
---> Package glibc-common.x86_64 0:2.12-1.107.el6 will be updated
---> Package glibc-common.x86_64 0:2.12-1.149.el6 will be an update
---> Package kernel-headers.x86_64 0:2.6.32-504.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================================================================================================
Package                                                                        Arch                                                                   Version                                                                                    Repository                                                            Size
=============================================================================================================================================================================================================================================================================================================================
Installing:
dkms                                                                           noarch                                                                 2.2.0.3-28.git.7c3e7c5.el6                                                                 epel                                                                  77 k
Installing for dependencies:
cloog-ppl                                                                      x86_64                                                                 0.15.7-1.2.el6                                                                             base                                                                  93 k
cpp                                                                            x86_64                                                                 4.4.7-11.el6                                                                               base                                                                 3.7 M
gcc                                                                            x86_64                                                                 4.4.7-11.el6                                                                               base                                                                  10 M
glibc-devel                                                                    x86_64                                                                 2.12-1.149.el6                                                                             base                                                                 983 k
glibc-headers                                                                  x86_64                                                                 2.12-1.149.el6                                                                             base                                                                 611 k
kernel-headers                                                                 x86_64                                                                 2.6.32-504.el6                                                                             base                                                                 3.3 M
libgomp                                                                        x86_64                                                                 4.4.7-11.el6                                                                               base                                                                 133 k
mpfr                                                                           x86_64                                                                 2.4.1-6.el6                                                                                base                                                                 157 k
ppl                                                                            x86_64                                                                 0.10.2-11.el6                                                                              base                                                                 1.3 M
Updating for dependencies:
glibc                                                                          x86_64                                                                 2.12-1.149.el6                                                                             base                                                                 3.8 M
glibc-common                                                                   x86_64                                                                 2.12-1.149.el6                                                                             base                                                                  14 M
libgcc                                                                         x86_64                                                                 4.4.7-11.el6                                                                               base                                                                 102 k

Transaction Summary
=============================================================================================================================================================================================================================================================================================================================
Install      10 Package(s)
Upgrade       3 Package(s)

Total download size: 39 M
Is this ok [y/N]: y
Downloading Packages:
(1/13): cloog-ppl-0.15.7-1.2.el6.x86_64.rpm                                                                                                                                                                                                                                                           |  93 kB     00:00
(2/13): cpp-4.4.7-11.el6.x86_64.rpm                                                                                                                                                                                                                                                                   | 3.7 MB     00:00
(3/13): dkms-2.2.0.3-28.git.7c3e7c5.el6.noarch.rpm                                                                                                                                                                                                                                                    |  77 kB     00:00
(4/13): gcc-4.4.7-11.el6.x86_64.rpm                                                                                                                                                                                                                                                                   |  10 MB     00:00
(5/13): glibc-2.12-1.149.el6.x86_64.rpm                                                                                                                                                                                                                                                               | 3.8 MB     00:00
(6/13): glibc-common-2.12-1.149.el6.x86_64.rpm                                                                                                                                                                                                                                                        |  14 MB     00:01
(7/13): glibc-devel-2.12-1.149.el6.x86_64.rpm                                                                                                                                                                                                                                                         | 983 kB     00:00
(8/13): glibc-headers-2.12-1.149.el6.x86_64.rpm                                                                                                                                                                                                                                                       | 611 kB     00:00
(9/13): kernel-headers-2.6.32-504.el6.x86_64.rpm                                                                                                                                                                                                                                                      | 3.3 MB     00:00
(10/13): libgcc-4.4.7-11.el6.x86_64.rpm                                                                                                                                                                                                                                                               | 102 kB     00:00
(11/13): libgomp-4.4.7-11.el6.x86_64.rpm                                                                                                                                                                                                                                                              | 133 kB     00:00
(12/13): mpfr-2.4.1-6.el6.x86_64.rpm                                                                                                                                                                                                                                                                  | 157 kB     00:00
(13/13): ppl-0.10.2-11.el6.x86_64.rpm                                                                                                                                                                                                                                                                 | 1.3 MB     00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                                                                        8.9 MB/s |  39 MB     00:04
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
Userid : EPEL (6) <epel@fedoraproject.org>
Package: epel-release-6-8.noarch (installed)
From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Updating   : libgcc-4.4.7-11.el6.x86_64                                                                                                                                                                                                                                                                               1/16
  Updating   : glibc-2.12-1.149.el6.x86_64                                                                                                                                                                                                                                                                              2/16
  Updating   : glibc-common-2.12-1.149.el6.x86_64                                                                                                                                                                                                                                                                       3/16
  Installing : libgomp-4.4.7-11.el6.x86_64                                                                                                                                                                                                                                                                              4/16
  Installing : mpfr-2.4.1-6.el6.x86_64                                                                                                                                                                                                                                                                                  5/16
  Installing : cpp-4.4.7-11.el6.x86_64                                                                                                                                                                                                                                                                                  6/16
  Installing : ppl-0.10.2-11.el6.x86_64                                                                                                                                                                                                                                                                                 7/16
  Installing : cloog-ppl-0.15.7-1.2.el6.x86_64                                                                                                                                                                                                                                                                          8/16
  Installing : kernel-headers-2.6.32-504.el6.x86_64                                                                                                                                                                                                                                                                     9/16
  Installing : glibc-headers-2.12-1.149.el6.x86_64                                                                                                                                                                                                                                                                     10/16
  Installing : glibc-devel-2.12-1.149.el6.x86_64                                                                                                                                                                                                                                                                       11/16
  Installing : gcc-4.4.7-11.el6.x86_64                                                                                                                                                                                                                                                                                 12/16
  Installing : dkms-2.2.0.3-28.git.7c3e7c5.el6.noarch                                                                                                                                                                                                                                                                  13/16
  Cleanup    : glibc-2.12-1.107.el6.x86_64                                                                                                                                                                                                                                                                             14/16
  Cleanup    : glibc-common-2.12-1.107.el6.x86_64                                                                                                                                                                                                                                                                      15/16
  Cleanup    : libgcc-4.4.7-3.el6.x86_64                                                                                                                                                                                                                                                                               16/16
  Verifying  : glibc-common-2.12-1.149.el6.x86_64                                                                                                                                                                                                                                                                       1/16
  Verifying  : gcc-4.4.7-11.el6.x86_64                                                                                                                                                                                                                                                                                  2/16
  Verifying  : glibc-2.12-1.149.el6.x86_64                                                                                                                                                                                                                                                                              3/16
  Verifying  : dkms-2.2.0.3-28.git.7c3e7c5.el6.noarch                                                                                                                                                                                                                                                                   4/16
  Verifying  : glibc-headers-2.12-1.149.el6.x86_64                                                                                                                                                                                                                                                                      5/16
  Verifying  : glibc-devel-2.12-1.149.el6.x86_64                                                                                                                                                                                                                                                                        6/16
  Verifying  : libgcc-4.4.7-11.el6.x86_64                                                                                                                                                                                                                                                                               7/16
  Verifying  : libgomp-4.4.7-11.el6.x86_64                                                                                                                                                                                                                                                                              8/16
  Verifying  : mpfr-2.4.1-6.el6.x86_64                                                                                                                                                                                                                                                                                  9/16
  Verifying  : cpp-4.4.7-11.el6.x86_64                                                                                                                                                                                                                                                                                 10/16
  Verifying  : kernel-headers-2.6.32-504.el6.x86_64                                                                                                                                                                                                                                                                    11/16
  Verifying  : ppl-0.10.2-11.el6.x86_64                                                                                                                                                                                                                                                                                12/16
  Verifying  : cloog-ppl-0.15.7-1.2.el6.x86_64                                                                                                                                                                                                                                                                         13/16
  Verifying  : glibc-2.12-1.107.el6.x86_64                                                                                                                                                                                                                                                                             14/16
  Verifying  : libgcc-4.4.7-3.el6.x86_64                                                                                                                                                                                                                                                                               15/16
  Verifying  : glibc-common-2.12-1.107.el6.x86_64                                                                                                                                                                                                                                                                      16/16

Installed:
  dkms.noarch 0:2.2.0.3-28.git.7c3e7c5.el6

Dependency Installed:
  cloog-ppl.x86_64 0:0.15.7-1.2.el6        cpp.x86_64 0:4.4.7-11.el6        gcc.x86_64 0:4.4.7-11.el6        glibc-devel.x86_64 0:2.12-1.149.el6        glibc-headers.x86_64 0:2.12-1.149.el6        kernel-headers.x86_64 0:2.6.32-504.el6        libgomp.x86_64 0:4.4.7-11.el6        mpfr.x86_64 0:2.4.1-6.el6
  ppl.x86_64 0:0.10.2-11.el6

Dependency Updated:
  glibc.x86_64 0:2.12-1.149.el6                                                                          glibc-common.x86_64 0:2.12-1.149.el6                                                                          libgcc.x86_64 0:4.4.7-11.el6

Complete!

もう一度インストールしてみる。
$ sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.12 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.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
Building the main Guest Additions module                   [失敗]
(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.

さっきとちょっと変わったけど、またしてもエラー・・・。

エラーログを確認してみると、
Uninstalling modules from DKMS
Attempting to install using DKMS

Creating symlink /var/lib/dkms/vboxguest/4.3.12/source ->
                 /usr/src/vboxguest-4.3.12

DKMS: add completed.

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
make KERNELRELEASE=2.6.32-358.el6.x86_64 -C /lib/modules/2.6.32-358.el6.x86_64/build M=/var/lib/dkms/vboxguest/4.3.12/build...(bad exit status: 2)
Error! Bad return status for module build on kernel: 2.6.32-358.el6.x86_64 (x86_64)
Consult /var/lib/dkms/vboxguest/4.3.12/build/make.log for more information.
Failed to install using DKMS, attempting to install without
make KBUILD_VERBOSE=1 CONFIG_MODULE_SIG= -C /lib/modules/2.6.32-358.el6.x86_64/build SUBDIRS=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 modules
test -e include/linux/autoconf.h -a -e include/config/auto.conf || (            \
        echo;                                                           \
        echo "  ERROR: Kernel configuration is invalid.";               \
        echo "         include/linux/autoconf.h or include/config/auto.conf are missing.";      \
        echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";  \
        echo;                                                           \
        /bin/false)
mkdir -p /tmp/vbox.0/.tmp_versions ; rm -f /tmp/vbox.0/.tmp_versions/*
make -f scripts/Makefile.build obj=/tmp/vbox.0
  gcc -Wp,-MD,/tmp/vbox.0/.VBoxGuest-linux.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.4.7/include -Iinclude  -I/usr/src/kernels/2.6.32-358.el6.x86_64/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -fstack-protector -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Wframe-larger-than=2048 -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack -include /tmp/vbox.0/include/VBox/VBoxGuestMangling.h -I/lib/modules/2.6.32-358.el6.x86_64/build/include -I/tmp/vbox.0/ -I/tmp/vbox.0/include -I/tmp/vbox.0/r0drv/linux -I/tmp/vbox.0/vboxguest/ -I/tmp/vbox.0/vboxguest/include -I/tmp/vbox.0/vboxguest/r0drv/linux -D__KERNEL__ -DMODULE -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS  -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(VBoxGuest_linux)"  -D"KBUILD_MODNAME=KBUILD_STR(vboxguest)" -D"DEBUG_HASH=24" -D"DEBUG_HASH2=60" -c -o /tmp/vbox.0/.tmp_VBoxGuest-linux.o /tmp/vbox.0/VBoxGuest-linux.c
  set -e ; perl /usr/src/kernels/2.6.32-358.el6.x86_64/scripts/recordmcount.pl "x86_64" "64" "objdump" "objcopy" "gcc" "ld" "nm" "" "" "1" "/tmp/vbox.0/VBoxGuest-linux.o";
/bin/sh: perl: コマンドが見つかりません
make[2]: *** [/tmp/vbox.0/VBoxGuest-linux.o] エラー 127
make[1]: *** [_module_/tmp/vbox.0] エラー 2
make: *** [vboxguest] エラー 2
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

なんかkernelのバージョンが一致していないことが問題らしい。

$ rpm -qa | grep kernel
dracut-kernel-004-303.el6.noarch
kernel-2.6.32-358.el6.x86_64
kernel-devel-2.6.32-358.el6.x86_64
kernel-firmware-2.6.32-358.el6.noarch
kernel-headers-2.6.32-504.el6.x86_64

どうやら
kernel-headers-2.6.32-504.el6.x86_64
ってやつだけあってないので、これだけダウングレードする。

$ sudo yum downgrade http://vault.centos.org/6.4/os/x86_64/Packages/kernel-headers-2.6.32-358.el6.x86_64.rpm
Loaded plugins: fastestmirror
Setting up Downgrade Process
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
kernel-headers-2.6.32-358.el6.x86_64.rpm                                                                                                                                                                                                                                                              | 2.3 MB     00:02
Examining /var/tmp/yum-root-UTuUDk/kernel-headers-2.6.32-358.el6.x86_64.rpm: kernel-headers-2.6.32-358.el6.x86_64
Resolving Dependencies
--> Running transaction check
---> Package kernel-headers.x86_64 0:2.6.32-358.el6 will be a downgrade
---> Package kernel-headers.x86_64 0:2.6.32-504.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================================================================================================
 Package                                                                  Arch                                                             Version                                                                     Repository                                                                                       Size
=============================================================================================================================================================================================================================================================================================================================
Downgrading:
 kernel-headers                                                           x86_64                                                           2.6.32-358.el6                                                              /kernel-headers-2.6.32-358.el6.x86_64                                                           2.5 M

Transaction Summary
================================================================================
Downgrade     1 Package(s)

Total size: 2.5 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : kernel-headers-2.6.32-358.el6.x86_64
  Cleanup    : kernel-headers-2.6.32-504.el6.x86_64
  Verifying  : kernel-headers-2.6.32-358.el6.x86_64
  Verifying  : kernel-headers-2.6.32-504.el6.x86_64

Removed:
  kernel-headers.x86_64 0:2.6.32-504.el6

Installed:
  kernel-headers.x86_64 0:2.6.32-358.el6

Complete!

カーネル合わせた後に再びやってみる。
# sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.12 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.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
Building the main Guest Additions module                   [失敗]
(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.

またしてもエラー。
$ less /var/log/vboxadd-install.log

Uninstalling modules from DKMS
Attempting to install using DKMS

Creating symlink /var/lib/dkms/vboxguest/4.3.12/source ->
                 /usr/src/vboxguest-4.3.12

DKMS: add completed.

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
make KERNELRELEASE=2.6.32-358.el6.x86_64 -C /lib/modules/2.6.32-358.el6.x86_64/build M=/var/lib/dkms/vboxguest/4.3.12/build...(bad exit status: 2)
Error! Bad return status for module build on kernel: 2.6.32-358.el6.x86_64 (x86_64)
Consult /var/lib/dkms/vboxguest/4.3.12/build/make.log for more information.
Failed to install using DKMS, attempting to install without
make KBUILD_VERBOSE=1 CONFIG_MODULE_SIG= -C /lib/modules/2.6.32-358.el6.x86_64/build SUBDIRS=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 modules
test -e include/linux/autoconf.h -a -e include/config/auto.conf || (            \
        echo;                                                           \
        echo "  ERROR: Kernel configuration is invalid.";               \
        echo "         include/linux/autoconf.h or include/config/auto.conf are missing.";      \
        echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";  \
        echo;                                                           \
        /bin/false)
mkdir -p /tmp/vbox.0/.tmp_versions ; rm -f /tmp/vbox.0/.tmp_versions/*
make -f scripts/Makefile.build obj=/tmp/vbox.0
  gcc -Wp,-MD,/tmp/vbox.0/.VBoxGuest-linux.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.4.7/include -Iinclude  -I/usr/src/kernels/2.6.32-358.el6.x86_64/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -fstack-protector -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Wframe-larger-than=2048 -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-dwarf2-cfi-asm -fconserve-stack -include /tmp/vbox.0/include/VBox/VBoxGuestMangling.h -I/lib/modules/2.6.32-358.el6.x86_64/build/include -I/tmp/vbox.0/ -I/tmp/vbox.0/include -I/tmp/vbox.0/r0drv/linux -I/tmp/vbox.0/vboxguest/ -I/tmp/vbox.0/vboxguest/include -I/tmp/vbox.0/vboxguest/r0drv/linux -D__KERNEL__ -DMODULE -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS  -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(VBoxGuest_linux)"  -D"KBUILD_MODNAME=KBUILD_STR(vboxguest)" -D"DEBUG_HASH=24" -D"DEBUG_HASH2=60" -c -o /tmp/vbox.0/.tmp_VBoxGuest-linux.o /tmp/vbox.0/VBoxGuest-linux.c
  set -e ; perl /usr/src/kernels/2.6.32-358.el6.x86_64/scripts/recordmcount.pl "x86_64" "64" "objdump" "objcopy" "gcc" "ld" "nm" "" "" "1" "/tmp/vbox.0/VBoxGuest-linux.o";
/bin/sh: perl: コマンドが見つかりません
make[2]: *** [/tmp/vbox.0/VBoxGuest-linux.o] エラー 127
make[1]: *** [_module_/tmp/vbox.0] エラー 2
make: *** [vboxguest] エラー 2
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

perlコマンドがないらしいので、perlをインストール

$ sudo yum install perl

もう一回試してみた。
# sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.12 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.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  ]
Starting the VirtualBox Guest Additions                    [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.

出来た!!!!
Building the VirtualBox Guest Additions kernel modulesの所でやたら時間掛かってたみたいで心配でしたが出来てました。
以上で仮想マシンの設定は完了。
マシンはシャットダウンしておく。

4.BaseBoxファイルにパッケージする


今度はホスト側で作業を行う。
■仮想マシンが保存されているディレクトリに移動してBase Boxファイルにパッケージする。
$ cd ~/VirtualBox\ VMs/vagrant-centos64/
$ vagrant package --base vagrant-centos64

■完成したBase BoxファイルをVagrantに登録する。
$ cd ~/VirtualBox VMs/box新規作成用/vagrant-centos64
$ vagrant box add centos64_30gb package.box
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/builtin/box_add.rb:44:in `file?': "\x88\x90" from Windows-31J to UTF-8 (Encoding::UndefinedConversionError)
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/builtin/box_add.rb:44:in `block in call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/builtin/box_add.rb:29:in `map'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/builtin/box_add.rb:29:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/builder.rb:116:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/runner.rb:66:in `block in run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/util/busy.rb:19:in `busy'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/action/runner.rb:66:in `run'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/plugins/commands/box/command/add.rb:85:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/plugins/commands/box/command/root.rb:61:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/cli.rb:42:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/environment.rb:292:in `cli'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/bin/vagrant:174:in `
'

出来たboxを追加しようとしたらエラーになった・・・。
日本語があやしい気がしたので、とりあえずVirtualBox上で作っていたグループから移動させた。
$ mv ~/VirtualBox VMs/box新規作成用/vagrant-centos64 ~/VirtualBox VMs\vagrant-centos64

で、新しいディレクトリへ移動

$ cd ~/VirtualBox VMs\vagrant-centos64

もう一回addしてみる。

$ vagrant box add centos64_30gb package.box
==> box: Adding box 'centos64_30gb' (v0) for provider:
    box: Downloading: file://C:/Users/kusagaya-naoki/VirtualBox%20VMs/vagrant-centos64/package.box
    box:
==> box: Successfully added box 'centos64_30gb' (v0) for 'virtualbox'!

出来た!

box追加して起動させてみたら、エラーが出た。(エラー内容のログ取り忘れた・・・。)
内容的にはSCPインストールしろよって感じのエラーだったので、VirtualBoxをもう一度起動して、サーバにログイン。 openssh-clientsをyum経由でインストールし、再度シャットダウンしてみたらうまく行った。