You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
#!/bin/bash
|
|
|
|
set -Eeuo pipefail
|
|
|
|
if [[ $# -ne 1 ]]; then
|
|
echo "Usage: $0 <vm-name>"
|
|
exit 1
|
|
fi
|
|
|
|
VM="${1}"
|
|
temp_dir=$(mktemp -d)
|
|
cleanup() {
|
|
rm -rf "$temp_dir"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
mkdir -p "/var/lib/libvirt/images/${VM}"
|
|
cp -a "/usr/local/libvirt/images/${VM}/qcow2/disk.qcow2" "/var/lib/libvirt/images/${VM}/root.qcow2"
|
|
|
|
# Inject the Flightctl configuration file (w/ enrollment certificates) into the VM image
|
|
if [ -f /etc/flightctl/config.yaml ]; then
|
|
yq e '.default-labels += { "type": "virtualmachine" }' /etc/flightctl/config.yaml > "$temp_dir/config.yaml"
|
|
guestfish --add /var/lib/libvirt/images/${VM}/root.qcow2 -m /dev/sda4 <<EOF
|
|
copy-in $temp_dir/config.yaml /ostree/deploy/default/var/lib/flightctl/
|
|
EOF
|
|
fi
|
|
|
|
virt-install --name "${VM}" \
|
|
--autostart \
|
|
--cpu=host-passthrough \
|
|
--vcpus=${DOMAIN_VCPUS} \
|
|
--ram=${DOMAIN_RAM} \
|
|
--os-variant=${DOMAIN_OS_VARIANT} \
|
|
--disk=path=/var/lib/libvirt/images/${VM}/root.qcow2,bus=virtio,format=qcow2,size=${DOMAIN_DISK_SIZE} \
|
|
--console=pty,target_type=virtio \
|
|
--serial=pty \
|
|
--graphics=none \
|
|
--import \
|
|
--network=network=default,mac=${DOMAIN_MAC_ADDRESS} \
|
|
--noautoconsole
|
|
|