forked from grnet/ganeti-instance-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create
executable file
·77 lines (73 loc) · 2.44 KB
/
create
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
#!/bin/sh
# Copyright (C) 2010, 2011, 2012 Oregon State University
# Copyright (C) 2013, 2014, 2015 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
set -e
. ./common.sh
debug set -x
# TODO: optimise some things based on INSTANCE_REINSTALL=1
test 'no' = "$CDINSTALL" || exit 0
RUN_PARTS="`which run-parts`"
get_imagefile
# workaround restore's non-unique /tmp/rstdir* & /tmp/rstmode*
test -f "$IMAGE_FILE" || die 'Can'\''t find image file "%s"\n' "$IMAGE_FILE"
case "$IMAGE_TYPE" in
tarball|dump)
losetup_blockdev
! test 'dump' = "$IMAGE_TYPE" || use_unique_tmpdir
get_disk0_size_mbytes
check_swap_size
format_disk0
;;
qemu)
if test 'nomount' = "`printf '%s' "$IMAGE_NAME" | cut -d- -f1`" && ! test -b "$BLOCKDEV"; then
qcow_extract 'raw'
else
losetup_blockdev
qcow_extract
fi
# deploying something like a windows image, skip the rest
! test 'yes' = "$NOMOUNT" || exit 0
;;
esac
map_all
if test -n "$RUN_PARTS" && test -d "$PRE_CUSTOMIZE_DIR"; then
export TARGET SUITE IMAGE_TYPE filesystem_dev
env DISK_0_PATH="$BLOCKDEV" "$RUN_PARTS" "$PRE_CUSTOMIZE_DIR"
fi
if ! test 'qemu' = "$IMAGE_TYPE"; then
mkfs_disk0
get_uuids
fi
mkdir_disk0_temp
mount_disk0
case "$IMAGE_TYPE" in
tarball)
tarball_extract
;;
dump)
dump_extract
;;
esac
test 'qemu' = "$IMAGE_TYPE" || setup_fstab
! test 'True' = "$INSTANCE_HV_serial_console" || setup_console
filesystem_relabel
if test -n "$RUN_PARTS" && test -d "$CUSTOMIZE_DIR"; then
ROOT_DEV="$root_dev"; BOOT_DEV="$boot_dev"; IMG_SSH_KEY_URL="$IMG_SSH_KEY_URL"
export TARGET SUITE ROOT_DEV BOOT_DEV IMAGE_TYPE IMG_SSH_KEY_URL
env DISK_0_PATH="$BLOCKDEV" "$RUN_PARTS" "$CUSTOMIZE_DIR"
fi