公式サイトのリファレンスを参考にする
https://wiki.almalinux.org/cloud/Generic-cloud-on-local.html#almalinux-guest-os-support
OpenStackAnterope&KVM環境で作っている。
今回はOpenStackにImage登録したいので、リファレンスの通りのスナップショットは取得していない。
cloud-initは、もともとAWSのEC2で利用されているもので、インストール時のGUIポチポチを自動化するというもの。
最初はAWSのみで使われていたようだが、このcloud-initが広く使われるようになったみたい。
オンプレミスというか、クラウド環境でなくても使える。
イメージダウンロードする。cloud-init用のイメージがあるのでそれをダウンロードする。
curl -O -s https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2 cp AlmaLinux-9-GenericCloud-latest.x86_64.qcow2 /var/kvm/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2
almalinuxがvirt-managerに対応しているか確認する。
osinfo-query os | grep almalinux
イメージを作るためにログインするユーザーを定義する。
cat <<EOF> ci_user_data_ssh_auth_pass_pubkey
#cloud-config
ssh_pwauth: true # sshd service will be configured to accept password authentication method
password: password # Set a password for almalinux
chpasswd:
expire: false # Don't ask for password reset after the first log-in
ssh_authorized_keys: # Add your ssh public key for publickey authentication
- ssh-ed25519 AAAAB3NzaC1yc2EAAAABIwAAAQEA3I7VUf2l5gSn5uavROsc5HRDpZ turquoisekodkod@almalinux.example
- ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAGEA3FSyQwBI6Z+nCSjUU sapphirecaracal@almalinux.example
EOF
osinfo_db_version='20230719' # Replace with the latest version curl -O https://releases.pagure.org/libosinfo/osinfo-db-"$osinfo_db_version".tar.xz # Download sudo osinfo-db-import --local osinfo-db-"$osinfo_db_version".tar.xz # Install
virt-installするシェルスクリプトを作る
cat <<EOF> install.sh
#!/usr/bin/env bash
vm_name='almalinux92'
vm_memory='2048'
vm_cpus='2'
vm_disk='/var/kvm/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2'
ci_user_data='ci_user_data_ssh_auth_pass_pubkey'
virt-install \
--connect qemu:///system \
--name "$vm_name" \
--memory "$vm_memory" \
--machine q35 \
--vcpus "$vm_cpus" \
--cpu host-passthrough \
--import \
--cloud-init user-data="$ci_user_data" \
--osinfo name=almalinux9 \
--disk "$vm_disk" \
--virt-type kvm
EOF
シェルスクリプトを実行
sh -x install.sh
qemu-img create -f qcow2 -b AlmaLinux-9-GenericCloud-latest.x86_64.qcow2 -F qcow2 wiki_example_almalinux92_snapshot.qcow2 20G
AlmaLinux内での操作
# rootになる
sudo su -
# 必要パッケージをインストール
dnf -y install cloud-init openssh-server vim bash-completion net-tools
# cloud-initファイルの編集
vim /etc/cloud/cloud.cfg
ssh_pwauth: true # sshパスワード認証を有効化
system_info:
default_user:
name: almalinux # デフォルトユーザーはalmalinux
lock_passwd: false # パスワードロックはかからないようにする
# パスワードを必要であれば変更しておく
passwd almalinux
# Macアドレスを新調してほしいのでネットワークデバイスを削除
nmcli device
nmcli connection delete eth0
# cloud-initとsshdを有効化
systemctl enable cloud-init sshd
# シャットダウン
shutdown -h now
OpenStackに登録する場合のコマンド。
openstack image create "AlmaLinux92" --file /var/kvm/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2 --disk-format qcow2 --container-format bare --public --insecure
