summaryrefslogtreecommitdiff
path: root/bin/debvm-run
diff options
context:
space:
mode:
Diffstat (limited to 'bin/debvm-run')
-rwxr-xr-xbin/debvm-run46
1 files changed, 37 insertions, 9 deletions
diff --git a/bin/debvm-run b/bin/debvm-run
index d8ff174..bba0c15 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -24,6 +24,12 @@ A net interface configured for user mode is added automatically.
=over 8
+=item B<--append>=I<cmdline>
+
+While the kernel command line can be modified by passing B<-append> to B<qemu> directly, doing that always replaces the entire command line and thus removes important values passed by B<debvm-run>.
+This variant instead appends given command line arguments to the automatic ones.
+Repeated use also causes appending rather than replacement.
+
=item B<-g>, B<--graphical>
By default, the option B<-nographic> is passed to B<qemu> and one interacts with the serial console of the machine.
@@ -35,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<--skip>=I<task>
Skip a particular task or feature.
@@ -76,6 +90,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>.
@@ -128,9 +144,11 @@ POD2MAN
set -u
IMAGE=rootfs.ext4
-SSHPORT=
GRAPHICAL=
+CMDLINE_APPEND=
+NETOPTS=
SKIP=,
+SSHPORT=
nth_arg() {
shift "$1"
@@ -157,12 +175,18 @@ usage_error() {
usage
}
+opt_append() {
+ CMDLINE_APPEND="${CMDLINE_APPEND:+$CMDLINE_APPEND }$1"
+}
opt_graphical() {
GRAPHICAL=1
}
opt_image() {
IMAGE=$1
}
+opt_netopt() {
+ NETOPTS="$NETOPTS,$1"
+}
opt_skip() {
SKIP="$SKIP$1,"
}
@@ -183,12 +207,12 @@ while getopts :gi:s:-: OPTCHAR; do
graphical)
"opt_$OPTARG"
;;
- image|skip|sshport)
+ append|image|netopt|skip|sshport)
test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG"
"opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")"
OPTIND=$((OPTIND+1))
;;
- image=*|skip=*|sshport=*)
+ append=*|image=*|netopt=*|skip=*|sshport=*)
"opt_${OPTARG%%=*}" "${OPTARG#*=}"
;;
*)
@@ -209,6 +233,10 @@ while getopts :gi:s:-: OPTCHAR; do
done
shift "$((OPTIND - 1))"
+if test -n "$SSHPORT"; then
+ opt_netopt "hostfwd=tcp:127.0.0.1:$SSHPORT-:22"
+fi
+
test -f "$IMAGE" || die "image '$IMAGE' not found"
test -s "$IMAGE" || die "image '$IMAGE' is empty"
@@ -297,7 +325,6 @@ KERNEL_CMDLINE=
if ! check_skip root/cmd; then
KERNEL_CMDLINE="root=LABEL=$IMAGE_LABEL rw"
fi
-NETDEV="user,id=net0"
KERNELFD=3
while test -h "/proc/self/fd/$KERNELFD"; do
@@ -450,19 +477,20 @@ 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
+
+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 "$NETDEV" -device "$NIC_DEV" "$@"
+ set -- -netdev "user,id=net0$NETOPTS" -device "$NIC_DEV" "$@"
fi
echo "+ $QEMU $*" 1>&2