mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 05:26:58 +02:00
build_library/qemu_template.sh: Add support for extra disks
This commit is contained in:
parent
36ee8ed43a
commit
df17f6b672
@ -20,6 +20,7 @@ CONFIG_IMAGE=""
|
|||||||
SWTPM_DIR=
|
SWTPM_DIR=
|
||||||
SAFE_ARGS=0
|
SAFE_ARGS=0
|
||||||
FORWARDED_PORTS=""
|
FORWARDED_PORTS=""
|
||||||
|
DISKS=()
|
||||||
USAGE="Usage: $0 [-a authorized_keys] [--] [qemu options...]
|
USAGE="Usage: $0 [-a authorized_keys] [--] [qemu options...]
|
||||||
Options:
|
Options:
|
||||||
-i FILE File containing an Ignition config
|
-i FILE File containing an Ignition config
|
||||||
@ -27,6 +28,11 @@ Options:
|
|||||||
-u FILE Cloudinit user-data as either a cloud config or script.
|
-u FILE Cloudinit user-data as either a cloud config or script.
|
||||||
-c FILE Config drive as an iso or fat filesystem image.
|
-c FILE Config drive as an iso or fat filesystem image.
|
||||||
-a FILE SSH public keys for login access. [~/.ssh/id_{dsa,rsa}.pub]
|
-a FILE SSH public keys for login access. [~/.ssh/id_{dsa,rsa}.pub]
|
||||||
|
-d DISK Setup additional disk. Can be used multiple times to
|
||||||
|
setup multiple disks. The value is a path to an image
|
||||||
|
file, optionally followed by a comma and options to
|
||||||
|
pass to virtio-blk-pci device. For example -d
|
||||||
|
/tmp/qcow2-disk,serial=secondary.
|
||||||
-p PORT The port on localhost to map to the VM's sshd. [2222]
|
-p PORT The port on localhost to map to the VM's sshd. [2222]
|
||||||
-I FILE Set a custom image file.
|
-I FILE Set a custom image file.
|
||||||
-f PORT Forward host_port:guest_port.
|
-f PORT Forward host_port:guest_port.
|
||||||
@ -83,6 +89,9 @@ while [ $# -ge 1 ]; do
|
|||||||
check_conflict
|
check_conflict
|
||||||
SSH_KEYS="$2"
|
SSH_KEYS="$2"
|
||||||
shift 2 ;;
|
shift 2 ;;
|
||||||
|
-d|-disk)
|
||||||
|
DISKS+=( "$2" )
|
||||||
|
shift 2 ;;
|
||||||
-p|-ssh-port)
|
-p|-ssh-port)
|
||||||
SSH_PORT="$2"
|
SSH_PORT="$2"
|
||||||
shift 2 ;;
|
shift 2 ;;
|
||||||
@ -262,6 +271,23 @@ if [ -n "${VM_IMAGE}" ]; then
|
|||||||
-device virtio-blk-pci,drive=blk,bootindex=1 "$@"
|
-device virtio-blk-pci,drive=blk,bootindex=1 "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
declare -i id_counter=1
|
||||||
|
|
||||||
|
for disk in "${DISKS[@]}"; do
|
||||||
|
disk_id="flatcar-extra-disk-$((id_counter++))"
|
||||||
|
if [[ ${disk} = *,* ]]; then
|
||||||
|
disk_path=${disk%%,*}
|
||||||
|
disk_opts=${disk#*,}
|
||||||
|
else
|
||||||
|
disk_path=${disk}
|
||||||
|
disk_opts=
|
||||||
|
fi
|
||||||
|
set -- \
|
||||||
|
-drive "if=none,id=${disk_id},file=${disk_path}" \
|
||||||
|
-device "virtio-blk-pci,drive=${disk_id}${disk_opts:+,}${disk_opts:-}" \
|
||||||
|
"${@}"
|
||||||
|
done
|
||||||
|
|
||||||
if [ -n "${VM_KERNEL}" ]; then
|
if [ -n "${VM_KERNEL}" ]; then
|
||||||
set -- -kernel "${VM_KERNEL}" "$@"
|
set -- -kernel "${VM_KERNEL}" "$@"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user