Box-Cutter で CentOS 7.1 の Box を作成する
久しぶりに Packer で CentOS 7 の Box を作成しようと思い、以前も使った Box-Cutter を使おうとしたらちょっと使い方が変わっていたのでメモ。
環境は Windows 7 64bit, Packer のバージョンは 0.8.6 です。
まず、そもそも Box-Cutter の CentOS 用リポジトリが以下のように移動していました。
https://github.com/box-cutter/centos-vm
↓
https://github.com/boxcutter/centos
なので改めて適当なディレクトリに clone。
>git clone https://github.com/boxcutter/centos >cd centos
CentOS 7.1 を作成することにしたので、centos71.json を編集。
memory を増やして iso_url を日本のミラーサーバに変更しました。
{
"_comment": "Build with `packer build -var-file=centos71.json centos.json`",
"vm_name": "centos71",
"cpus": "1",
"disk_size": "65536",
"iso_checksum": "1795184136b8bdddabe50453cc2cc2d46f0f7c5e",
"iso_checksum_type": "sha1",
"iso_name": "CentOS-7-x86_64-DVD-1503-01.iso",
"iso_url": "http://ftp.jaist.ac.jp/pub/Linux/CentOS/7/isos/x86_64/CentOS-7-x86_64-DVD-1503-01.iso",
"kickstart": "ks7.cfg",
"memory": "1024",
"parallels_guest_os_type": "centos7"
}日本語環境の Box にしたいので、http\ks7.cfg を開き、以下の部分を変更。
# Required settings lang ja_JP.UTF-8 keyboard jp106 rootpw vagrant authconfig --enableshadow --enablemd5 timezone Asia/Tokyo
この状態で普通に packer build を実行したら以下のようなエラーが発生しました。
>packer build -only=virtualbox-iso centos71.json Failed to parse template: 10 error(s) occurred: * Unknown root level key in template: 'cpus' * Unknown root level key in template: 'disk_size' * Unknown root level key in template: 'iso_checksum' * Unknown root level key in template: 'iso_checksum_type' * Unknown root level key in template: 'iso_name' * Unknown root level key in template: 'iso_url' * Unknown root level key in template: 'kickstart' * Unknown root level key in template: 'memory' * Unknown root level key in template: 'parallels_guest_os_type' * Unknown root level key in template: 'vm_name'
centos71.json の _comment の所をよく見ると書いてあるのですが、どうやら最近の Box-Cutter では centos.json に全体的な設定が記述してあり、バージョン番号入りの JSON ではバージョン毎に設定値が異なる変数のみが定義してあるようです。
なので書いてある通りに以下のようにして改めて実行。
>packer build -var-file=centos71.json -only=virtualbox-iso centos.json
これで暫く待つと box/virtualbox/centos71-nocm-0.1.0.box に Box が作成されました。