2013年7月14日日曜日

Veeweeを使ってVagrant boxを作成する (その2)

次のようなメッセージを出力して、veeweeの「build」コマンドが失敗してしまったので原因を調べます。
$ bundle exec veewee vbox build 'CentOS-6.4-x86_64'
 :
Typing:[1]:  text ks=http://10.0.2.2:7122/ks.cfg
Error: We executed a shell command and the exit status was not 0
- Command :VBoxManage controlvm "CentOS-6.4-x86_64" keyboardputscancode 0f.
- Exitcode :1.
- Output   :
VBoxManage: error: Guest not running

$
メッセージから、VirtualBoxが上手く動いてないことは分かります。
しかし、VirtualBoxをちゃんと使ったことがないので、仮想マシンの起動の仕方が分かりません。

VirtualBox UserManualで調べると、VBoxManage startvmで、仮想マシンをスタートできるようです。
早速、試してみると次のように失敗しました。
$ VBoxManage startvm "CentOS-6.4-x86_64"
Waiting for VM "CentOS-6.4-x86_64" to power on...
VBoxManage: error: The virtual machine 'CentOS-6.4-x86_64' has terminated unexpe
ctedly during startup with exit code 0
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Machin
e, interface IMachine
$
ヒントがとれたので、ググるとforums.virtualbox.orgでNS_ERROR_FAILURE (0x80004005)という記事が見つかりました。
読んでみると、どうもGUIを使用しようとして失敗しているような感じです。
確かに、リモートからsshでログインして操作しているので該当しそうです。

--nogui--forceを付けて再度buildコマンドを実行します。
途中まで実行されているため、--forceを付けないとエラーになります。
$ bundle exec veewee vbox build 'CentOS-6.4-x86_64' --force --nogui
Downloading vbox guest additions iso v 4.2.14 - http://download.virtualbox.org/virtualbox/4.2.14/VBoxGuestAdditions_4.2.14.iso
Checking if isofile VBoxGuestAdditions_4.2.14.iso already exists.
Full path: /home/foo/work/veewee/iso/VBoxGuestAdditions_4.2.14.iso

The isofile VBoxGuestAdditions_4.2.14.iso already exists.
Building Box CentOS-6.4-x86_64 with Definition CentOS-6.4-x86_64:
- debug : false
- cwd : /home/foo/work/veewee
- force : true
- nogui : true
- auto : false
- checksum : false
- redirectconsole : false
- postinstall_include : []
- postinstall_exclude : []

The isofile CentOS-6.4-x86_64-minimal.iso already exists.
VBoxManage unregistervm  "CentOS-6.4-x86_64" --delete
Deleting vm CentOS-6.4-x86_64
Creating vm CentOS-6.4-x86_64 : 480M - 1 CPU - RedHat_64
Creating new harddrive of size 10140, format VDI, variant Standard
Attaching disk: /home/foo/VirtualBox VMs/CentOS-6.4-x86_64/CentOS-6.4-x86_641.vdi
Mounting cdrom: /home/foo/work/veewee/iso/CentOS-6.4-x86_64-minimal.iso
Mounting guest additions: /home/foo/work/veewee/iso/VBoxGuestAdditions_4.2.14.iso
Finding unused TCP port in range: 7222 - 7262
Selected TCP port 7222
Finding unused TCP port in range: 7222 - 7262
Selected TCP port 7222
Waiting 10 seconds for the machine to boot
Finding unused TCP port in range: 7122 - 7199
Selected TCP port 7122
Starting a webserver :7122

Typing:[1]:  text ks=http://10.0.2.2:7122/ks.cfg
Done typing.

 :
 :
No Match for argument: bitstream-vera-fonts
No Packages marked for removal
Loaded plugins: fastestmirror
Cleaning repos: base epel extras puppetlabs puppetlabs-dependencies updates
Cleaning up Everything
Cleaning up list of fastest mirrors
Waiting for ssh login on 127.0.0.1 with user veewee to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'veewee'|sudo -S sh './zerodisk.sh'
dd: writing `/EMPTY': デバイスに空き領域がありません
7454+0 records in
7453+0 records out
7815069696 bytes (7.8 GB) copied, 12.6561 s, 617 MB/s
The box CentOS-6.4-x86_64 was built successfully!
You can now login to the box with:
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 7222 -l veewee 127.0.0.1
$
なんかメッセージが出てますが、とりあえず成功したようです。
試しに、最後のメッセージにあるようにsshしたところ、ログインも出来ました。

次は、validateコマンドで作成した仮想マシンの検証をします。
$ bundle exec veewee vbox validate 'CentOS-6.4-x86_64'
Checking user - OK
Checking sudo - OK
Checking ruby - OK
Checking gem - OK
Checking chef - OK
Checking puppet - OK
Checking shared folder - OK
$
問題ないようです。
いよいよ、exportコマンドでboxを作ります。
$ bundle exec veewee vbox export 'CentOS-6.4-x86_64'
Vagrant requires the box to be shutdown, before it can export
Sudo also needs to work for user veewee
Performing a clean shutdown now.
Waiting for ssh login on 127.0.0.1 with user veewee to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo '/sbin/halt -h -p' > /tmp/shutdown.sh
Waiting for ssh login on 127.0.0.1 with user veewee to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: chmod +x /tmp/shutdown.sh
Waiting for ssh login on 127.0.0.1 with user veewee to sshd on port => 7222 to work, timeout=10000 sec
.
Executing command: echo 'veewee'|sudo -S sh '/tmp/shutdown.sh'
.......
Machine CentOS-6.4-x86_64 is powered off cleanly
Creating a temporary directory for export
Adding additional files
Creating Vagrantfile
Exporting the box
Executing VBoxManage export CentOS-6.4-x86_64 --output /tmp/d20130713-10173-1y2vmzn/box.ovf
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Successfully exported 1 machine(s).
Packaging the box
Cleaning up temporary directory

To import it into vagrant type:
vagrant box add 'CentOS-6.4-x86_64' '/home/foo/work/veewee/CentOS-6.4-x86_64.box'

To use it:
vagrant init 'CentOS-6.4-x86_64'
vagrant up
vagrant ssh
$
$ ls *.box
CentOS-6.4-x86_64.box
$
やっとboxができました。

0 件のコメント:

コメントを投稿