-
Notifications
You must be signed in to change notification settings - Fork 6
/
vmbuilder.sh
executable file
·129 lines (116 loc) · 4.51 KB
/
vmbuilder.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
#
# description:
# VM builder
#
# requires:
# bash
# pwd
#
# import:
# vm: create_vm
#
# memo:
#
# <based on vmbuilder>
#
# NAME
# vmbuilder - builds virtual machines from the command line
#
# SYNOPSIS
# vmbuilder [OPTIONS]...
#
# OPTIONS
#
# Guest partitioning options
# The following three options are not used if --part is specified:
#
# --rootsize=SIZE
# Size (in MB) of the root filesystem [default: 4096]. Discarded when --part is used.
#
# --optsize=SIZE
# Size (in MB) of the /opt filesystem. If not set, no /opt filesystem will be added. Discarded when --part is used.
#
# --swapsize=SIZE
# Size (in MB) of the swap partition [default: 1024]. Discarded when --part is used.
#
# Network related options:
# --ip=ADDRESS
# IP address in dotted form [default: dhcp]
#
# Options below are discarded if --ip is not specified
# --mask=VALUE IP mask in dotted form [default: based on ip setting].
#
# --net=ADDRESS
# IP net address in dotted form [default: based on ip setting].
#
# --bcast=VALUE
# IP broadcast in dotted form [default: based on ip setting].
#
# --gw=ADDRESS
# Gateway (router) address in dotted form [default: based on ip setting (first valid address in the network)].
#
# --dns=ADDRESS
# DNS address in dotted form [default: based on ip setting (first valid address in the network)]
#
# Post install actions:
# --copy=FILE
# Read 'source dest' lines from FILE, copying source files from
# host to dest in the guest's file system.
#
# --execscript=SCRIPT
# Run SCRIPT after distro installation finishes. Script will be called with the guest's chroot as first argument, so you can use chroot $1 <cmd> to run code in
# the virtual machine.
#
#
# <based on tune2fs>
#
# --max-mount-count=COUNT
# Adjust the number of mounts after which the filesystem will be checked by e2fsck(8). If max-mount-counts is 0 or -1, the number of times the
# filesystem is mounted will be disregarded by e2fsck(8) and the kernel.
#
# Staggering the mount-counts at which filesystems are forcibly checked will avoid all filesystems being checked at one time when using journaled
# filesystems.
#
# You should strongly consider the consequences of disabling mount-count-dependent checking entirely. Bad disk drives, cables, memory, and kernel
# bugs could all corrupt a filesystem without marking the filesystem dirty or in error. If you are using journaling on your filesystem, your
# filesystem will never be marked dirty, so it will not normally be checked. A filesystem error detected by the kernel will still force an fsck on
# the next reboot, but it may already be too late to prevent data loss at that point.
#
# See also the -i option for time-dependent checking.
#
# --interval-between-check=COUNT
# Adjust the maximal time between two filesystem checks. No suffix or d will interpret the number interval-between-checks as days, m as months, and
# w as weeks. A value of zero will disable the time-dependent checking.
#
# It is strongly recommended that either -c (mount-count-dependent) or -i (time-dependent) checking be enabled to force periodic full e2fsck(8)
# checking of the filesystem. Failure to do so may lead to filesystem corruption (due to bad disks, cables, memory, or kernel bugs) going unnoticed,
# ultimately resulting in data loss or corruption.
#
set -e
## private functions
function register_options() {
debug=${debug:-}
[[ -z "${debug}" ]] || set -x
distro_name=${distro_name:-centos}
distro_ver=${distro_ver:-6}
hypervisor=${hypervisor:-kvm}
}
### environment variables
export LANG=C
export LC_ALL=C
### read-only variables
readonly abs_dirname=$(cd ${BASH_SOURCE[0]%/*} && pwd)
### include files
. ${abs_dirname}/functions/utils.sh
. ${abs_dirname}/functions/disk.sh
. ${abs_dirname}/functions/mbr.sh
. ${abs_dirname}/functions/distro.sh
. ${abs_dirname}/functions/hypervisor.sh
. ${abs_dirname}/functions/vm.sh
### prepare
extract_args $*
## main
[[ -f "${config_path}" ]] && load_config ${config_path} || :
register_options
create_vm