Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Configure sizes for multiple disks #371

Merged
merged 5 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions run/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions run/power.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion run/print.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ retry=true
while [ "$retry" = true ]
do

sleep 2
sleep 3

# Retrieve IP from guest VM

Expand Down
8 changes: 1 addition & 7 deletions run/serial.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down