diff --git a/run/disk.sh b/run/disk.sh index 92b04f5c..23794da7 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -21,10 +21,11 @@ if [[ ! -f "${DATA}" ]] && [[ -f "$STORAGE/data$DISK_SIZE.img" ]]; then DATA="$STORAGE/data$DISK_SIZE.img" fi +MIN_SIZE=6442450944 DISK_SIZE=$(echo "${DISK_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}") -if (( DATA_SIZE < 6442450944 )); then +if (( DATA_SIZE < MIN_SIZE )); then error "Please increase DISK_SIZE to at least 6 GB." && exit 83 fi @@ -124,9 +125,6 @@ if [ ! -f "${DATA}" ]; then error "Virtual disk does not exist ($DATA)" && exit 88 fi - # Format as BTRFS filesystem - # mkfs.btrfs -q -L data -d single -m dup "${DATA}" > /dev/null - fi # Check the filesize @@ -147,34 +145,60 @@ DISK_OPTS="\ -drive file=${DATA},if=none,id=drive-userdata,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \ -device scsi-hd,bus=hw-userdata.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata,id=userdata0,rotation_rate=${DISK_ROTATION},bootindex=3" +: ${DISK2_SIZE:=''} +EXTRA_SIZE=DISK2_SIZE EXTRA_DISK="/storage2/data.img" -if [ -f "${EXTRA_DISK}" ]; then +if [ -d "$(dirname "${EXTRA_DISK}")" ]; then + + if [ ! -f "${EXTRA_DISK}" ]; then + [ -z "$EXTRA_SIZE" ] && EXTRA_SIZE="16G" + if ! truncate -s "${EXTRA_SIZE}" "${EXTRA_DISK}"; then + error "Could not create the file for the second disk." && exit 53 + fi + fi + if [ -n "$EXTRA_SIZE" ]; then + CUR_SIZE=$(stat -c%s "${EXTRA_DISK}") + DATA_SIZE=$(numfmt --from=iec "${EXTRA_SIZE}") + if [ "$DATA_SIZE" -gt "$CUR_SIZE" ]; then + truncate -s "${EXTRA_SIZE}" "${EXTRA_DISK}" + fi + fi + DISK_OPTS="${DISK_OPTS} \ -device virtio-scsi-pci,id=hw-userdata2,bus=pcie.0,addr=0xd \ -drive file=${EXTRA_DISK},if=none,id=drive-userdata2,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \ -device scsi-hd,bus=hw-userdata2.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata2,id=userdata2,rotation_rate=${DISK_ROTATION},bootindex=4" -else - - [ -d "$(dirname "${EXTRA_DISK}")" ] && error "Disk image ${EXTRA_DISK} does not exist! Please supply an empty file of at least 6 GB." && exit 53 - fi +: ${DISK3_SIZE:=''} +EXTRA_SIZE=DISK3_SIZE EXTRA_DISK="/storage3/data.img" -if [ -f "${EXTRA_DISK}" ]; then +if [ -d "$(dirname "${EXTRA_DISK}")" ]; then + + if [ ! -f "${EXTRA_DISK}" ]; then + [ -z "$EXTRA_SIZE" ] && EXTRA_SIZE="16G" + if ! truncate -s "${EXTRA_SIZE}" "${EXTRA_DISK}"; then + error "Could not create the file for the third disk." && exit 54 + fi + fi + + if [ -n "$EXTRA_SIZE" ]; then + CUR_SIZE=$(stat -c%s "${EXTRA_DISK}") + DATA_SIZE=$(numfmt --from=iec "${EXTRA_SIZE}") + if [ "$DATA_SIZE" -gt "$CUR_SIZE" ]; then + truncate -s "${EXTRA_SIZE}" "${EXTRA_DISK}" + fi + fi DISK_OPTS="${DISK_OPTS} \ -device virtio-scsi-pci,id=hw-userdata3,bus=pcie.0,addr=0xe \ -drive file=${EXTRA_DISK},if=none,id=drive-userdata3,format=raw,cache=${DISK_CACHE},aio=${DISK_IO},discard=${DISK_DISCARD},detect-zeroes=on \ -device scsi-hd,bus=hw-userdata3.0,channel=0,scsi-id=0,lun=0,drive=drive-userdata3,id=userdata3,rotation_rate=${DISK_ROTATION},bootindex=5" -else - - [ -d "$(dirname "${EXTRA_DISK}")" ] && error "Disk image ${EXTRA_DISK} does not exist! Please supply an empty file of at least 6 GB." && exit 54 - fi : ${DEVICE:=''} # Docker variable to passthrough a block device, like /dev/vdc1. diff --git a/run/power.sh b/run/power.sh index fcff1c7a..cfd107e1 100644 --- a/run/power.sh +++ b/run/power.sh @@ -54,8 +54,8 @@ _graceful_shutdown() { sleep 1 - #CNT="$(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT}" - #[[ "${DEBUG}" == [Yy1]* ]] && info "Shutting down, waiting... (${CNT})" + CNT="$(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT}" + [[ "${DEBUG}" == [Yy1]* ]] && info "Shutting down, waiting... (${CNT})" fi diff --git a/run/print.sh b/run/print.sh index 988193c7..93a47cd2 100644 --- a/run/print.sh +++ b/run/print.sh @@ -9,7 +9,7 @@ retry=true while [ "$retry" = true ] do - sleep 2 + sleep 3 # Retrieve IP from guest VM diff --git a/run/serial.sh b/run/serial.sh index f3d9fa1d..02fdb3ae 100644 --- a/run/serial.sh +++ b/run/serial.sh @@ -5,13 +5,10 @@ set -Eeuo pipefail : ${HOST_CPU:=''} : ${HOST_MAC:=''} -: ${HOST_BUILD:=''} : ${HOST_DEBUG:=''} : ${HOST_SERIAL:=''} -: ${GUEST_SERIAL:=''} : ${HOST_MODEL:=''} -: ${HOST_VERSION:=''} -: ${HOST_TIMESTAMP:=''} +: ${GUEST_SERIAL:=''} if [ -z "$HOST_CPU" ]; then HOST_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1' | sed 's# @.*##g' | sed s/"(R)"//g | sed 's/[^[:alnum:] ]\+/ /g' | sed 's/ */ /g') @@ -32,12 +29,9 @@ HOST_ARGS+=("-cpu=${CPU_CORES}") HOST_ARGS+=("-cpu_arch=${HOST_CPU}") [ -n "$HOST_MAC" ] && HOST_ARGS+=("-mac=${HOST_MAC}") -[ -n "$HOST_BUILD" ] && HOST_ARGS+=("-build=${HOST_BUILD}") [ -n "$HOST_MODEL" ] && HOST_ARGS+=("-model=${HOST_MODEL}") [ -n "$HOST_SERIAL" ] && HOST_ARGS+=("-hostsn=${HOST_SERIAL}") [ -n "$GUEST_SERIAL" ] && HOST_ARGS+=("-guestsn=${GUEST_SERIAL}") -[ -n "$HOST_VERSION" ] && HOST_ARGS+=("-version=${HOST_VERSION}") -[ -n "$HOST_TIMESTAMP" ] && HOST_ARGS+=("-ts=${HOST_TIMESTAMP}") if [[ "${HOST_DEBUG}" == [Yy1]* ]]; then set -x