From 4f4eaae62f21c8229d0e3779d1b1045cdf818dfe Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 17:08:29 +0100 Subject: Use jessie-or-older hook in latest mmdebstrap --- debvm-create | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'debvm-create') diff --git a/debvm-create b/debvm-create index a8f164d..da1899c 100755 --- a/debvm-create +++ b/debvm-create @@ -205,8 +205,7 @@ if test "$DEBVER" -le 8; then # Use obsolete and expired keys. set -- '--keyring=/usr/share/keyrings/debian-archive-removed-keys.gpg' "$@" set -- --aptopt='Apt::Key::gpgvcommand "/usr/libexec/mmdebstrap/gpgvnoexpkeysig"' "$@" - # chfn does not work, because libpam-runtime.postinst is late setting up /etc/pam.d/common-auth et al, see #1026765 - set -- --extract-hook='chroot "$1" pam-auth-update --package --force' "$@" + set -- --hook-dir=/usr/share/mmdebstrap/hooks/jessie-or-older "$@" fi if test "$DEBVER" -ge 12; then -- cgit v1.2.3 From 99374d17fc20abc1659d46280971376f795babaf Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 23:40:06 +0100 Subject: Fix image name for fsck --- debvm-create | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'debvm-create') diff --git a/debvm-create b/debvm-create index a8f164d..7cc5e31 100755 --- a/debvm-create +++ b/debvm-create @@ -225,4 +225,4 @@ truncate -s "$SIZE" "$IMAGE" /sbin/resize2fs "$IMAGE" /sbin/tune2fs -L debvm -i 0 -O extents,uninit_bg,dir_index,has_journal "$IMAGE" # Must fsck after tune2fs: https://ext4.wiki.kernel.org/index.php/UpgradeToExt4 -/sbin/fsck.ext4 -fDp rootfs.ext2 +/sbin/fsck.ext4 -fDp "$IMAGE" -- cgit v1.2.3 From 98fd7c69af3dd9b2dc56399197dc1e441939012e Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 25 Dec 2022 17:35:22 +0100 Subject: debvm-create: do not truncate images beyond their minimum size --- debvm-create | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'debvm-create') diff --git a/debvm-create b/debvm-create index da1899c..d3631fc 100755 --- a/debvm-create +++ b/debvm-create @@ -220,8 +220,11 @@ set -ex mmdebstrap "$@" -truncate -s "$SIZE" "$IMAGE" -/sbin/resize2fs "$IMAGE" +IMAGESIZE=$(stat -c %s "$IMAGE") +if test "$IMAGESIZE" -lt "$SIZE"; then + truncate -s "$SIZE" "$IMAGE" + /sbin/resize2fs "$IMAGE" +fi /sbin/tune2fs -L debvm -i 0 -O extents,uninit_bg,dir_index,has_journal "$IMAGE" # Must fsck after tune2fs: https://ext4.wiki.kernel.org/index.php/UpgradeToExt4 /sbin/fsck.ext4 -fDp rootfs.ext2 -- cgit v1.2.3 From c42caac69b5d32c6330716a829d33086b04f2b76 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 27 Dec 2022 13:05:00 +0100 Subject: support long options This change extends option parsing of the debvm tools: * Uses posix getopts. No additional dependencies. * Long option are supported. The option value may be a separate argument or separated with =. * Option value may follow short option immediately, e.g. -as390x * Multiple short options may be combined, e.g. -gs 2222 Technical limitation: * Short options are parsed inside a double dash, e.g. -g-image=rootfs.ext4 --- debvm-create | 111 +++++++++++++++++++++++++++++++++++------------------------ debvm-run | 66 +++++++++++++++++++++++++---------- 2 files changed, 113 insertions(+), 64 deletions(-) (limited to 'debvm-create') diff --git a/debvm-create b/debvm-create index d3631fc..5ac62e7 100755 --- a/debvm-create +++ b/debvm-create @@ -15,67 +15,88 @@ SSHKEY= SUITE=unstable VMNAME=testvm +nth_arg() { + shift "$1" + printf "%s" "$1" +} + die() { echo "$*" 1>&2 exit 1 } - usage() { die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-m mirror] [-o output] [-p packages] [-r release] [-s size_in_GB] [-- mmdebstrap options]" } +usage_error() { + echo "error: $*" 1>&2 + usage +} +opt_architecture() { + ARCHITECTURE=$1 +} +opt_hostname() { + VMNAME=$1 +} +opt_mirror() { + MIRROR=$1 +} +opt_sshkey() { + SSHKEY=$1 +} +opt_output() { + IMAGE=$1 +} +opt_package() { + INCLUDE_PACKAGES="$INCLUDE_PACKAGES,$1" +} +opt_release() { + SUITE=$1 +} +opt_size() { + SIZE=$(($1*1024*1024*1024)) +} -while test "$#" -gt 0; do - case "$1" in - -a) - test "$#" -eq 1 && usage - ARCHITECTURE=$2 - shift 2 - ;; - -h) - test "$#" -eq 1 && usage - VMNAME=$2 - shift 2 - ;; - -k) - test "$#" -eq 1 && usage - SSHKEY=$2 - shift 2 - ;; - -m) - test "$#" -eq 1 && usage - MIRROR=$2 - shift 2 - ;; - -o) - test "$#" -eq 1 && usage - IMAGE=$2 - shift 2 - ;; - -p) - test "$#" -eq 1 && usage - INCLUDE_PACKAGES="$INCLUDE_PACKAGES,$2" - shift 2 - ;; - -r) - test "$#" -eq 1 && usage - SUITE=$2 - shift 2 +while getopts :a:h:k:m:o:p:r:s:-: OPTCHAR; do + case "$OPTCHAR" in + a) opt_architecture "$OPTARG" ;; + h) opt_hostname "$OPTARG" ;; + k) opt_sshkey "$OPTARG" ;; + m) opt_mirror "$OPTARG" ;; + o) opt_output "$OPTARG" ;; + p) opt_package "$OPTARG" ;; + r) opt_release "$OPTARG" ;; + s) opt_size "$OPTARG" ;; + -) + case "$OPTARG" in + help) + usage + ;; + architecture|hostname|mirror|output|package|release|size|sshkey) + test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" + "opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")" + OPTIND=$((OPTIND+1)) + ;; + architecture=*|hostname=*|mirror=*|output=*|package=*|release=*|size=*|sshkey=*) + "opt_${OPTARG%%=*}" "${OPTARG#*=}" + ;; + *) + usage_error "unrecognized option --$OPTARG" + ;; + esac ;; - -s) - test "$#" -eq 1 && usage - SIZE=$(($2*1024*1024*1024)) - shift 2 + :) + usage_error "missing argument for -$OPTARG" ;; - --) - shift - break + '?') + usage_error "unrecognized option -$OPTARG" ;; *) - usage + die "internal error while parsing command options, please report a bug" ;; esac done +shift "$((OPTIND - 1))" if test -n "$SSHKEY" && ! test -f "$SSHKEY"; then die "error: ssh keyfile '$SSHKEY' not found" diff --git a/debvm-run b/debvm-run index 972eac6..c800215 100755 --- a/debvm-run +++ b/debvm-run @@ -8,40 +8,68 @@ IMAGE=rootfs.ext2 SSHPORT= GRAPHICAL= +nth_arg() { + shift "$1" + printf "%s" "$1" +} + die() { echo "$*" 1>&2 exit 1 } - usage() { die "usage: $0 [-g] [-i image] [-s sshport] [-- qemu options]" } +usage_error() { + echo "error: $*" 1>&2 + usage +} -while test "$#" -gt 0; do - case "$1" in - -g) - GRAPHICAL=1 - shift - ;; - -i) - test "$#" -eq 1 && usage - IMAGE=$2 - shift 2 +opt_graphical() { + GRAPHICAL=1 +} +opt_image() { + IMAGE=$1 +} +opt_sshport() { + SSHPORT=$1 +} + +while getopts :gi:s:-: OPTCHAR; do + case "$OPTCHAR" in + g) opt_graphical ;; + i) opt_image "$OPTARG" ;; + s) opt_sshport "$OPTARG" ;; + -) + case "$OPTARG" in + help) + usage + ;; + graphical|image|sshport) + test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" + "opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")" + OPTIND=$((OPTIND+1)) + ;; + image=*|sshport=*) + "opt_${OPTARG%%=*}" "${OPTARG#*=}" + ;; + *) + usage_error "unrecognized option --$OPTARG" + ;; + esac ;; - -s) - test "$#" -eq 1 && usage - SSHPORT=$2 - shift 2 + :) + usage_error "missing argument for -$OPTARG" ;; - --) - shift - break + '?') + usage_erro "unrecognized option -$OPTARG" ;; *) - usage + die "internal error while parsing command options, please report a bug" ;; esac done +shift "$((OPTIND - 1))" test -f "$IMAGE" || die "image '$IMAGE' not found" test -s "$IMAGE" || die "image '$IMAGE' is empty" -- cgit v1.2.3 From d43e76f6f4c3f2e6ce196c5544b7ff5653c024c8 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 08:16:25 +0100 Subject: debvm-create: allow easily overriding the kernel image When adding your own kernel image via -p, it will now skip the automatically detected one. --- debvm-create | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'debvm-create') diff --git a/debvm-create b/debvm-create index a903350..c4159e1 100755 --- a/debvm-create +++ b/debvm-create @@ -111,8 +111,6 @@ case "$SUITE" in ;; esac - - KERNEL_SUFFIX=-$ARCHITECTURE case "$ARCHITECTURE" in amd64|arm64) @@ -138,7 +136,13 @@ case "$ARCHITECTURE" in ;; esac -INCLUDE_PACKAGES="$INCLUDE_PACKAGES,linux-image$KERNEL_SUFFIX" +case ",$INCLUDE_PACKAGES," in + *,linux-image-*) + ;; + *) + INCLUDE_PACKAGES="$INCLUDE_PACKAGES,linux-image$KERNEL_SUFFIX" + ;; +esac if test -n "$SSHKEY"; then INCLUDE_PACKAGES="$INCLUDE_PACKAGES,openssh-server" -- cgit v1.2.3 From b666a2909890a7954b103388ec846cac8ce55722 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 10:06:49 +0100 Subject: debvm-create: rename -s option to -z The idea is to eventually add a mechanism for skipping steps similar to how mmdebstrap allows skipping them. --- debvm-create | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'debvm-create') diff --git a/debvm-create b/debvm-create index 2362beb..cddab8f 100755 --- a/debvm-create +++ b/debvm-create @@ -25,7 +25,7 @@ die() { exit 1 } usage() { - die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-m mirror] [-o output] [-p packages] [-r release] [-s size_in_GB] [-- mmdebstrap options]" + die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-m mirror] [-o output] [-p packages] [-r release] [-z size_in_GB] [-- mmdebstrap options]" } usage_error() { echo "error: $*" 1>&2 @@ -57,7 +57,7 @@ opt_size() { SIZE=$(($1*1024*1024*1024)) } -while getopts :a:h:k:m:o:p:r:s:-: OPTCHAR; do +while getopts :a:h:k:m:o:p:r:z:-: OPTCHAR; do case "$OPTCHAR" in a) opt_architecture "$OPTARG" ;; h) opt_hostname "$OPTARG" ;; @@ -66,7 +66,7 @@ while getopts :a:h:k:m:o:p:r:s:-: OPTCHAR; do o) opt_output "$OPTARG" ;; p) opt_package "$OPTARG" ;; r) opt_release "$OPTARG" ;; - s) opt_size "$OPTARG" ;; + z) opt_size "$OPTARG" ;; -) case "$OPTARG" in help) -- cgit v1.2.3