page_adsence

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

2015年7月23日木曜日

vagrant haltやsuspendコマンドが使えない

ansible-playbookを処理途中で「Ctrl + C」した影響か、vagrant haltやsuspendコマンドを実行すると下記の様なエラーが出るようになってしまった。
ちなみに、vagrant statusやvagrant sshは普通に使えました。

$ vagrant halt
An action 'halt' was attempted on the machine 'default',
but another process is already executing an action on the machine.
Vagrant locks each machine for access by only one process at a time.
Please wait until the other Vagrant process finishes modifying this
machine, then try again.

If you believe this message is in error, please check the process
listing for any "ruby" or "vagrant" processes and kill them. Then
try again.

原因はホストマシン側(自分の場合はWindows)で動いているrubyによるものらしい。
vagrantコマンドを実行するとホストマシン上でrubyが実行されるのですが、
コマンドの処理終了のタイミングでrubyのプロセスも切れる様になっている。
しかし、このメッセージが出ている時は、rubyのプロセスが切れずに残り続けている状態になっていた。
対応としては、該当のrubyのプロセスを切ってやればいい。
タスクマネージャーを開くと、ruby.exeというプロセスが残っているはずなので、それを右クリックしてプロセス終了をクリック。
終了したら通常通りvagrant haltやsuspendなどが使えるようになりました。

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!

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

2015年4月9日木曜日

Vagrantでsuspendからresumeする際のポート問題

vagrantでマシンを起動や停止を行う際に、「vagrant up」「vagrant halt」を使っていたが、
これだと起動や停止にかかる時間が長いのでよく利用するVMに関しては「vagrant suspend」(一時停止)「vagrant resume」(復帰)を利用するようにしている。
しかしこの「vagrant suspend」「vagrant resume」を複数のVMで併用していると、ある工程で作業をすると問題が出てくる。

