From 654e1561707b0da0304022a93f8b1597672f7764 Mon Sep 17 00:00:00 2001 From: primardj Date: Sun, 3 Mar 2024 18:26:33 +0000 Subject: [PATCH] add cdrom option --- vm-start.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/vm-start.sh b/vm-start.sh index 6551922..f7f2750 100755 --- a/vm-start.sh +++ b/vm-start.sh @@ -18,6 +18,7 @@ PARAMETTER available COMMAND available init Create the conf file in conf/NAME_var.sh + init_cdrom init a RO image/cdrom. The network will have to be set later in the conf file. NO EUFI start Start the virtual machine using the variabes in conf/NAME_var.sh start-backup Start the virtual machine using the backup volume if it exists. create Create the virtual machine using the conf in conf/NAME_var.sh @@ -105,6 +106,24 @@ EOF } +INIT_cdrom() { + echo "Init for a cdrom." + echo "Init was already called." + + # necessite au moins l'addresse de l'image en tant que $1 + + VMROM="$(basename $1)" + + if [ ! -f "${MAIN_LOCATION}/${LOCATION}/${VMROM}" ] + then + echo "create directory ${MAIN_LOCATION}/${LOCATION}/" + mkdir -p "${MAIN_LOCATION}/${LOCATION}/" + cp $1 "${MAIN_LOCATION}/${LOCATION}/${VMROM}" + fi + echo "CDROM_DISK=\"${VMROM}\"" >> "conf/$NAME-vm_var.sh" + echo "Done" +} + start_the_vm() { if [ "${network}" == "" ] @@ -113,13 +132,20 @@ start_the_vm() { -net user${FORWARD},hostname=${VMHOSTNAME}" fi + if [ "${CDROM_DISK}" != "" ] + then + DRIVE="-drive file=${MAIN_LOCATION}/${LOCATION}/${CDROM_DISK},index=2,id=maindrive,media=cdrom" + else + DRIVE="-drive file=${MAIN_LOCATION}/${LOCATION}/${VMDRIVE},index=2,id=maindrive,media=disk" + fi + qemu-system-x86_64 \ -enable-kvm \ -cpu host \ -smp "$NPROC" \ $network \ -m "$MEMORY" \ - -drive file="${MAIN_LOCATION}/${LOCATION}/${VMDRIVE}",index=2,id=maindrive,media=disk \ + $DRIVE \ $OPTION } @@ -228,9 +254,13 @@ set_net() { echo "error, no mac set" exit 1 fi + if [ "${driver}" == "" ] + then + driver="virtio-net" + fi network="${network} \ -netdev bridge,id=${1#*:},br=${1#*:} \ - -device virtio-net,netdev=${1#*:},mac=${mac}" + -device ${driver},netdev=${1#*:},mac=${mac}" ;; "none") echo "no interface will be connected." @@ -370,7 +400,19 @@ case "$2" in ;; "init") echo "Init volume $1" - INIT "$1" + #INIT "$1" + echo "Error, Normally, already called before." + ;; + "init_cdrom") + echo "Init cdrom $1" + if [ ! "${INSTALLATION_DISK_LOCATION}" == "" ] + then + echo "using image disk ${INSTALLATION_DISK_LOCATION}" + INIT_cdrom "${INSTALLATION_DISK_LOCATION}" + else + echo "Error, no image defined." >&2 + echo "use --create_disk=" >&2 + fi ;; *) echo "commande $2 inconnue" >&2