summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2023-06-20 22:04:56 +0200
committerHelmut Grohne <helmut@subdivi.de>2023-06-20 22:04:56 +0200
commit75d79763acc9bad36536affbeece33f13dc13af5 (patch)
treeb65164c6f530678a48a1fa6cdc36dcc296e97394
parent652b43980ed5a24dbc9cc9714e419c330d7963ec (diff)
downloaddebvm-75d79763acc9bad36536affbeece33f13dc13af5.tar.gz
debvm-run: add a --skip option
As with debvm-create, this option allows skipping default configuration to let a user override things in their way. Link: https://bugs.debian.org/1036918
-rwxr-xr-xbin/debvm-run65
1 files changed, 54 insertions, 11 deletions
diff --git a/bin/debvm-run b/bin/debvm-run
index ddd6d1f..ead9942 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -35,6 +35,31 @@ Note that B<debvm-create> defaults to installing a cloud kernel if available, so
This option specifies the location of the virtual machine image file.
By default F<rootfs.ext4> in the working directory is used.
+=item B<--skip>=I<task>
+
+Skip a particular task or feature.
+The option may be specified multiple times or list multiple tasks to be skipped by separating them with a comma.
+By default, no tasks are skipped.
+The following tasks may be skipped.
+
+=over 4
+
+=item B<network>
+
+Do not pass configure network card.
+
+=item B<rngdev>
+
+Do not pass a random number generator device.
+
+=item B<rootdev>
+
+A block device for the root filesystem is no longer passed.
+This can be used to customize the block device.
+The label of the root filesystem will still be passed.
+
+=back
+
=item B<-s> I<sshport>, B<--sshport>=I<sshport>
If given, B<qemu> is configured to pass connections to I<127.0.0.1:sshport> to port 22 of the virtual machine.
@@ -96,6 +121,7 @@ set -u
IMAGE=rootfs.ext4
SSHPORT=
GRAPHICAL=
+SKIP=,
nth_arg() {
shift "$1"
@@ -128,6 +154,9 @@ opt_graphical() {
opt_image() {
IMAGE=$1
}
+opt_skip() {
+ SKIP="$SKIP$1,"
+}
opt_sshport() {
SSHPORT=$1
}
@@ -145,12 +174,12 @@ while getopts :gi:s:-: OPTCHAR; do
graphical)
"opt_$OPTARG"
;;
- image|sshport)
+ image|skip|sshport)
test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG"
"opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")"
OPTIND=$((OPTIND+1))
;;
- image=*|sshport=*)
+ image=*|skip=*|sshport=*)
"opt_${OPTARG%%=*}" "${OPTARG#*=}"
;;
*)
@@ -178,6 +207,13 @@ if ! printf '\123\357' | cmp --bytes=2 "$IMAGE" - 1080; then
die "image '$IMAGE' is not in ext4 format"
fi
+check_skip() {
+ case "$SKIP" in
+ *",$1,"*) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
cleanup() {
set +x
test -n "$KERNELTMP" && rm -f "$KERNELTMP"
@@ -266,10 +302,14 @@ set -- \
-m 1G \
-kernel "/proc/self/fd/$KERNELFD" \
-initrd "/proc/self/fd/$INITRDFD" \
- -drive "media=disk,format=raw,discard=unmap,file=$IMAGE,if=virtio,cache=unsafe" \
- -object rng-random,filename=/dev/urandom,id=rng0 \
"$@"
+if ! check_skip rootdev; then
+ set -- \
+ -drive "media=disk,format=raw,discard=unmap,file=$IMAGE,if=virtio,cache=unsafe" \
+ "$@"
+fi
+
# Translate KERNELARCH (a Debian architecture) to a Debian CPU name.
# This utilizes the QEMU Debian package symlink mapping that ensures that
# calling qemu-system-${DEB_HOST_ARCH_CPU} will run the QEMU binary providing
@@ -358,8 +398,11 @@ if test -z "$MAX_SMP" || test "$MAX_SMP" -gt 1; then
set -- -smp "$NPROC" "$@"
fi
fi
-if test -n "$RNG_DEV"; then
- set -- -device "$RNG_DEV" "$@"
+if test -n "$RNG_DEV" && ! check_skip rngdev; then
+ set -- \
+ -device "$RNG_DEV" \
+ -object rng-random,filename=/dev/urandom,id=rng0 \
+ "$@"
fi
if test -z "$GRAPHICAL"; then
@@ -397,11 +440,11 @@ DNSSEARCH=$(dnsdomainname)
if test -n "$DNSSEARCH"; then
NETDEV="$NETDEV,domainname=$DNSSEARCH"
fi
-set -- \
- -append "$KERNEL_CMDLINE" \
- -netdev "$NETDEV" \
- -device "$NIC_DEV" \
- "$@"
+set -- -append "$KERNEL_CMDLINE" "$@"
+
+if ! check_skip network; then
+ set -- -netdev "$NETDEV" -device "$NIC_DEV" "$@"
+fi
echo "+ $QEMU $*" 1>&2
exec "$QEMU" "$@"