問題となる手順は以下の通り。
1.VM1を「vagrant up」で起動
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> 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: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (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:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> 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/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX-1
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.

2.VM1を「vagrant suspend」で一時停止
$ vagrant suspend
==> default: Saving VM state and suspending execution...

3.VM2を「vagrant up」で起動
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> 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: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (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:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> 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/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX-2
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.

4.VM2を「vagrant suspend」で一時停止
$ vagrant suspend
==> default: Saving VM state and suspending execution...

5.VM1で「vagrant resume」で起動
$ 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:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection refused. Retrying...
==> default: Machine booted and ready!

6.VM2で「vagrant resume」をするが起動しない。
$ vagrant resume
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 2222 is already in use
on the host machine.

To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 22, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.

ここで、何が問題になって起動しないかというと、ホストマシンからVMにSSH接続する際に使用するポートの重複が問題となっている。
※VMを2台同時に立ち上げる事が問題なのではなく、立ち上げる時の工程に問題がある。

こういった問題を回避する為に、予めローカルからVMにSSH接続する際に使用するポート番号を変更しておく必要がある。
ポート番号の変更方法は、Vagrantfileに下記の様な設定を追加する事で回避出来る。

config.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2223

一度全てのVMを「vagrant halt」で停止させてから、Vagrantfileを編集し、上記設定を追記した状態で「vagrant up」する。
追加する場所は下記のコメントがあるので、その下辺りに追加する。

# config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2223 ← この部分を追記

保存した状態で再び「vagrant up」すると、
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> 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: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2223 (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:2223
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
==> 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/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX-2
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.

この様な感じで立ち上がる。
ちなみに複数台立ち上げて「vagrant resume」「vagrant suspend」しても問題ない手順は以下の通り。

1.VM1を「vagrant up」で起動
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> 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: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (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:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> 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/kusagaya-naoki/VirtualBoxMachines/jenkins-laravel
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.

2.VM2を「vagrant up」で起動
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> 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 => 2200 (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:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
==> 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/kusagaya-naoki/VirtualBoxMachines/jenkins-laravel-2
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.

3.VM1を「vagrant suspend」で停止
$ vagrant suspend
==> default: Saving VM state and suspending execution...

4.VM2を「vagrant suspend」で停止
$ vagrant suspend
==> default: Saving VM state and suspending execution...

5.VM1を「vagrant resume」で起動
$ 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:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection refused. Retrying...
==> default: Machine booted and ready!

6.VM2を「vagrant resume」で起動
$ 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:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection refused. Retrying...
==> default: Machine booted and ready!

赤文字にした部分も見てもらえれば一目瞭然だと思いますが、
なぜこの手順で問題ないかというと、「vagrant up」時にはSSHポート番号が重複していた場合に
vagrantが自動で別の開いているポートを使用して立ち上げる様になっている。
しかし、このポートチェックは現在起動しているVMで使用されているポート番号だけで、一時停止されているVMに使われているポート番号はチェック対象にならない。
そのため、手順によってはこういった現象が発生する。
常にこの様な手順で起動させるようにしていればこういった事態にはならないが、常にこの手順を守れるわけではないので、予めポート番号は設定しておいたほうが良さげ。

2015年4月7日火曜日

Vagrant upをした時のエラー

vagrantを使ってVM作ろうと思ったのですが、Vagrantfileの中身を色々と間違えていた事に気がついたので、1から作リ直そうとした時に出たエラー。

行った作業としては以下の通り。

$ vagrant init box-name

$ vi Vagrantfile

$ vagrant up

ここで間違いに気がついたので、VirtualBoxでマシンを停止。(ここでVirtualBoxで止めるのではなく、vagrant haltしてれば起きなかったかもしれない)

$ vagrant destroy

$ vim Vagrantfile
Vagrantfileの中身を修正(但しvb.nameは同じ)

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos6.4-30gb'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: jenkins-laravel
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["modifyvm", "a36f7bef-e56e-4686-91a4-a649a92f3a17", "--name", "jenkins-laravel"]

Stderr: VBoxManage.exe: error: Could not rename the directory 'C:\Users\username\VirtualBox VMs\vagrant-centos64_1_1427941735336_99768' to 'C:\Users\username\VirtualBox VMs\jenkins-laravel' to save the settings file (VERR_ALREADY_EXISTS)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component SessionMachine, interface IMachine, callee IUnknown
VBoxManage.exe: error: Context: "SaveSettings()" at line 2716 of file VBoxManageModifyVM.cpp

こんな感じのエラーが出た。
色々と試行錯誤してみたけど、原因はvagrant destroyした時に
C:\Users\username\VirtualBox VMs\jenkins-laravel
のフォルダが消えていなかったため、重複していてリネームできなかった事が原因だった。

2015年2月13日金曜日

Ansibleで作った環境をServerspecでテストする

ServerspecとはAnsibleやChef、Puppetといったプロビジョニングツールで作成された環境が、本当に意図した通りに作成されているのかをテストするためのツール。
Rubyで書かれていて、RubyのテストフレームワークであるRSpecの書き方に準拠している。

説明はこのくらいにして、実際に使ってみる。
テストする環境としては、自分のローカルPC上に作成したVMマシンで、
既にVagrant、VirtualBox、Ansibleが使える状態になっている。
今回、ServerspecでテストするサーバはVagrant使って新しいVMを作っておく。

まずはインストールから。
gemがインストールしてあることが前提。

user_name@computer_name ~
$ gem install serverspec
DL is deprecated, please use Fiddle
Fetching: rspec-support-3.2.1.gem (100%)
Successfully installed rspec-support-3.2.1
Fetching: rspec-mocks-3.2.0.gem (100%)
Successfully installed rspec-mocks-3.2.0
Fetching: rspec-expectations-3.2.0.gem (100%)
Successfully installed rspec-expectations-3.2.0
Fetching: rspec-core-3.2.0.gem (100%)
Successfully installed rspec-core-3.2.0
Fetching: rspec-3.2.0.gem (100%)
Successfully installed rspec-3.2.0
Fetching: rspec-its-1.1.0.gem (100%)
Successfully installed rspec-its-1.1.0
Fetching: multi_json-1.10.1.gem (100%)
Successfully installed multi_json-1.10.1
Fetching: net-scp-1.2.1.gem (100%)
Successfully installed net-scp-1.2.1
Fetching: specinfra-2.12.7.gem (100%)
Successfully installed specinfra-2.12.7
Fetching: serverspec-2.8.2.gem (100%)
Successfully installed serverspec-2.8.2
Parsing documentation for multi_json-1.10.1
Installing ri documentation for multi_json-1.10.1
Parsing documentation for net-scp-1.2.1
Installing ri documentation for net-scp-1.2.1
Parsing documentation for rspec-3.2.0
Installing ri documentation for rspec-3.2.0
Parsing documentation for rspec-core-3.2.0
Installing ri documentation for rspec-core-3.2.0
Parsing documentation for rspec-expectations-3.2.0
Installing ri documentation for rspec-expectations-3.2.0
Parsing documentation for rspec-its-1.1.0
Installing ri documentation for rspec-its-1.1.0
Parsing documentation for rspec-mocks-3.2.0
Installing ri documentation for rspec-mocks-3.2.0
Parsing documentation for rspec-support-3.2.1
Installing ri documentation for rspec-support-3.2.1
Parsing documentation for serverspec-2.8.2
Installing ri documentation for serverspec-2.8.2
Parsing documentation for specinfra-2.12.7
Installing ri documentation for specinfra-2.12.7
Done installing documentation for multi_json, net-scp, rspec, rspec-core, rspec-expectations, rspec-its, rspec-mocks, rspec-support, serverspec, specinfra after 40 seconds
10 gems installed

次にテストしたいVMのVagrantfileがあるディレクトリへ移動。
自分の場合は下記のディレクトリだったので、そこへ移動。

user_name@computer_name ~
$ cd VirtualBoxMachines/test

でserverspecを初期化する。

user_name@computer_name ~/VirtualBoxMachines/test
$ serverspec-init
DL is deprecated, please use Fiddle
Select OS type:

  1) UN*X
  2) Windows

Select number: 1 ← serverspecでチェックするマシンがUnix系なのかWindows系なのかを選択

Select a backend type:

  1) SSH
  2) Exec (local)

Select number: 1 ← SSHで接続するリモートサーバなのか、ローカルサーバなのか。

Vagrant instance y/n: y ← Vagrantで作成したマシンなのか
Auto-configure Vagrant from Vagrantfile? y/n: y ← Vagrantfileを元にしてserverspecの設定ファイルを勝手に作ってくれる
 + spec/
 + spec/default/
 + spec/default/sample_spec.rb
 + spec/spec_helper.rb
 + Rakefile
 + .rspec

初期化すると、上記に書かれているファイルができている。
特に修正するわけでもなく、早速テストしてみる。

user_name@computer_name ~/VirtualBoxMachines/test
$ rake spec
rake aborted!
Circular dependency detected: TOP => spec => spec:all => spec:default => spec:all

Tasks: TOP => spec => spec:all => spec:default
(See full trace by running task with --trace)

エラーになった・・・。
原因をググって見ると、下記の様な記事が出てきたので、とりあえず記事通りに修正してみる。
https://saintaardvarkthecarpeted.com/blog/archive/2014/10/_Circular_dependency_detected__error_in_ServerSpec.html

user_name@computer_name ~/VirtualBoxMachines/test
$ vim Rakefile
require 'rake'
require 'rspec/core/rake_task'

task :spec    => 'spec:all'
task :default => :spec

namespace :spec do
  targets = []
  Dir.glob('./spec/*').each do |dir|
    next unless File.directory?(dir)
    targets << File.basename(dir)
  end

  task :all     => targets
  # task :default => :all ← ここをコメントアウトする

  targets.each do |target|
    desc "Run serverspec tests to #{target}"
    RSpec::Core::RakeTask.new(target.to_sym) do |t|
      ENV['TARGET_HOST'] = target
      t.pattern = "spec/#{target}/*_spec.rb"
    end
  end
end

もう一回試しに走らせてみる。
user_name@computer_name ~/VirtualBoxMachines/test
$ rake spec
/usr/local/bin/ruby.exe -I'/usr/local/lib/ruby/gems/2.1.0/gems/rspec-support-3.2.1/lib':'/usr/local/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.0/lib' '/usr/local/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.0/exe/rspec' --pattern 'spec/default/*_spec.rb'
DL is deprecated, please use Fiddle

Package "httpd"
  should be installed (FAILED - 1)

Service "httpd"
  should be enabled (FAILED - 2)
  should be running (FAILED - 3)

Port "80"
  should be listening (FAILED - 4)

Failures:

  1) Package "httpd" should be installed
     On host `default'
     Failure/Error: it { should be_installed }
       expected Package "httpd" to be installed
       sudo -p 'Password: ' /bin/sh -c rpm\ -q\ httpd
       package httpd is not installed

     # ./spec/default/sample_spec.rb:4:in `block (2 levels) in '

  2) Service "httpd" should be enabled
     On host `default'
     Failure/Error: it { should be_enabled }
       expected Service "httpd" to be enabled
       sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\ httpd\ \|\ grep\ 3:on

     # ./spec/default/sample_spec.rb:8:in `block (2 levels) in '

  3) Service "httpd" should be running
     On host `default'
     Failure/Error: it { should be_running }
       expected Service "httpd" to be running
       sudo -p 'Password: ' /bin/sh -c ps\ aux\ \|\ grep\ -w\ --\ httpd\ \|\ grep\ -qv\ grep

     # ./spec/default/sample_spec.rb:9:in `block (2 levels) in '

  4) Port "80" should be listening
     On host `default'
     Failure/Error: it { should be_listening }
       expected Port "80" to be listening
       sudo -p 'Password: ' /bin/sh -c netstat\ -tunl\ \|\ grep\ --\ :80\\\

     # ./spec/default/sample_spec.rb:13:in `block (2 levels) in '

