Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 72 lines (58 sloc) 1.426 kb
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
1 #!/bin/bash
ca81781 Dave Reisner qinit: move config to separate file
authored
2 #
3 # launcher script for qemu-kvm
4 #
5 # machines are sourced from a file which defines functions, each
6 # specifying options for the particular VM, for example:
7 #
8 # vm_beatbox() {
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
9 # mac="de:ad:be:ef:00:09"
10 # options=(-nographic)
ca81781 Dave Reisner qinit: move config to separate file
authored
11 # }
12 #
8440927 Dave Reisner qinit: add more defaults
authored
13 # If unspecified:
14 # ${drives[@]}: will match all of "$imgroot/$vm".*.qcow2
15 #
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
16
17 ### Paths ################################
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
18 machines=${XDG_CONFIG_HOME:-$HOME/.config}/qemu/machines
19 isoroot=/mnt/Gluttony/iso
20 imgroot=/mnt/Haven/qemu-img
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
21
22 ### Defaults #############################
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
23 mem=(-m 1024)
2d63059 Dave Reisner qinit: tweak startup opts
authored
24 cpus=(-cpu Nehalem -smp sockets=1,cores=2,threads=2)
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
25 iso=$isoroot/archlinux.iso
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
26 ### Launcher #############################
27
ca81781 Dave Reisner qinit: move config to separate file
authored
28 . "$machines"
29
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
30 while getopts 'cd:' flag; do
f774edc Dave Reisner qinit: call exec for qemu-kvm
authored
31 case $flag in
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
32 c) usecdrom=1 ;;
33 d) iso=$OPTARG ;;
f774edc Dave Reisner qinit: call exec for qemu-kvm
authored
34 esac
35 done
36 shift $(( OPTIND - 1 ))
37
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
38 if [[ -z $1 ]]; then
39 printf 'Available VMs:\n'
d83cbdc Dave Reisner qinit: use compgen to determine available vms
authored
40 compgen -A function -- vm_ | sed 's/^vm_/ /'
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
41 exit 0
42 fi
43
8440927 Dave Reisner qinit: add more defaults
authored
44 vm=$1; shift
45 if ! type -t vm_$vm >/dev/null; then
46 printf 'unknown VM: %s\n' "$vm"
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
47 exit 1
48 fi
49
8440927 Dave Reisner qinit: add more defaults
authored
50 vm_$vm
51
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
52 cdrom=(-cdrom "$iso" -boot d)
53 net=(-net vde -net nic,model=virtio,macaddr="$mac")
54
55 opts+=("${cpus[@]}" "${mem[@]}" "${net[@]}")
56
57 if (( usecdrom )); then
58 opts+=(-cdrom "$iso" -boot d)
59 fi
60
8440927 Dave Reisner qinit: add more defaults
authored
61 # default drives
62 if (( ${#drives[*]} == 0 )); then
63 for drive in "$imgroot/$vm".*.qcow2; do
2d63059 Dave Reisner qinit: tweak startup opts
authored
64 opts+=("-drive" "file=$drive,if=virtio,aio=native")
8440927 Dave Reisner qinit: add more defaults
authored
65 done
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
66 else
67 opts+=("${drives[@]}")
8440927 Dave Reisner qinit: add more defaults
authored
68 fi
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
69
45fb997 Dave Reisner qinit: simplify machine definitions, cleanup option building
authored
70 exec kvm "${opts[@]}" "$@"
e4285a3 Dave Reisner qinit: quick launcher framework for qemu/kvm
authored
71
Something went wrong with that request. Please try again.