From 75d79763acc9bad36536affbeece33f13dc13af5 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 20 Jun 2023 22:04:56 +0200 Subject: 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 --- bin/debvm-run | 65 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 11 deletions(-) (limited to 'bin') 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 defaults to installing a cloud kernel if available, so This option specifies the location of the virtual machine image file. By default F in the working directory is used. +=item B<--skip>=I + +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 + +Do not pass configure network card. + +=item B + +Do not pass a random number generator device. + +=item B + +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, B<--sshport>=I If given, B 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" "$@" -- cgit v1.2.3 From 94f7ace2c486b0daac410becd57ab6e36be5b1c2 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 22 Jun 2023 21:57:25 +0200 Subject: debvm-run: expand the rootdev skip --- bin/debvm-run | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'bin') diff --git a/bin/debvm-run b/bin/debvm-run index ead9942..d8ff174 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -52,11 +52,20 @@ Do not pass configure network card. Do not pass a random number generator device. -=item B +=item B + +Skip all of the following tasks matching C. +If either of these is present, the VM will not boot unless a suitable replacement is added in another way. + +=item B + +Since B uses B 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 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 @@ -208,10 +217,15 @@ if ! printf '\123\357' | cmp --bytes=2 "$IMAGE" - 1080; then fi check_skip() { - case "$SKIP" in - *",$1,"*) return 0 ;; - *) return 1 ;; - esac + while :; do + case "$SKIP" in + *",$1,"*) return 0 ;; + esac + if test "$1" = "${1%/*}"; then + return 1 + fi + set -- "${1%/*}" + done } cleanup() { @@ -279,7 +293,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 NETDEV="user,id=net0" KERNELFD=3 @@ -304,7 +321,7 @@ set -- \ -initrd "/proc/self/fd/$INITRDFD" \ "$@" -if ! check_skip rootdev; then +if ! check_skip root/dev; then set -- \ -drive "media=disk,format=raw,discard=unmap,file=$IMAGE,if=virtio,cache=unsafe" \ "$@" @@ -409,11 +426,11 @@ 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 @@ -440,7 +457,9 @@ DNSSEARCH=$(dnsdomainname) if test -n "$DNSSEARCH"; then NETDEV="$NETDEV,domainname=$DNSSEARCH" fi -set -- -append "$KERNEL_CMDLINE" "$@" +if test -n "$KERNEL_CMDLINE"; then + set -- -append "$KERNEL_CMDLINE" "$@" +fi if ! check_skip network; then set -- -netdev "$NETDEV" -device "$NIC_DEV" "$@" -- cgit v1.2.3