Finished in 0.33207 seconds (files took 19.95 seconds to load)
4 examples, 4 failures

Failed examples:

rspec ./spec/default/sample_spec.rb:4 # Package "httpd" should be installed
rspec ./spec/default/sample_spec.rb:8 # Service "httpd" should be enabled
rspec ./spec/default/sample_spec.rb:9 # Service "httpd" should be running
rspec ./spec/default/sample_spec.rb:13 # Port "80" should be listening

/usr/local/bin/ruby.exe -I'/usr/local/lib/ruby/gems/2.1.0/gems/rspec-support-3.2.1/lib':'/usr/local/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.0/lib' '/usr/local/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.0/exe/rspec' --pattern 'spec/default/*_spec.rb' failed

テストは通ってない(apacheインストールしてないので当然ですが)けど、動きました。
真っ赤っ赤で不安になる。
ちなみにテストが通る様になった時の結果がこれ。

user_name@computer_name ~/VirtualBoxMachines/test
$ rake spec
/usr/local/bin/ruby.exe -I'/usr/local/lib/ruby/gems/2.1.0/gems/rspec-support-3.2.1/lib':'/usr/local/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.0/lib' '/usr/local/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.0/exe/rspec' --pattern 'spec/default/*_spec.rb'
DL is deprecated, please use Fiddle

