From 50d32d2cba87f161ad2da04f1613def74804fd76 Mon Sep 17 00:00:00 2001 From: bill-auger Date: Sun, 22 Dec 2019 21:49:07 -0500 Subject: [PATCH] make configurable default memory size and minimum disk size --- src/pvmboot.sh | 12 +++++++----- src/pvmbootstrap.sh | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/pvmboot.sh b/src/pvmboot.sh index abebdbb..2eddc72 100644 --- a/src/pvmboot.sh +++ b/src/pvmboot.sh @@ -21,13 +21,15 @@ # shellcheck source=/usr/lib/libretools/messages.sh source "$(librelib messages)" +readonly DEF_RAM_MB=1000 + usage() { print "USAGE: %s [-h] [qemu-args ...]" "${0##*/}" prose "Determine the architecture of and boot it using qemu. is assumed to be a valid, raw-formatted parabola virtual machine image, ideally - created using pvmbootstrap. The started instance is assigned 1G of - RAM and one SMP core." + created using pvmbootstrap. The started instance is assigned + ${DEF_RAM_MB}MB of RAM and one SMP core." echo prose "When a graphical desktop environment is available, start the machine normally, otherwise append -nographic to the qemu options. This behavior @@ -129,13 +131,13 @@ pvm_guess_qemu_args() { local kernel_console case "$2" in i386|x86_64|ppc64) - qemu_args+=(-m 1G -hda "$1") + qemu_args+=(-m $DEF_RAM_MB -hda "$1") # unmount the unneeded virtual drive early pvm_umount ;; arm) kernel_console="console=tty0 console=ttyAMA0 " qemu_args+=(-machine virt - -m 1G + -m $DEF_RAM_MB -kernel "$workdir"/vmlinuz-linux-libre -initrd "$workdir"/initramfs-linux-libre.img -append "${kernel_console}rw root=/dev/vda3" @@ -146,7 +148,7 @@ pvm_guess_qemu_args() { riscv64) kernel_console=$( [ -z "$DISPLAY" ] && echo "console=ttyS0 " ) qemu_args+=(-machine virt - -m 1G + -m $DEF_RAM_MB -kernel "$workdir"/bbl -append "${kernel_console}rw root=/dev/vda" -drive "file=${loopdev}p3,format=raw,id=hd0" diff --git a/src/pvmbootstrap.sh b/src/pvmbootstrap.sh index 442d1da..b7e20a8 100644 --- a/src/pvmbootstrap.sh +++ b/src/pvmbootstrap.sh @@ -52,7 +52,7 @@ usage() { echo " -M Specify a different mirror from which to fetch packages" echo " (default: $DEF_MIRROR)" echo " -O Bootstrap an openrc system instead of a systemd one" - echo " -s Set the size (in GB) of the VM image (default: $DEF_IMG_GB)" + echo " -s Set the size (in GB) of the VM image (minimum: $MIN_GB, default: $DEF_IMG_GB)" echo echo "Pre-defined hooks:" echo " ethernet-dhcp: Configure and enable an ethernet device in the virtual" @@ -390,9 +390,10 @@ main() { local shiftlen=$(( OPTIND - 1 )) shift $shiftlen - if [ "$#" -ne 2 ]; then usage >&2; exit "$EXIT_INVALIDARGUMENT"; fi local file="$1" local arch="$2" + [ "$#" -ne 2 ] && usage >&2 && exit "$EXIT_INVALIDARGUMENT" + [ "$ImgSizeGb" -lt $MIN_GB ] && usage >&2 && exit "$EXIT_INVALIDARGUMENT" # determine if the target arch is supported case "$arch" in