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