Package "httpd"
  should be installed

Service "httpd"
  should be enabled
  should be running

Port "80"
  should be listening

Finished in 0.1375 seconds (files took 15.45 seconds to load)
4 examples, 0 failures

緑色になって安心。
こうなるまでひたすらAnsibleのplaybookを修正し続ける。

2015年2月5日木曜日

AnsibleでSELinuxをOFFにする方法

AnsibleでSELinuxをOFFにするための方法を調べてみた。

ググってみると下記の記事が見つかった。

Ansibleの事例とちょっとしたTips

この部分を見ながらやってみたが、どうもうまく行かない。
ymlの記述を全く同じにしてみてもうまくいかない。

-bash: sudo: コマンドが見つかりません

なんで記事中ではうまくいってるのに、自分の環境じゃダメなのかと思ったのですが、
原因は自分の環境がCygwin環境だからでした。
なので、下記のように修正してやってみる。

---
- name: Install libselinux-python
  yum: name=libselinux-python state=present

- name: Check status of selinux
  shell: getenforce

- name: Permissive selinux
  selinux: policy=targeted state=permissive

- name: reboot after change selinux
  shell: sleep 2s && /sbin/reboot &

- name: wait for the server to go down (reboot)
  local_action: wait_for host={{ inventory_hostname }} port=22 state=stopped
  sudo: no

