Created
April 19, 2021 13:14
-
-
Save haraldh/56cd15f8209fd61f1e2f4d299da757f6 to your computer and use it in GitHub Desktop.
qemu_add_drive_args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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