source: trunk/scripts/invirt-admin/invirt-admin @ 2936

Last change on this file since 2936 was 2900, checked in by gdb, 14 years ago

Changed xen.lvm -> lvm

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#!/bin/bash
2
3set -e
4
5usage () {
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
18if [ create-sysvm != "$1" ]; then
19    usage
20fi
21shift
22
23vg=$(invirt-getconf lvm.vg)
24while [ $# -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=$2shift 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
45done
46if [ -z "$name" ]; then
47    usage
48fi
49disk_size=$(( $fs_size + $swap_size ))
50
51
52lvcreate "$vg" --name "s_${name}_hda" --size "$disk_size"m
53
54# XXX breaks if $name has dashes
55TARGET=/dev/mapper/$vg-s_${name}_hda FSSIZE=$fs_size \
56ARCH=$arch DIST=$dist MIRROR=$mirror \
57HOSTNAME=$hostname IP=$ip \
58NETMASK=$netmask GATEWAY=$gateway \
59 invirt-create-image
60
61cat >/etc/xen/sysvms/s_$name <<EOF
62import os
63
64release     = os.uname()[2]
65kernel      = '/boot/vmlinuz-%s' % release
66ramdisk     = '/boot/initrd.img-%s' % release
67memory      = '$memory'
68
69disk        = ['phy:$vg/s_${name}_hda,hda,w']
70
71name        = 's_$name'
72
73vif         = [ 'ip=$ip,mac=$mac' ]
74
75on_poweroff = 'destroy'
76on_reboot   = 'restart'
77on_crash    = 'restart'
78
79root = "/dev/hda1 ro"
80extra = '2 console=xvc0'
81EOF
82
83echo
84echo "Configuration written to /etc/xen/sysvms/s_$name."
85echo "To boot:"
86echo "  xm create sysvms/s_$name"
Note: See TracBrowser for help on using the repository browser.