Skip to content

Instantly share code, notes, and snippets.

@haraldh
Created April 19, 2021 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haraldh/56cd15f8209fd61f1e2f4d299da757f6 to your computer and use it in GitHub Desktop.
Save haraldh/56cd15f8209fd61f1e2f4d299da757f6 to your computer and use it in GitHub Desktop.
qemu_add_drive_args
# generate qemu arguments for named raw disks
#
# qemu_add_drive_args <index> <filename> <id-name> [<bootindex>]
#
# $1: name of the index variable (set to 0 at start)
# $2: name of the argument array variable (set to () at start)
# $3: filename of the raw disk image
# $4: name of the disk in /dev/disk/by-id -> /dev/disk/by-id/ata-disk_$name
# $5: optional bootindex number
#
# to be used later with `qemu … "${args[@]}" …`
#
# can't be easier than this :-/
#
# # EXAMPLES
# ```
# declare -a args=()
# let i=0
# qemu_add_drive_args i args "$TESTDIR"/root.ext3 root 1
# qemu_add_drive_args i args "$TESTDIR"/client.img client
# qemu_add_drive_args i args "$TESTDIR"/iscsidisk2.img iscsidisk2
# qemu_add_drive_args i args "$TESTDIR"/iscsidisk3.img iscsidisk3
# qemu "${args[@]}"
# ```
qemu_add_drive_args() {
local index=${!1}
local file=$3
local name=${4:-$index}
local bootindex=$5
eval "${2}"'+=(' \
-drive "if=none,format=raw,file=${file},id=drive-sata${index}" \
-device "ide-hd,bus=ide.${index},drive=drive-sata${index},id=sata${index},${bootindex:+bootindex=$bootindex,}model=disk,serial=${name}" \
')'
let "${1}++"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment