From a61487ea842a83b927c689f3b38fbb3edd289b8a Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 10 Jan 2014 00:08:53 +0100 Subject: add a bunch of new scripts Signed-off-by: Florian Pritz --- qinit | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 qinit (limited to 'qinit') diff --git a/qinit b/qinit new file mode 100755 index 0000000..bdece6e --- /dev/null +++ b/qinit @@ -0,0 +1,80 @@ +#!/bin/bash +# +# launcher script for qemu-kvm +# +# machines are sourced from a file which defines functions, each +# specifying options for the particular VM, for example: +# +# vm_beatbox() { +# net+=",mac=de:ad:be:ef:00:01" +# cdrom="-cdrom $isoroot/archlinux-2011.05.08-core-x86_64.iso -boot d" +# +# opts=(-nographic) +# drives=( +# "-drive file=$imgroot/beatbox.1.qcow2,if=virtio" +# "-drive file=$imgroot/beatbox.2.qcow2,if=virtio" +# ) +# } +# +# If unspecified: +# ${drives[@]}: will match all of "$imgroot/$vm".*.qcow2 +# + +shopt -s nullglob + +### Paths ################################ +#declare config_root=/mnt/levant/nfs/tmp/Florian/qemu +declare config_root=/mnt/data/qemu +declare -r machines=$config_root/machines +declare isoroot=$config_root +declare imgroot=$config_root + +### Defaults ############################# +declare mem="-m 1024" +declare cpus="-cpu host -smp 4" +#declare net="-net vde -net nic,model=virtio" +declare net="-netdev bridge,br=br-qemu,id=mynet0 -device virtio-net,netdev=mynet0" +cdrom+=("-boot" "d") + +#declare cdrom="-cdrom $isoroot/archlinux-2012.11.01-dual.iso -boot d" +for iso in "$isoroot/"archlinux-*.iso; do + cdrom+=("-cdrom" "$iso") +done +### Launcher ############################# + +. "$machines" + +while getopts 'c' flag; do + case $flag in + c) usecdrom=true ;; + esac +done +shift $(( OPTIND - 1 )) + +if [[ -z $1 ]]; then + printf 'Available VMs:\n' + compgen -A function -- vm_ | sed 's/^vm_/ /' + exit 0 +fi + +vm=$1; shift +if ! type -t vm_$vm >/dev/null; then + printf 'unknown VM: %s\n' "$vm" + exit 1 +fi + +vm_$vm + +# default drives +if (( ${#drives[*]} == 0 )); then + for drive in "$imgroot/$vm".*.raw; do + drives+=("-drive" "file=$drive,if=virtio,format=raw") + done + + for drive in "$imgroot/$vm".*.qcow2; do + drives+=("-drive" "file=$drive,if=virtio") + done +fi + +exec qemu-system-x86_64 --machine type=pc,accel=kvm "${opts[@]}" $cpus $mem "${drives[@]}" $net ${usecdrom:+${cdrom[@]}} "$@" + -- cgit v1.2.3-24-g4f1b