VMware環境で、仮想マシンのLinuxサーバーを運用にするあたり、仮想マシンテンプレートを用意して、そこから展開するケースがあると思います。
Windowsの仮想マシンであれば、VMwareの機能にて、テンプレートからの展開後にsysprepが実行されて、仮想マシンの初期化が実行されますが、Linuxの場合は、当然のことながら、Windowsのsysprepは実行されません。
その為、Linuxの仮想マシンテンプレートを初期化して展開したい場合は、Linux5,6の場合は、以下のような設定を実施します。
【Linux5,6の初期化(シーリング)手順】
①仮想マシンにログインします。
②root として以下のコマンドを実行して、システムを再設定するためのフラグを付けます。
# touch /.unconfigured
③以下のコマンドを実行して、ssh ホストキーを削除します。
# rm -rf /etc/ssh/ssh_host_*
④/etc/sysconfig/network に HOSTNAME=localhost.localdomain を設定します。
⑤以下のコマンドを実行して、/etc/udev/rules.d/70-*を削除します。
# rm -rf /etc/udev/rules.d/70-*
⑥/etc/sysconfig/network-scripts/ifcfg-eth* から HWADDR= の行を削除します。
⑦任意で /var/log から全ログを削除し、/root からのログを作成します。
⑧以下のコマンドを実行して、仮想マシンをシャットダウンします。
# poweroff
以上で、次回の仮想マシン起動時に、初期化されて起動しますので、パスワード、ロケールなどの設定を行うことになります。
また、sys-unconfigのコマンドで同様のことが実現できます。しかし、Red Hat Linux7については、上記コマンドが対応しておらず、異なる方法で初期化をする必要があります。
このLinux7の初期化手順は、Linuxの公式サイトにあります。
>>How to seal a rhel 7 linux virtual machine ?
https://access.redhat.com/solutions/2271601
【環境】
Red Hat Enterprise Linux 7
【問題】
How to seal a rhel 7 linux virtual machine ?
【解決策】
・Before a template is created out of a VM, it needs to be sealed.
・Details about how to seal a Red Hat Enterprise Linux VM before creating a template can be found on this customer portal video or refer below steps.
・Login to the virtual machine to be cloned and flag the system for re-configuration by running the following commands as root:
①仮想マシンにログインします。
②以下のコマンドを実行します。事前に、外部に出る設定が必要になります。
# yum install initial-setup
# touch /etc/reconfigSys
③以下のコマンドを実行して、ssh ホストキーを削除します。
# rm -rf /etc/ssh/ssh_host_*
④「/etc/sysconfig/network-scripts/ifcfg-ethx」ファイルからMacアドレスとUUIDを削除します。固定のアドレス設定がある場合も削除します。
DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="AA:BB:CC:DD:EE:FF" <--------削除行
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="954bd22c-f96c-4b59-9445-b39dd86ac8ab" <-------- 削除行
⑤以下のコマンドを実行して、/etc/udev/rules.d/70-*を削除します。
# rm -rf /etc/udev/rules.d/70-persistent-*
⑥ホスト名を以下のように変更します。
# cat /etc/hostname
localhost.localdomain
⑦Graphical、テキストベースのInitial Setupサービスを有効にします。
# systemctl enable initial-setup-graphical.service
or
# systemctl enable initial-setup-text.service
⑧マシンの登録を解除し、電源オフします。
# subscription-manager ungregister
# subscription-manager remove --all
# subscription-manager clean
# poweroff
次回、仮想マシンを起動すると、初期化されて起動されます。Linux7ってまだまだ使い慣れていない人が多いと思いますので、Linux7で仮想マシンテンプレートで初期化で困っている方は、参考にしてみてください。