Added fedora guest VM support

This commit is contained in:
2025-08-01 15:42:27 +02:00
parent c75eae71b2
commit 5cce3a0337
4 changed files with 46 additions and 13 deletions

View File

@ -87,6 +87,13 @@ check_host_os()
fi
}
chown_image_permissions(){
if [[ "${DISTRO}" == "fedora" ]]; then
USER_GROUP="$USER:qemu"
else
USER_GROUP="$USER:libvirt-qemu"
fi
}
generate_openbsd_image()
{
@ -102,7 +109,7 @@ generate_openbsd_image()
-b
if ! test -f "${VM_BASE_DIR}/images/${VM_HOSTNAME}.${VM_DISK_EXTENSION}"; then
mv images/${VM_BASE_IMAGE_NAME}.${VM_BASE_IMAGE_EXTENSION} ${VM_BASE_DIR}/images/${VM_HOSTNAME}.${VM_DISK_EXTENSION}
sudo chown -R $USER:libvirt-qemu "${VM_BASE_DIR}/images/${VM_HOSTNAME}.${VM_DISK_EXTENSION}"
sudo chown -R ${USER_GROUP} ${VM_BASE_DIR}/images/${VM_HOSTNAME}.${VM_DISK_EXTENSION}
cd ${CURRENT_PATH}
rm -r openbsd-cloud-image
else
@ -181,16 +188,29 @@ compare_checksum()
VM_BASE_IMAGE_CHECKSUM=$(grep "FreeBSD-14.3-STABLE-amd64-BASIC-CLOUDINIT" "${CHECKSUM_TMP_FOLDER}" | grep "ufs.qcow2.xz" | awk '{print $4}')
fi
else
VM_BASE_IMAGE_CHECKSUM=$(grep "$VM_BASE_IMAGE_NAME.${VM_BASE_IMAGE_EXTENSION}" "${CHECKSUM_TMP_FOLDER}" | awk '{print $1}')
#Fedora things
if [[ "${VM_OS_VARIANT}" == "fedora41" ]]; then
VM_BASE_IMAGE_CHECKSUM=$(grep "${VM_BASE_IMAGE_NAME}.${VM_BASE_IMAGE_EXTENSION}" "${CHECKSUM_TMP_FOLDER}" | grep -v \# | awk '{print $4}')
else
VM_BASE_IMAGE_CHECKSUM=$(grep "${VM_BASE_IMAGE_NAME}.${VM_BASE_IMAGE_EXTENSION}" "${CHECKSUM_TMP_FOLDER}" | awk '{print $1}')
fi
fi
if [[ "${VM_CHECKSUMS_URL}" == *"SHA256"* || "${VM_CHECKSUMS_URL}" == *"sha256"* ]]; then
HASH_CMD="sha256sum"
elif [[ "${VM_CHECKSUMS_URL}" == *"SHA512"* ]]; then
HASH_CMD="sha512sum"
#Fedora things
else
echo "ERROR: Unknown checksum type in URL: $CHECKSUM_URL"
if grep -qi "SHA256" "${CHECKSUM_TMP_FOLDER}"; then
HASH_CMD="sha256sum"
elif grep -qi "SHA512" "${CHECKSUM_TMP_FOLDER}"; then
HASH_CMD="sha512sum"
else
echo "ERROR: Cannot determinate checksum type on ${CHECKSUM_TMP_FOLDER}"
exit 1
fi
fi
BASE_FILE_CHECKSUM=$(${HASH_CMD} ${VM_BASE_IMAGE_LOCATION} | awk '{print $1}')
if [ "${BASE_FILE_CHECKSUM}" = "${VM_BASE_IMAGE_CHECKSUM}" ]; then
echo "Checksum OK: ${BASE_FILE_CHECKSUM}"
@ -327,7 +347,7 @@ vm_download_base_image()
fi
VM_BASE_IMAGE_LOCATION="${VM_BASE_DIR}/${VM_BASE_IMAGES}/${VM_BASE_IMAGE_NAME}.${VM_BASE_IMAGE_EXTENSION}"
if ! test -f "${VM_BASE_IMAGE_LOCATION}"; then
wget --recursive \
wget \
--user-agent="Mozilla/5.0 (X11; Linux x86_64)" \
-O "${VM_BASE_IMAGE_LOCATION}" \
${VM_BASE_IMAGE_URL}
@ -352,7 +372,7 @@ vm_create_guest_image()
qemu-img resize \
"${VM_BASE_DIR}/images/${VM_HOSTNAME}.${VM_DISK_EXTENSION}" \
"${VM_DISK_SIZE}G"
sudo chown -R $USER:libvirt-qemu "${VM_BASE_DIR}/images/${VM_HOSTNAME}.${VM_DISK_EXTENSION}"
sudo chown -R ${USER_GROUP} ${VM_BASE_DIR}/images/${VM_HOSTNAME}.${VM_DISK_EXTENSION}
else
echo "${VM_BASE_DIR}/images/${VM_HOSTNAME}.${VM_DISK_EXTENSION} already exists. Delete VM with "delete" option"
exit 1
@ -506,7 +526,7 @@ vm_guest_install()
eval virt-install $VM_INSTALL_OPTS
virsh dumpxml "${VM_HOSTNAME}" > "${VM_BASE_DIR}/xml/${VM_HOSTNAME}.xml"
clear
#clear
echo "VM ${VM_HOSTNAME} Created!"
echo "NOTE: It may take some time for the virtual machine to be available if it is a BSD flavor. You can check the status of the virtual machine with the following command:"
echo "root pass is(only for BSD flavour): ${VM_USER_PASS}"

View File

@ -73,6 +73,16 @@
} ,
{
"id": 8,
"name": "Fedora CLoud",
"os_type": "GNULinux",
"variant": "fedora41",
"url": " https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2",
"origin_image_name": "Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2",
"md5sum": "https://fedora.mirrorservice.org/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-42-1.1-x86_64-CHECKSUM",
"boot_type": "bios"
} ,
{
"id": 9,
"name": "FreeBSD 14.3 UFS",
"os_type": "BSD",
"variant": "freebsd14.2",
@ -81,7 +91,7 @@
"md5sum": "https://download.freebsd.org/ftp/snapshots/VM-IMAGES/14.3-STABLE/amd64/Latest/CHECKSUM.SHA512"
} ,
{
"id": 9,
"id": 10,
"name": "FreeBSD 14.3 ZFS",
"os_type": "BSD",
"variant": "freebsd14.2",
@ -90,7 +100,7 @@
"md5sum": "https://download.freebsd.org/ftp/snapshots/VM-IMAGES/14.3-STABLE/amd64/Latest/CHECKSUM.SHA512"
} ,
{
"id": 10,
"id": 11,
"name": "OpenBSD 7.7 generic",
"os_type": "BSD",
"variant": "openbsd7.6",

View File

@ -27,7 +27,6 @@ sudo usermod -aG libvirt $(whoami)
sudo usermod -aG kvm $(whoami)
sudo systemctl enable libvirtd
sudo systemctl start libvirtd
newgrp libvirt
mkdir -p "${VM_BASE_DIR}"/{images,xml,init,base,ssh}
cp files/network.xml ${VM_BASE_DIR}/xml/network.xml
@ -35,3 +34,4 @@ sed -i "s/YOURNETWORK/${VM_NETWORK}/g" ${VM_BASE_DIR}/xml/network.xml
virsh net-define ${VM_BASE_DIR}/xml/network.xml
virsh net-autostart ${VM_NETWORK}
virsh net-start ${VM_NETWORK}
newgrp libvirt

View File

@ -99,6 +99,7 @@ case "${ACTION}" in
usage
fi
source env_scripts/common.sh
detect_distro
#Check network type
vm_net_set_bridge_mode
#Check host os for guest debian type
@ -108,6 +109,8 @@ case "${ACTION}" in
show_vm_menu
#Set guest type based on check_host_os
vm_set_guest_type
#set image permissions
chown_image_permissions
if [[ "$VM_OS_TYPE" == "BSD" && "${VM_OS_VARIANT}" == *"openbsd"* ]]; then
generate_openbsd_image
else