From febd3b76d391271c0cef0499b01ad3120166ad25 Mon Sep 17 00:00:00 2001 From: victor Date: Wed, 27 Aug 2025 16:13:45 +0200 Subject: [PATCH] Added Debian Trixie as new Debian stable guest. Fixed host only things on scripts --- README.md | 2 ++ env_scripts/functions.sh | 10 ++++++---- files/os_options.json | 8 ++++---- vm_manage.sh | 10 +++++----- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 040cb7b..6dbd6d8 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ VM_NETWORK_HOSTONLY="host-only" VM_USERNAME="user" ``` +You can create a VM with isolated network but an extra interface with NAT network if added, because when guest is initialized, it get updated and some packages are installed (dependend on linux-user-metadata). You can delete NAT interface after VM guest is initialized. + ### AppArmor exception (if needed) If AppArmor is blocking libvirtd, disable the profile temporarily: diff --git a/env_scripts/functions.sh b/env_scripts/functions.sh index 9a6fc85..875df71 100644 --- a/env_scripts/functions.sh +++ b/env_scripts/functions.sh @@ -231,7 +231,7 @@ vm_list() vm_net_get_mac() { local VM=$1 - MAC_VM=$(virsh domiflist "$VM" | awk '{ print $5 }' | tail -2 | head -1) + MAC_VM=$(virsh domiflist "${VM}" | grep "${VM_NETWORK_NAT}"| awk '{ print $5 }' | tail -2 | head -1) echo $MAC_VM } ## Get VM ip (only on NAT) @@ -295,9 +295,7 @@ vm_net_bridge_set_ip() vm_net_set_network_type() { - if [[ "${VM_NETWORK_TYPE}" == "isolated" ]]; then - LIBVIRT_NET_OPTION="network=${VM_NETWORK_HOST_ONLY},model=${LIBVIRT_NET_MODEL}" - elif [[ "${VM_NETWORK_TYPE}" == "bridge" ]]; then + if [[ "${VM_NETWORK_TYPE}" == "bridge" ]]; then LIBVIRT_NET_OPTION="model=virtio,bridge=${VM_BRIDGE_INT}" fi } @@ -523,6 +521,10 @@ vm_guest_install() VM_INSTALL_OPTS="${VM_INSTALL_OPTS} --os-variant=${VM_OS_VARIANT}" VM_INSTALL_OPTS="${VM_INSTALL_OPTS} --disk ${VM_BASE_DIR}/images/${VM_HOSTNAME}.img,device=disk,bus=virtio" VM_INSTALL_OPTS="${VM_INSTALL_OPTS} --network ${LIBVIRT_NET_OPTION}" + if [[ "${VM_NETWORK_TYPE}" == "isolated" ]]; then + LIBVIRT_NET_OPTION="network=${VM_NETWORK_HOSTONLY},model=${LIBVIRT_NET_MODEL}" + VM_INSTALL_OPTS="${VM_INSTALL_OPTS} --network ${LIBVIRT_NET_OPTION}" + fi VM_INSTALL_OPTS="${VM_INSTALL_OPTS} --autostart" VM_INSTALL_OPTS="${VM_INSTALL_OPTS} --import --noautoconsole" VM_INSTALL_OPTS="${VM_INSTALL_OPTS} --cloud-init user-data=${VM_BASE_DIR}/init/${VM_HOSTNAME}-user-data,meta-data=$VM_BASE_DIR/init/${VM_HOSTNAME}-meta-data" diff --git a/files/os_options.json b/files/os_options.json index da0bc2c..96c36f9 100644 --- a/files/os_options.json +++ b/files/os_options.json @@ -2,12 +2,12 @@ "os_variants": [ { "id": 1, - "name": "Debian 12", + "name": "Debian Stable", "variant": "debian13", "os_type": "GNULinux", - "url": "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2", - "origin_image_name": "debian-12-generic-amd64.qcow2", - "md5sum": "https://cdimage.debian.org/images/cloud/bookworm/latest/SHA512SUMS", + "url": "http://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-amd64.qcow2", + "origin_image_name": "debian-13-generic-amd64.qcow2", + "md5sum": "http://cloud.debian.org/images/cloud/trixie/latest/SHA512SUMS", "boot_type": "bios" }, { diff --git a/vm_manage.sh b/vm_manage.sh index 208e53b..03ad554 100755 --- a/vm_manage.sh +++ b/vm_manage.sh @@ -60,8 +60,8 @@ case "${ACTION}" in # Parse options for create command VERBOSE=false NAME_SET=false - - while getopts ":hn:b:H:r:c:s:v" opt; do + source env_scripts/common.sh + while getopts ":hn:b:Hr:c:s:v" opt; do case "${opt}" in h) usage @@ -72,10 +72,10 @@ case "${ACTION}" in ;; b) VM_BRIDGE_INT="${OPTARG}" - VM_NETWORK_TYPE_DEFAULT="bridge" + VM_NETWORK_TYPE="bridge" ;; H) - VM_NETWORK_TYPE_DEFAULT="isolated" + VM_NETWORK_TYPE="isolated" ;; r) VM_MEM_SIZE="${OPTARG}" @@ -105,7 +105,7 @@ case "${ACTION}" in echo "Error: The -n option is required for create action." >&2 usage fi - source env_scripts/common.sh + detect_distro #Check network type vm_net_set_network_type