add cdrom option

This commit is contained in:
primardj 2024-03-03 18:26:33 +00:00
parent bd5eb053a6
commit 654e156170

View file

@ -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=<loc_disk>" >&2
fi
;;
*)
echo "commande $2 inconnue" >&2