この記事はopenSUSE Advent Calendar 2023 14日目の記事です。
openSUSE のダウンロードサイトに存在する Minimal Virtual Machine の中で、Cloud image
というものが存在します。
Cloud image
OpenstakやKVMのcloud-init環境で使用可能な qcow2形式のイメージ
説明にもある通り、cloud-image は cloud-initを使用して自動で初期設定を行うことができます。
cloud-init は、システムの起動時にクラウドインスタンスの初期化を自動化するソフトウェアパッケージです。
cloud-init は、さまざまなタスクを実行するように設定できます。 - cloud-init は、システムの起動時にクラウドインスタンスの初期化を自動化するソフトウェアパッケージです。cloud-init は、さまざまなタスクを実行するように設定できます。
第2章 cloud-init の概要 Red Hat Enterprise Linux 9 | Red Hat Customer Portal
cloud-initはゲストマシンの初期設定を自動化するもので、Openstack上での仮想マシン配備時や
AzureやAWS等のパブリッククラウド上でのゲスト配備でも使用されています。
cloud-initは様々な方法でゲストに基盤側データ(初期情報)を流し込むことが出来るのですが、
今回は基盤側データをISOイメージにまとめてゲストに見せる NoCloud
を使用してゲストをデプロイしたいと思います。
まず、最小限の基盤側データを作成します。
今回はクラウドイメージの使用に最低限必要な、以下の基盤側データのみを作成します。
* meta-deta
* user-data
halni@SUSE-MZ32:~/cloudinit> cat meta-data instance-id: SUSE-cloud01 local-hostname: SUSE-cloud01
halni@SUSE-MZ32:~/cloudinit> cat user-data #cloud-config password: mypassword chpasswd: {expire: False} ssh_pwauth: True ssh_authorized_keys: - ssh-rsa XXXX...(略)...XXXX= halni@SUSE-MZ32 haruka@SUSE-MZ32:~/cloudinit>
作成したデータを、基盤側メタデータとして isoイメージにまとめます。
mkisofs -r -J -V cidata -o cloud-init.iso user-data meta-data ...(その他データ)...
halni@SUSE-MZ32:~/cloudinit> mkisofs -r -J -V cidata -o cloud-init.iso user-data meta-data Setting input-charset to 'UTF-8' from locale. Total translation table size: 0 Total rockridge attributes bytes: 363 Total directory bytes: 0 Path table size(bytes): 10 Max brk space used 0 183 extents written (0 MB) halni@SUSE-MZ32:~/cloudinit> ls cloud-init.iso meta-data user-data
作成したisoファイルをゲストにアタッチして起動します。
ユーザー名は opensuse
でログイン可能です。
halni@SUSE-MZ32:~/cloudinit> ssh opensuse@192.168.1.151 Have a lot of fun... opensuse@SUSE-cloud01:~> ★ 公開鍵を登録していない環境からは、user-data内で設定したパスワードでログイン可能です。 halni@SUSE-RX2530M4:~> ssh opensuse@192.168.1.151 The authenticity of host '192.168.1.151 (192.168.1.151)' can't be established. ECDSA key fingerprint is SHA256:iunEjQ0Ov6uOGfKfo+CdVOt36RbddBGhSibLh4EHY40. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.1.151' (ECDSA) to the list of known hosts. Password: Last login: Tue Dec 5 12:50:08 2023 from 192.168.1.33 Have a lot of fun... opensuse@SUSE-cloud01:~>