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 MiB" |
---|
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 | *) |
---|
36 | echo "Unknown option: $1" |
---|
37 | echo |
---|
38 | usage |
---|
39 | ;; |
---|
40 | esac |
---|
41 | done |
---|
42 | if [ -z "$name" ]; then |
---|
43 | usage |
---|
44 | fi |
---|
45 | disk_size=$(( $fs_size + $swap_size )) |
---|
46 | |
---|
47 | |
---|
48 | lvcreate "$vg" --name "s_${name}_hda" --size "$disk_size"m |
---|
49 | |
---|
50 | # XXX breaks if $name has dashes |
---|
51 | TARGET=/dev/mapper/$vg-s_${name}_hda FSSIZE=$fs_size \ |
---|
52 | ARCH=$arch DIST=$dist MIRROR=$mirror \ |
---|
53 | HOSTNAME=$hostname IP=$ip \ |
---|
54 | invirt-create-image |
---|
55 | |
---|
56 | cat >/etc/xen/sysvms/s_$name <<EOF |
---|
57 | import os |
---|
58 | |
---|
59 | release = os.uname()[2] |
---|
60 | kernel = '/boot/vmlinuz-%s' % release |
---|
61 | ramdisk = '/boot/initrd.img-%s' % release |
---|
62 | memory = '$memory' |
---|
63 | |
---|
64 | disk = ['phy:$vg/s_${name}_hda,hda,w'] |
---|
65 | |
---|
66 | name = 's_$name' |
---|
67 | |
---|
68 | vif = [ 'ip=$ip,mac=$mac' ] |
---|
69 | |
---|
70 | on_poweroff = 'destroy' |
---|
71 | on_reboot = 'restart' |
---|
72 | on_crash = 'restart' |
---|
73 | |
---|
74 | root = "/dev/hda1 ro" |
---|
75 | extra = '2 console=xvc0' |
---|
76 | EOF |
---|
77 | |
---|
78 | echo |
---|
79 | echo "Configuration written to /etc/xen/sysvms/s_$name." |
---|
80 | echo "To boot:" |
---|
81 | echo " xm create sysvms/s_$name" |
---|