- name: wait for the server to come up
  local_action: wait_for host={{ inventory_hostname }} port=22 delay=30
  sudo: no

- name: Check status of selinux
  shell: getenforce

再起動自体は行われたが、後続が続かない。
何をやってもダメで、他の方法を探してみた。

で、見つけた記事がこれ。

Ansible で Vagrant ホストを再起動する

「wait_for で待つ方法だと ansible-playbook が再起動以降でコケたり共有フォルダーがマウントされなくなったりとダメ。」
という記述を見つけて愕然。
今まで色々と試行錯誤してみたけど、無駄だったことが発覚。
とりあえず、この方法で出来るのかを検証してみることにした。

$ vi selinux-off.yml

---
- name: Install libselinux-python
  yum: name=libselinux-python state=installed

- name: disable SELinux
  sudo: yes
  selinux: state=disabled

- include: reboot.yml

$ vi reboot.yml

---
- name: reboot vagrant host
  command: 'vagrant reload'
  delegate_to: 127.0.0.1
  changed_when: false

この様な感じでファイルを用意して試してみたら、見事成功。
ということで、この方法を採用してplaybookを作っていきたいと思います。

2015年2月3日火曜日

vagrantコマンドでよく使うもの

vagrantのコマンドでよく使うものを中心にメモしておく。
vagrant box add
boxの追加。
boxを追加しておくと、すでにあるLinuxイメージをローカルにダウンロードし、登録しておくイメージ。
追加されたboxは初期化することですぐに利用出来る様になる。
boxのダウンロードはある程度時間が掛かる。
boxファイルは色々な所に落ちているが、下記の様にまとめサイト的なものもある。

http://www.vagrantbox.es/

$ vagrant box add [box-name] [box-url]

例)
$ vagrant box add centos6.4 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box

vagrant box list
すでに追加されているboxの一覧を確認する。
今までbox addコマンドで追加したboxの一覧が確認出来る。

$ vagrant box list

例)
$ vagrant box list
centos6.4       (virtualbox, 0)
centos6.4-30gb  (virtualbox, 0)
centos6.4-nomal (virtualbox, 0)
centos6.5       (virtualbox, 0)
centos7.0       (virtualbox, 0)
test            (virtualbox, 0)

vagrant box remove
すでに追加してあるboxファイルを削除する。

$ vagrant box remove [box name]

例)
$ vagrant box remove test
Removing box 'test' (v0) with provider 'virtualbox'...

$ vagrant box list
centos6.4       (virtualbox, 0)
centos6.4-30gb  (virtualbox, 0)
centos6.4-nomal (virtualbox, 0)
centos6.5       (virtualbox, 0)
centos7.0       (virtualbox, 0)

vagrant init
boxを初期化する。
これをする事でVagrantfileが作成され、VMの細かい設定が出来るようになる。

$ vagrant init [box-name]

例)
$ vagrant init centos6.4
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

vagrant up
VMを起動する。Vagrantfileに書かれた内容に基づいたVMが作成され、起動する。

$ vagrant up

