4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VirtualBox で cloud-init を使う

Last updated at Posted at 2016-10-09

VirtualBox で cloud-init を使う

CentOS などの cloud image を VirtualBox から利用する際に cloud-init を使ってログインパスワードの設定などを行う方法をまとめる。1

イメージファイルを vdi 形式に変換

OpenStack 等で動作する仮想マシンイメージは http://cloud.centos.org/centos/7/images/ から入手できる。例えば以下のコマンドで raw 形式のイメージファイルを VirtualBox の仮想ディスクの vdi 形式に変換する。

VBoxManage convertdd CentOS-7-x86_64-GenericCloud-1608.raw CentOS-7-1608.vdi

cloud-init の設定内容を iso イメージにする

以下の内容で meta-data, user-data の2つのファイルを作成

meta-data
instance-id: host0001
local-hostname: host0001.example.com
user-data
#cloud-config
password: 3Ggpx4Qiy
ssh_pwauth: True
chpasswd: { expire: False }

ssh_authorized_keys:
-  public key の内容をここに書く

以下のコマンドにより、上記の2ファイルで構成される iso イメージを作成

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

VirtualBox の Storage 設定で iso イメージを指定

VirtualBox で新規に仮想マシンを作成後、 "Machine" > "Settings..." のメニューから "Storage" をクリックし、 Optical Drive として iso イメージファイルを設定する。

Untitled.png

これで CentOS の cloud image を VirtualBox で利用できるようになる。

OpenStack 環境への移行

パッケージ追加・設定などを行ってカスタマイズした仮想マシンイメージを OpenStack 等で利用するには、 qemu-img コマンドで vdi 形式から直接 qcow2 形式に変換すればよい。

qemu-img convert -f vdi -O qcow2 CentOS-7-1608.vdi CentOS-7-1608.qcow2
  1. 多くの cloud image はデフォルトで SSH パスワード認証を無効化しているため、 VirtualBox でイメージを起動してもログインすることができません。

4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?