Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 55 lines (44 sloc) 1.19 kb
e4285a3 @falconindy qinit: quick launcher framework for qemu/kvm
authored
1 #!/bin/bash
ca81781 @falconindy 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() {
9 # cdrom="-cdrom $isoroot/archlinux-2011.05.08-core-x86_64.iso -boot d"
10 #
11 # opts=(-nographic)
12 # drives=(
13 # "-drive file=$imgroot/beatbox.1.qcow2,if=virtio"
14 # "-drive file=$imgroot/beatbox.2.qcow2,if=virtio"
15 # )
16 # }
17 #
e4285a3 @falconindy qinit: quick launcher framework for qemu/kvm
authored
18
19 ### Paths ################################
ca81781 @falconindy qinit: move config to separate file
authored
20 declare -r machines=$XDG_CONFIG_HOME/qemu/machines
f3d5f3e @falconindy qinit: dont force RO on {iso,img}root
authored
21 declare isoroot=/mnt/Gluttony/iso
22 declare imgroot=/mnt/Haven/qemu-img
e4285a3 @falconindy qinit: quick launcher framework for qemu/kvm
authored
23
24 ### Defaults #############################
25 declare mem="-m 1024"
26 declare cpus="-smp 4"
f774edc @falconindy qinit: call exec for qemu-kvm
authored
27 declare net="-net vde -net nic,model=virtio"
e4285a3 @falconindy qinit: quick launcher framework for qemu/kvm
authored
28
29 ### Launcher #############################
30
ca81781 @falconindy qinit: move config to separate file
authored
31 . "$machines"
32
f774edc @falconindy qinit: call exec for qemu-kvm
authored
33 while getopts 'c' flag; do
34 case $flag in
35 c) usecdrom=true ;;
36 esac
37 done
38 shift $(( OPTIND - 1 ))
39
e4285a3 @falconindy qinit: quick launcher framework for qemu/kvm
authored
40 if [[ -z $1 ]]; then
41 printf 'Available VMs:\n'
ca81781 @falconindy qinit: move config to separate file
authored
42 printf ' %s\n' $(sed -n 's/^vm_\([^(;$]\+\).*/\1/p' "$machines")
e4285a3 @falconindy qinit: quick launcher framework for qemu/kvm
authored
43 exit 0
44 fi
45
46 if ! type -t vm_$1 >/dev/null; then
47 printf 'unknown VM: %s\n' "$1"
48 exit 1
49 fi
50
51 vm_$1; shift
52
f774edc @falconindy qinit: call exec for qemu-kvm
authored
53 exec qemu-kvm "${opts[@]}" $cpus $mem ${drives[@]} $net ${usecdrom:+$cdrom} "$@"
e4285a3 @falconindy qinit: quick launcher framework for qemu/kvm
authored
54
Something went wrong with that request. Please try again.