summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2023-06-22 22:02:31 +0200
committerHelmut Grohne <helmut@subdivi.de>2023-06-22 22:02:31 +0200
commit7d1734785df8d922eb5da75111afb4903b90ca23 (patch)
tree025664e723d304c1417f379c82a0e352572424fe
parent6e42dece4f4baac74fe6148a7016c6aece32068e (diff)
parenta2db07766257c53381f198c678c844695ca1e79d (diff)
downloaddebvm-7d1734785df8d922eb5da75111afb4903b90ca23.tar.gz
Merge run-netopt into main
-rwxr-xr-xbin/debvm-run29
1 files changed, 19 insertions, 10 deletions
diff --git a/bin/debvm-run b/bin/debvm-run
index fe38a7a..a4a0890 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -41,6 +41,14 @@ 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<--netopt>=I<option>
+
+B<debvm-run> sets up a user mode network by default.
+It therefore passes a B<-netdev> option to B<qemu>.
+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<-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.
@@ -48,6 +56,8 @@ You can connect to your virtual machine without updating your known hosts like t
ssh -o NoHostAuthenticationForLocalhost=yes -p $sshport root@127.0.0.1
+The option is a shorthand for C<--netopt hostfwd=tcp:127.0.0.1:sshport-:22>.
+
=item B<--> I<qemu options>
All options beyond a double dash are passed to B<qemu>.
@@ -100,9 +110,9 @@ POD2MAN
set -u
IMAGE=rootfs.ext4
-SSHPORT=
GRAPHICAL=
CMDLINE_APPEND=
+NETOPTS=
nth_arg() {
shift "$1"
@@ -138,8 +148,11 @@ opt_graphical() {
opt_image() {
IMAGE=$1
}
+opt_netopt() {
+ NETOPTS="$NETOPTS,$1"
+}
opt_sshport() {
- SSHPORT=$1
+ opt_netopt "hostfwd=tcp:127.0.0.1:$1-:22"
}
while getopts :gi:s:-: OPTCHAR; do
@@ -155,12 +168,12 @@ while getopts :gi:s:-: OPTCHAR; do
graphical)
"opt_$OPTARG"
;;
- append|image|sshport)
+ append|image|netopt|sshport)
test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG"
"opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")"
OPTIND=$((OPTIND+1))
;;
- append=|image=*|sshport=*)
+ append=*|image=*|netopt=*|sshport=*)
"opt_${OPTARG%%=*}" "${OPTARG#*=}"
;;
*)
@@ -254,7 +267,6 @@ case "$IMAGE_LABEL" in
esac
KERNEL_CMDLINE="root=LABEL=$IMAGE_LABEL rw"
-NETDEV="user,id=net0"
KERNELFD=3
while test -h "/proc/self/fd/$KERNELFD"; do
@@ -400,16 +412,13 @@ else
"$@"
fi
-if test -n "$SSHPORT"; then
- NETDEV="$NETDEV,hostfwd=tcp:127.0.0.1:$SSHPORT-:22"
-fi
DNSSEARCH=$(dnsdomainname)
if test -n "$DNSSEARCH"; then
- NETDEV="$NETDEV,domainname=$DNSSEARCH"
+ NETOPTS=",domainname=$DNSSEARCH$NETOPTS"
fi
set -- \
-append "$KERNEL_CMDLINE${CMDLINE_APPEND:+ $CMDLINE_APPEND}" \
- -netdev "$NETDEV" \
+ -netdev "user,id=net0$NETOPTS" \
-device "$NIC_DEV" \
"$@"