1 | #!/bin/bash |
---|
2 | |
---|
3 | set -e |
---|
4 | |
---|
5 | usage () { |
---|
6 | echo "usage:" |
---|
7 | echo "invirt-admin create-sysvm {options}" |
---|
8 | echo " required options: --name, --fs-size, --swap-size, --memory," |
---|
9 | echo " --hostname, --ip, --mac, --arch, --dist, --mirror" |
---|
10 | echo |
---|
11 | echo " optional options: --netmask, --gateway. Defaults will be pulled from invirt-getconf" |
---|
12 | echo |
---|
13 | echo " fs-size, swap-size, memory in MiB" |
---|
14 | echo " fs-size + swap-size will be total disk-image size" |
---|
15 | exit 2 |
---|
16 | } |
---|
17 | |
---|
18 | if [ create-sysvm != "$1" ]; then |
---|
19 | usage |
---|
20 | fi |
---|
21 | shift |
---|
22 | |
---|
23 | vg=$(invirt-getconf lvm.vg) |
---|
24 | while [ $# -gt 0 ]; do |
---|
25 | case "$1" in |
---|
26 | --vg) vg=$2; shift 2;; |
---|
27 | --name) name=$2; shift 2;; |
---|
28 | --fs-size) fs_size=$2; shift 2;; |
---|
29 | --swap-size) swap_size=$2; shift 2;; |
---|
30 | --memory) memory=$2; shift 2;; |
---|
31 | --hostname) hostname=$2; shift 2;; |
---|
32 | --ip) ip=$2; shift 2;; |
---|
33 | --mac) mac=$2; shift 2;; |
---|
34 | --arch) arch=$2; shift 2;; |
---|
35 | --dist) dist=$2; shift 2;; |
---|
36 | --mirror) mirror=$2; shift 2;; |
---|
37 | --netmask) netmask=$2; shift 2;; |
---|
38 | --gateway) gateway=$2; shift 2;; |
---|
39 | *) |
---|
40 | echo "Unknown option: $1" |
---|
41 | echo |
---|
42 | usage |
---|
43 | ;; |
---|
44 | esac |
---|
45 | done |
---|
46 | if [ -z "$name" ]; then |
---|
47 | usage |
---|
48 | fi |
---|
49 | disk_size=$(( $fs_size + $swap_size )) |
---|
50 | |
---|
51 | |
---|
52 | lvcreate "$vg" --name "s_${name}_hda" --size "$disk_size"m |
---|
53 | |
---|
54 | # XXX breaks if $name has dashes |
---|
55 | TARGET=/dev/mapper/$vg-s_${name}_hda FSSIZE=$fs_size \ |
---|
56 | ARCH=$arch DIST=$dist MIRROR=$mirror \ |
---|
57 | HOSTNAME=$hostname IP=$ip \ |
---|
58 | NETMASK=$netmask GATEWAY=$gateway \ |
---|
59 | invirt-create-image |
---|
60 | |
---|
61 | cat >/etc/xen/sysvms/s_$name <<EOF |
---|
62 | import os |
---|
63 | |
---|
64 | release = os.uname()[2] |
---|
65 | kernel = '/boot/vmlinuz-%s' % release |
---|
66 | ramdisk = '/boot/initrd.img-%s' % release |
---|
67 | memory = '$memory' |
---|
68 | |
---|
69 | disk = ['phy:$vg/s_${name}_hda,hda,w'] |
---|
70 | |
---|
71 | name = 's_$name' |
---|
72 | |
---|
73 | vif = [ 'ip=$ip,mac=$mac' ] |
---|
74 | |
---|
75 | on_poweroff = 'destroy' |
---|
76 | on_reboot = 'restart' |
---|
77 | on_crash = 'restart' |
---|
78 | |
---|
79 | root = "/dev/hda1 ro" |
---|
80 | extra = '2 console=xvc0' |
---|
81 | EOF |
---|
82 | |
---|
83 | echo |
---|
84 | echo "Configuration written to /etc/xen/sysvms/s_$name." |
---|
85 | echo "To boot:" |
---|
86 | echo " xm create sysvms/s_$name" |
---|