summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2023-06-22 22:50:26 +0200
committerHelmut Grohne <helmut@subdivi.de>2023-06-22 22:50:26 +0200
commitdb209c40839aedf6d6de478c5d798df07211b636 (patch)
treec1277c8e0a278f4120263b374874d01c9c2518ba
parentf9f5d74144b11ebb6df156549365453ea426e379 (diff)
parent94f7ace2c486b0daac410becd57ab6e36be5b1c2 (diff)
downloaddebvm-db209c40839aedf6d6de478c5d798df07211b636.tar.gz
Merge run-skip into main
-rwxr-xr-xbin/debvm-run94
1 files changed, 80 insertions, 14 deletions
diff --git a/bin/debvm-run b/bin/debvm-run
index 1019ac7..bba0c15 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -49,6 +49,40 @@ Using this option, you can customize the value of that B<-netdev> option.
For instance, you can set up additional port forwards by passing e.g. C<--netopt hostfwd=:127.0.0.1:8080-:80>.
It can be used multiple times.
+=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<root>
+
+Skip all of the following tasks matching C<root/*>.
+If either of these is present, the VM will not boot unless a suitable replacement is added in another way.
+
+=item B<root/cmd>
+
+Since B<debvm-run> uses B<qemu> as bootloader it normally passes the label of the root block device via the kernel command line.
+This passing can be inhibited to supply a different location.
+
+=item B<root/dev>
+
+A block device for the root filesystem is no longer passed.
+This can be used to customize the block device.
+
+=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.
@@ -113,6 +147,7 @@ IMAGE=rootfs.ext4
GRAPHICAL=
CMDLINE_APPEND=
NETOPTS=
+SKIP=,
SSHPORT=
nth_arg() {
@@ -152,6 +187,9 @@ opt_image() {
opt_netopt() {
NETOPTS="$NETOPTS,$1"
}
+opt_skip() {
+ SKIP="$SKIP$1,"
+}
opt_sshport() {
SSHPORT=$1
}
@@ -169,12 +207,12 @@ while getopts :gi:s:-: OPTCHAR; do
graphical)
"opt_$OPTARG"
;;
- append|image|netopt|sshport)
+ append|image|netopt|skip|sshport)
test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG"
"opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")"
OPTIND=$((OPTIND+1))
;;
- append=*|image=*|netopt=*|sshport=*)
+ append=*|image=*|netopt=*|skip=*|sshport=*)
"opt_${OPTARG%%=*}" "${OPTARG#*=}"
;;
*)
@@ -206,6 +244,18 @@ if ! printf '\123\357' | cmp --bytes=2 "$IMAGE" - 1080; then
die "image '$IMAGE' is not in ext4 format"
fi
+check_skip() {
+ while :; do
+ case "$SKIP" in
+ *",$1,"*) return 0 ;;
+ esac
+ if test "$1" = "${1%/*}"; then
+ return 1
+ fi
+ set -- "${1%/*}"
+ done
+}
+
cleanup() {
set +x
test -n "$KERNELTMP" && rm -f "$KERNELTMP"
@@ -271,7 +321,10 @@ case "$IMAGE_LABEL" in
;;
esac
-KERNEL_CMDLINE="root=LABEL=$IMAGE_LABEL rw"
+KERNEL_CMDLINE=
+if ! check_skip root/cmd; then
+ KERNEL_CMDLINE="root=LABEL=$IMAGE_LABEL rw"
+fi
KERNELFD=3
while test -h "/proc/self/fd/$KERNELFD"; do
@@ -293,10 +346,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 root/dev; 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
@@ -385,19 +442,22 @@ 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
set -- -nographic "$@"
case "$KERNELARCH" in
amd64|i386)
- KERNEL_CMDLINE="$KERNEL_CMDLINE console=ttyS0"
+ KERNEL_CMDLINE="${KERNEL_CMDLINE:+"$KERNEL_CMDLINE "}console=ttyS0"
;;
esac
if test -t 0 && test -t 1 && test -n "$TERM"; then
- KERNEL_CMDLINE="$KERNEL_CMDLINE TERM=$TERM"
+ KERNEL_CMDLINE="${KERNEL_CMDLINE:+"$KERNEL_CMDLINE "}TERM=$TERM"
fi
else
case "$KERNELARCH" in
@@ -421,11 +481,17 @@ DNSSEARCH=$(dnsdomainname)
if test -n "$DNSSEARCH"; then
NETOPTS=",domainname=$DNSSEARCH$NETOPTS"
fi
-set -- \
- -append "$KERNEL_CMDLINE${CMDLINE_APPEND:+ $CMDLINE_APPEND}" \
- -netdev "user,id=net0$NETOPTS" \
- -device "$NIC_DEV" \
- "$@"
+
+if test -n "$CMDLINE_APPEND"; then
+ KERNEL_CMDLINE="${KERNEL_CMDLINE:+"$KERNEL_CMDLINE "}$CMDLINE_APPEND"
+fi
+if test -n "$KERNEL_CMDLINE"; then
+ set -- -append "$KERNEL_CMDLINE" "$@"
+fi
+
+if ! check_skip network; then
+ set -- -netdev "user,id=net0$NETOPTS" -device "$NIC_DEV" "$@"
+fi
echo "+ $QEMU $*" 1>&2
exec "$QEMU" "$@"