instant_osd/vm_host/make_cephxx.sh

57 lines
1.4 KiB
Bash
Raw Permalink Normal View History

2024-07-20 18:29:29 +00:00
#!/usr/bin/bash
# VM Creator for a Ceph OSD host
# 2024-07-19, Tim Holloway <timh@mousetech.com>
#
# Customize variables (and script!) as needed:
vm_host='cephxx'
vm_domain='ceph.mousetech.com'
vm_name="01-$vm_host"
vm_memory='4096'
vm_cpus='2'
lvm_data='/dev/vg_data/lv_cephxx'
vm_disk="$vm_name-VDA.qcow2"
vm_mac_address="04:00:00:00:01:08"
#RANDOM for host randomly assigned MAC
ci_user_data='cloud-init.data'
base_disk='/var/lib/libvirt/images/AlmaLinux-9-GenericCloud-9.4-20240507.x86_64.qcow2'
ci_meta_data=$(mktemp)
# virt-install won't process the following as "meta-data":
cat >$ci_meta_data <<EOF
#cloud-config
instance-id: $vm_name
fqdn: $vm_host.$vm_domain
#package_update: true
#package_upgrade: true
#package_reboot_if_required: true
packages:
- centos-release-ceph-pacific
EOF
# - cephadm
cat $ci_user_data >>$ci_meta_data
echo building host $hostname as $vm_name
echo Ensure $vm_disk exists
if [ ! -f "$vm_disk" ]; then
qemu-img create -b $base_disk -F qcow2 -f qcow2 $vm_disk 17G
fi
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_meta_data" \
--osinfo name=almalinux9 \
--disk "$vm_disk" \
--disk "$lvm_data",bus=scsi \
--network mac="$vm_mac_address",bridge=br0 \
--virt-type kvm
#echo "METADATA FILE: $ci_meta_data"
rm $ci_meta_data