Skip to content

Instantly share code, notes, and snippets.

@hiroyuki-sato
Last active August 29, 2015 14:05
Show Gist options
  • Save hiroyuki-sato/535e6e36e4f2dee06cce to your computer and use it in GitHub Desktop.
Save hiroyuki-sato/535e6e36e4f2dee06cce to your computer and use it in GitHub Desktop.
CenOS7上でpackerを使う注意点

CenOS7上でpackerを使う注意点

  • オリジナルのpackerでは(現状NG)、修正版をプルリクエスト済み
  • 修正したpackerのプルリクエスト
  • CentOS7の場合qemu-system-x86_64というコマンドは存在しない。代わりに/usr/libexec/qemu-kvmを使う
  • CentOS7のqemu-kvmは、SDLによる画面描画に対応してない模様

CentOS7はqemu-kvmで、pc-1.0というマシーンタイプをサポートしていない。

/usr/libexec/qemu-kvm -machine help
Supported machines are:
none                 empty machine
pc                   RHEL 7.0.0 PC (i440FX + PIIX, 1996) (alias of pc-i440fx-rhel7.0.0)
pc-i440fx-rhel7.0.0  RHEL 7.0.0 PC (i440FX + PIIX, 1996) (default)
rhel6.5.0            RHEL 6.5.0 PC
rhel6.4.0            RHEL 6.4.0 PC
rhel6.3.0            RHEL 6.3.0 PC
rhel6.2.0            RHEL 6.2.0 PC
rhel6.1.0            RHEL 6.1.0 PC
rhel6.0.0            RHEL 6.0.0 PC
q35                  RHEL-7.0.0 PC (Q35 + ICH9, 2009) (alias of pc-q35-rhel7.0.0)
pc-q35-rhel7.0.0     RHEL-7.0.0 PC (Q35 + ICH9, 2009)

以下のようなコマンドを実行する。type=pc-1.0と書かれているのがわかる。

/usr/libexec/qemu-kvm \
  -boot once=d \
  -m 512m \
  -machine type=pc-1.0,accel=kvm \
  -netdev user,id=user.0 \
  -redir tcp:2224::22 \
  -drive file=output_centos_tdhtest/tdhtest.qcow2,if=virtio \
  -device virtio-net,netdev=user.0 -vnc 0.0.0.0:47 \
  -name tdhtest \
  -cdrom /path/to/home/packer_cache/cabcb83f9d4178f7ea5bbeecc671587881496066896a5bb0c1c579a80f921b3d.iso \
  -display none

次のようなtemplate.jsonを使うことでイメージが作成できる。

  • machine_typeを追加
  • qemu_binaryを指定する。

設定は次のとおり

 {
  "builders":
  [
    {
      "type": "qemu",
      "iso_url": "http://ftp.iij.ad.jp/pub/linux/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-minimal.iso",
      "iso_checksum": "0d9dc37b5dd4befa1c440d2174e88a87",
      "iso_checksum_type": "md5",
      "output_directory": "output_centos",
      "ssh_wait_timeout": "30s",
      "shutdown_command": "shutdown -P now",
      "disk_size": 5000,
      "format": "qcow2",
      "headless": true,
      "accelerator": "kvm",
      "http_directory": "httpdir",
      "http_port_min": 10082,
      "http_port_max": 10089,
      "machine_type": "pc",
      "ssh_host_port_min": 2222,
      "ssh_host_port_max": 2229,
      "ssh_username": "root",
      "ssh_password": "s0m3password",
      "ssh_port": 22,
      "ssh_wait_timeout": "90m",
      "vm_name": "tdhtest",
      "net_device": "virtio-net",
      "disk_interface": "virtio",
      "qemu_binary": "/usr/libexec/qemu-kvm",
      "boot_wait": "5s",
      "boot_command":
      [
        "<tab><wait5>",
        " text ks=http://ip/centos6-ks.cfg<return>"
      ]
    }
  ]
}

yum install vnc-server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment