Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ For non-root usage, add your user to the `libvirt` and `kvm` groups:
sudo usermod -aG libvirt,kvm $USER
```

> [!IMPORTANT]
> The OS distro names are only as current as the version of `osinfo-db`
> installed in your environment. If the name is not found, eg, `rocky10`,
> then you need to edit the template file and change the OSVARIANT to
> `unknown` in order to install the desired OS version.

---

## **Configuration**
Expand Down
41 changes: 38 additions & 3 deletions bin/launch-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,57 @@ vm-setup() {
exit 1
fi

virt-install \
virt-install --import \
--name "${VMNAME}" \
--memory "${VMEM}" \
--vcpus "${VCPUS}" \
--cpu host-model \
--disk "vol=${VMPOOL}/${VMVOL},bus=virtio,format=qcow2" \
--os-variant "${OSVARIANT}" \
--network "network=${NETWORK},model=virtio" \
--virt-type kvm \
--import \
--cloud-init "user-data=${CLOUD_CONFIG_FILE}" \
--wait \
--noautoconsole \
--console "${CONSOLE:-}" \
--video none \
--qemu-commandline="-smbios type=1,serial=ds=nocloud;h=${VMNAME}.${DOMAIN}"
}

get-vminfo() {
IP=${IP:-}
timeout=60 # seconds
if [[ ! -n "$IP" ]]; then
echo "Waiting for $VMNAME IP address..."
for ((i = 0; i < timeout; i++)); do
DOM=$(virsh -q domifaddr "$VMNAME")
read -ra arr <<<"$DOM"
if [[ -n "${arr[@]}" ]]; then
IP="${arr[3]%/*}"
fi

if [[ -n "$IP" ]]; then
break
fi
sleep 1
done
fi

if [[ -n "$IP" ]]; then
echo ""
echo "SSH to ${VMNAME}:"
echo " ssh ${IP}"
echo " ssh ubuntu@${IP}"
echo ""
echo "Checking for ${IP} in known_hosts file"
grep -q ${IP} ${HOME}/.ssh/known_hosts &&
echo "Found entry for ${IP}. Removing" &&
(sed --in-place "/^${IP}/d" ~/.ssh/known_hosts) ||
echo "No entries found for ${IP}"
else
echo "Timed out waiting for DHCP lease"
fi
}

# -------------------------------------------------------------------------
# Main Execution Flow
# -------------------------------------------------------------------------
Expand All @@ -229,3 +263,4 @@ import-base-volume
clone-base
resize-clone
vm-setup
get-vminfo
5 changes: 3 additions & 2 deletions templates/rockylinux10.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
URL=https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2
SOURCE=source-rockylinux10.img
OSVARIANT=rockylinux10
SOURCE=source-rocky10.img
OSVARIANT=rocky10
#OSVARIANT=rocky-unknown
CONSOLE="pty,target_type=virtio"
4 changes: 2 additions & 2 deletions templates/rockylinux9.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
URL=https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2
SOURCE=source-rockylinux9.img
OSVARIANT=rockylinux9
SOURCE=source-rocky9.img
OSVARIANT=rocky9
CONSOLE="pty,target_type=virtio"
1 change: 1 addition & 0 deletions templates/ubuntu26.04.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
URL=https://cloud-images.ubuntu.com/resolute/current/resolute-server-cloudimg-amd64.img
SOURCE=source-ubuntu26.04.img
OSVARIANT=ubuntu26.04
#OSVARIANT=unknown
CONSOLE="pty,target_type=virtio"