Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 72 lines (58 sloc) 1.426 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#!/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() {
# mac="de:ad:be:ef:00:09"
# options=(-nographic)
# }
#
# If unspecified:
# ${drives[@]}: will match all of "$imgroot/$vm".*.qcow2
#

### Paths ################################
machines=${XDG_CONFIG_HOME:-$HOME/.config}/qemu/machines
isoroot=/mnt/Gluttony/iso
imgroot=/mnt/Haven/qemu-img

### Defaults #############################
mem=(-m 1024)
cpus=(-cpu Nehalem -smp sockets=1,cores=2,threads=2)
iso=$isoroot/archlinux.iso
### Launcher #############################

. "$machines"

while getopts 'cd:' flag; do
case $flag in
    c) usecdrom=1 ;;
    d) iso=$OPTARG ;;
  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

cdrom=(-cdrom "$iso" -boot d)
net=(-net vde -net nic,model=virtio,macaddr="$mac")

opts+=("${cpus[@]}" "${mem[@]}" "${net[@]}")

if (( usecdrom )); then
opts+=(-cdrom "$iso" -boot d)
fi

# default drives
if (( ${#drives[*]} == 0 )); then
for drive in "$imgroot/$vm".*.qcow2; do
opts+=("-drive" "file=$drive,if=virtio,aio=native")
  done
else
opts+=("${drives[@]}")
fi

exec kvm "${opts[@]}" "$@"

Something went wrong with that request. Please try again.