例)
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos6.4'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test-vm
==> 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 => 2222 (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:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
==> 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/username/VirtualBoxMachines/test-vm

vagrant halt
VMを停止する。

$ vagrant halt
==> default: Attempting graceful shutdown of VM...

vagrant suspend
VMを一時停止する

$ vagrant suspend
==> default: Saving VM state and suspending execution...

vagrant resume
一時停止されているVMを再開させる

$ 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:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!

vagrant status
VMのステータスを確認出来る

$ vagrant status
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

vagrant ssh
vagrant経由で起動させたVMにsshでログインする

$ vagrant ssh
Last login: Tue Feb  3 10:49:53 2015 from 192.168.33.100
[vagrant@vagrant ~]$

vagrant global-status
vagrant全体の状況が確認出来る。1度起動したVMはIDが振られる。
このIDを指定することで、対象のVMディレクトリ配下に移動しなくても起動出来る。

$ vagrant global-status
id       name    provider   state    directory
--------------------------------------------------------------------------------------------------
6dd4f19  default virtualbox saved    C:/cygwin64/home/user-name/vbox-cent64
b735130  default virtualbox poweroff C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1

The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"

vagrant global-status --prune
global-statusで確認した時、本来削除したはずのVMの管理情報が残っている場合がある。
そういった不要情報を綺麗にした状態にするためのオプションが「prune」

■通常のコマンドでステータス確認
$ vagrant global-status
id       name    provider   state    directory
------------------------------------------------------------------------------------------------------
17033d9  default virtualbox poweroff C:/cygwin64/home/user-name/virtualBox                            ← 削除済みなのに表示されている
754da86  default virtualbox poweroff C:/cygwin64/home/user-name/virtualBox_CentOS6.5                  ← 削除済みなのに表示されている
6dd4f19  default virtualbox poweroff C:/cygwin64/home/user-name/vbox-cent64
e8c4ab5  default virtualbox poweroff C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1-tmp  ← 削除済みなのに表示されている
2de0695  default virtualbox running  C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1

The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"

■削除済み情報を綺麗にして表示させる。
$ vagrant global-status --prune
C:/cygwin64/home/user-name/vbox-cent64/Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION
C:/cygwin64/home/user-name/virtualBox_CentOS6.5/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here
C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1/Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION
C:/cygwin64/home/user-name/vbox-cent64/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here
id       name    provider   state    directory
--------------------------------------------------------------------------------------------------
6dd4f19  default virtualbox poweroff C:/cygwin64/home/user-name/vbox-cent64
2de0695  default virtualbox running  C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1

The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"
C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1/Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION
C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here

vagrant destroy
作成されているVMを削除する。このコマンドを実行することで、VirtualBox上からもマシンが消える。
また、global-statusに出てくるIDを末尾につけることで、該当のVMのディレクトリに移動しなくても削除する事が可能。

$ vagrant destroy

vagrant box repackage
既に追加済みのBoxをカレントディレクトリにpackage.boxファイルとして出力する。

$ vagrant box repackage [provider_name] [version]

providerやversionはvagrant box listコマンドを打つと出てくる
$ vagrant box list
centos6.4       (virtualbox, 0)

この場合、コマンドは下記の様になる。
$ vagrant box repackage virtualbox 0


※下記のURLに綺麗にまとまっている。但しglobal-statusに関しては記載なし。
http://lab.raqda.com/vagrant/cli/

2015年1月30日金曜日

Windwosマシンからsambaへのアクセスでハマった

vagrant + ansibleを使ってVMのセットアップをして、いざ共有ディレクトリにアクセスしたら、アクセス拒否。
原因がいまいちよくわからなかった。
結論から先に言うと、全ての原因はSELinuxだったということ。
playbookにSELinuxをオフにする記述を追加して、設定ファイルを確認。

$ view /etc/selinux/config
SELINUX=disabled

と書かれていたので、安心しきっていたのですが、実際には設定ファイルだけ書き換わっていて再起動されていなかったため、
SELinuxが普通に動いている状態でした。

$ getenforce



$ sestatus

で確認した所、ガンガン動いていた。
以下、ハマった事象に関しての詳細。

起こっていた現象

\\サーバのIP

にはアクセス出来る。

\\サーバのIP\public

にもアクセス出来る。

\\サーバのIP\vagrant

にはアクセス出来ない。

sambaの設定色々いじったり、VM側のディレクトリのパーミッション弄ってみたりと色々試しましたが全てダメ。
何がダメなのかわからなかったのですが、こんな記事を教えてもらって試してみた。
VM上で、下記のコマンドを実行したら見れる様になりました。

$ setsebool -P samba_enable_home_dirs on

これで問題なくなったと思っていたら、今度はフォルダとシェルスクリプトだけsamba上で見えていて、ファイルが一切見えないという状態に。
VM上で同じディレクトリを参照すると、特に問題なくファイルもあり、中身も閲覧出来る。
何が原因なんだと思って調べていた所、このサイトが引っかかった。
原因はSELinuxだと書かれていて、SELinuxはオフにしてあるはずなのになぁと思いつつ、確認してみた。

$ getenforce
Enforcing

普通に動いてました・・・。
なので

$ setenforce 0

で一時的に無効化してから、もう一度samba経由で対象のディレクトリにアクセス。
普通に見れました。

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経由でインストールし、再度シャットダウンしてみたらうまく行った。