-
Notifications
You must be signed in to change notification settings - Fork 2
/
qinit
executable file
·65 lines (55 loc) · 1.48 KB
/
qinit
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
#!/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() {
# 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
#
### Paths ################################
declare -r machines=$XDG_CONFIG_HOME/qemu/machines
declare isoroot=/mnt/Gluttony/iso
declare imgroot=/mnt/Haven/qemu-img
### Defaults #############################
declare mem="-m 1024"
declare cpus="-cpu Nehalem -smp 4"
declare net="-net vde -net nic,model=virtio"
declare cdrom="-cdrom $isoroot/archlinux-2012.03.28_14-30-01-netinstall-x86_64.iso -boot d"
### 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".*.qcow2; do
drives+=("-drive" "file=$drive,if=virtio")
done
fi
exec qemu-kvm "${opts[@]}" $cpus $mem "${drives[@]}" $net ${usecdrom:+$cdrom} "$@"