diff options
author | Helmut Grohne <helmut@subdivi.de> | 2023-06-21 09:52:17 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2023-06-21 09:52:17 +0200 |
commit | a2db07766257c53381f198c678c844695ca1e79d (patch) | |
tree | e0a58a8c2d52ae34abec5d255f4f2a6b7a32d8c1 /bin | |
parent | 652b43980ed5a24dbc9cc9714e419c330d7963ec (diff) | |
download | debvm-a2db07766257c53381f198c678c844695ca1e79d.tar.gz |
debvm-run: add a --netopt option to customize the -netdev
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/debvm-run | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/bin/debvm-run b/bin/debvm-run index ddd6d1f..f2b4587 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -35,6 +35,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. @@ -42,6 +50,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>. @@ -94,8 +104,8 @@ POD2MAN set -u IMAGE=rootfs.ext4 -SSHPORT= GRAPHICAL= +NETOPTS= nth_arg() { shift "$1" @@ -128,8 +138,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 @@ -145,12 +158,12 @@ while getopts :gi:s:-: OPTCHAR; do graphical) "opt_$OPTARG" ;; - image|sshport) + image|netopt|sshport) test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" "opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")" OPTIND=$((OPTIND+1)) ;; - image=*|sshport=*) + image=*|netopt=*|sshport=*) "opt_${OPTARG%%=*}" "${OPTARG#*=}" ;; *) @@ -244,7 +257,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 @@ -390,16 +402,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" \ - -netdev "$NETDEV" \ + -netdev "user,id=net0$NETOPTS" \ -device "$NIC_DEV" \ "$@" |