Atomic HostのCentOSイメージをVirtualBoxで動かしてみる

概要

Red Hatが提供するDocker専用の軽量OS「Red Hat Enterprise Linux 7 Atomic Host」の
CentOSイメージ(テスト版)がリリースされました。

さっそく手元のMacOSのVirtualBoxで起動させてみました。

f:id:tsunokawa:20141118181236p:plain

イメージファイルはqcow2という形式で提供されています。
このイメージファイルを変換して、MacのVirtualMachineで使えるようにします。
http://www.projectatomic.io/download/
http://buildlogs.centos.org/rolling/7/


今回使用するファイルは
CentOS-7-x86_64-AtomicHost-20141029_02.qcow2
です。

qemu-imgインストール

イメージ変換の為、Macでqemu-imgコマンドが使えるようにインストールしておきます。
http://www.puredarwin.org/downloads
URL先のqemu-img.bz2をダウンロードして展開します。
bz2ファイル展開後、/usr/local/binへ移動後、chmod +xで実行権限を付与

イメージ変換(qcow2→raw)

qcow2→rawへ変換します。

qemu-img convert -f qcow2 -O raw CentOS-7-x86_64-AtomicHost-20141029_02.qcow2 CentOS-7-x86_64-AtomicHost-20141029_02.raw


イメージ変換(raw→vdi)

先ほどのrawファイルをvdiファイルへ変換します。

VBoxManage convertdd CentOS-7-x86_64-AtomicHost-20141029_02.raw CentOS-7-x86_64-AtomicHost-20141029_02.vdi

これでイメージ変換作業は完了です。

表示例

$ VBoxManage convertdd CentOS-7-x86_64-AtomicHost-20141029_02.raw CentOS-7-x86_64-AtomicHost-20141029_02.vdi
Converting from raw image file="CentOS-7-x86_64-AtomicHost-20141029_02.raw" to file="CentOS-7-x86_64-AtomicHost-20141029_02.vdi"...
Creating dynamic image with size 8589934592 bytes (8192MB)...
$


init.iso作成(CentOSで実行)

次に初期設定ファイルを作りそれをISOファイル化します。
この作業はMacで出来ないため、CentOSで実行します。

まず、

  • meta-data
  • user-data

という2つの設定ファイルを準備します。

meta-data
instance-id: iid-local01;
local-hostname: myhost;
user-data
#cloud-config
password: mypassword
ssh_pwauth: True
chpasswd: { expire: False }

ssh_authorized_keys:
  - ssh-rsa ... foo@foo.com (insert ~/.ssh/id_rsa.pub here)

パスワードは変更してください。
公開鍵は自分のものと置き換えてください。

ISOファイル化

次にgenisoimageコマンドでISOファイル化します。

yum install genisoimage.x86_64

genisoimageインストール後、ISOファイル化します。

genisoimage -output init.iso -volid cidata -joliet -rock user-data meta-data


VirtualBoxでブート

f:id:tsunokawa:20141118180304p:plain
イメージ変換したvdiファイルからブートします。
ブート中に↓のISOファイルをマウント作業を行ってください。

ISOファイルをマウント

f:id:tsunokawa:20141118180349p:plain
ブート中、先ほど作成したISOファイルinit.isoをCD/DVDでマウントします。


ログイン(コンソール)

f:id:tsunokawa:20141118180010p:plain

初期ユーザ名 centos
パスワード mypassword

このパスワードは先程の手順で設定ファイルに記述したものです。

ログイン(SSH)

f:id:tsunokawa:20141118184310p:plain
f:id:tsunokawa:20141118175954p:plain

ポートフォワーディングの設定(2222→22)

ssh centos@localhost -p 2222