@@ -19,6 +19,7 @@ IGNITION_CONFIG_FILE=""
19
19
CONFIG_IMAGE=" "
20
20
SWTPM_DIR=
21
21
SAFE_ARGS=0
22
+ FORWARDED_PORTS=" "
22
23
USAGE=" Usage: $0 [-a authorized_keys] [--] [qemu options...]
23
24
Options:
24
25
-i FILE File containing an Ignition config
@@ -28,6 +29,7 @@ Options:
28
29
-a FILE SSH public keys for login access. [~/.ssh/id_{dsa,rsa}.pub]
29
30
-p PORT The port on localhost to map to the VM's sshd. [2222]
30
31
-I FILE Set a custom image file.
32
+ -f PORT Forward host_port:guest_port.
31
33
-M MB Set VM memory in MBs.
32
34
-T DIR Add a software TPM2 device through swtpm which stores secrets
33
35
and the control socket to the given directory. This may need
@@ -84,6 +86,9 @@ while [ $# -ge 1 ]; do
84
86
-p|-ssh-port)
85
87
SSH_PORT=" $2 "
86
88
shift 2 ;;
89
+ -f|-forward-port)
90
+ FORWARDED_PORTS=" ${FORWARDED_PORTS} $2 "
91
+ shift 2 ;;
87
92
-s|-safe)
88
93
SAFE_ARGS=1
89
94
shift ;;
@@ -203,6 +208,15 @@ if [ -z "${CONFIG_IMAGE}" ]; then
203
208
fi
204
209
fi
205
210
211
+ # Process port forwards
212
+ QEMU_FORWARDED_PORTS=" "
213
+ for port in ${FORWARDED_PORTS} ; do
214
+ host_port=${port%:* }
215
+ guest_port=${port#*: }
216
+ QEMU_FORWARDED_PORTS=" ${QEMU_FORWARDED_PORTS} ,hostfwd=tcp::${host_port} -:${guest_port} "
217
+ done
218
+ QEMU_FORWARDED_PORTS=" ${QEMU_FORWARDED_PORTS# ,} "
219
+
206
220
# Start assembling our default command line arguments
207
221
if [ " ${SAFE_ARGS} " -eq 1 ]; then
208
222
# Disable KVM, for testing things like UEFI which don't like it
@@ -288,7 +302,7 @@ case "${VM_BOARD}" in
288
302
qemu-system-x86_64 \
289
303
-name " $VM_NAME " \
290
304
-m ${VM_MEMORY} \
291
- -netdev user,id=eth0,hostfwd=tcp::" ${SSH_PORT} " -:22,hostname=" ${VM_NAME} " \
305
+ -netdev user,id=eth0,${QEMU_FORWARDED_PORTS} , hostfwd=tcp::" ${SSH_PORT} " -:22,hostname=" ${VM_NAME} " \
292
306
-device virtio-net-pci,netdev=eth0 \
293
307
-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 \
294
308
" $@ "
@@ -297,7 +311,7 @@ case "${VM_BOARD}" in
297
311
qemu-system-aarch64 \
298
312
-name " $VM_NAME " \
299
313
-m ${VM_MEMORY} \
300
- -netdev user,id=eth0,hostfwd=tcp::" ${SSH_PORT} " -:22,hostname=" ${VM_NAME} " \
314
+ -netdev user,id=eth0,${QEMU_FORWARDED_PORTS} , hostfwd=tcp::" ${SSH_PORT} " -:22,hostname=" ${VM_NAME} " \
301
315
-device virtio-net-device,netdev=eth0 \
302
316
-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 \
303
317
" $@ "
0 commit comments