-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathopenstack-bundle
More file actions
executable file
·129 lines (102 loc) · 3.39 KB
/
openstack-bundle
File metadata and controls
executable file
·129 lines (102 loc) · 3.39 KB
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 -e
# Copyright (c) 2011-2015 TurnKey GNU/Linux - http://www.turnkeylinux.org
#
# This file is part of buildtasks.
#
# Buildtasks is free software; you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; }
info() { echo "INFO [$(basename $0)]: $@"; }
usage() {
cat<<EOF
Syntax: $0 rootfs
Bundles rootfs into an openstack tarball
Arguments::
rootfs - root filesystem path
EOF
exit 1
}
if [[ "$#" != "1" ]]; then
usage
fi
rootfs=$1
name=$(echo $rootfs | sed 's/.rootfs//')
appname=$(echo $name |sed 's/turnkey-\(.*\)-[0-9].*/\1/')
case "$appname" in
canvas) loopsize_padding=524288 ;;
ejabberd) loopsize_padding=524288 ;;
appengine-python) loopsize_padding=524288 ;;
*) loopsize_padding=262144 ;;
esac
info "getting size for loopback"
rootsize=$(du -s $rootfs | awk '{print $1}')
loopsize=$[$rootsize + $loopsize_padding]
info "creating sparse loopback"
dd if=/dev/null of=$rootfs.img bs=1 seek=${loopsize}K
info "creating partition"
#inspired by package openstack-debian-images
PARTED=/sbin/parted
AMI_NAME=$rootfs.img
${PARTED} -s ${AMI_NAME} mktable msdos
${PARTED} -s -a optimal ${AMI_NAME} mkpart primary ext3 1Mi 100%
${PARTED} -s ${AMI_NAME} set 1 boot on
install-mbr ${AMI_NAME}
RESULT_KPARTX=`kpartx -asv ${AMI_NAME} 2>&1`
if echo "${RESULT_KPARTX}" | grep "^add map" ; then
LOOP_DEVICE=`echo ${RESULT_KPARTX} | cut -d" " -f3`
info "kpartx mounted using: ${LOOP_DEVICE}"
else
fatal "It seems kpartx didn't mount the image correctly: exiting."
fi
cleanup(){
error=$?
[ ! -d "${MOUNT_DIR}" ] && return
echo
echo "error $error, umounting $MOUNT_DIR"
chroot ${MOUNT_DIR} umount /proc || true
chroot ${MOUNT_DIR} umount /sys || true
umount ${MOUNT_DIR}
rmdir ${MOUNT_DIR}
kpartx -d ${AMI_NAME}
exit $error
}
trap "cleanup" EXIT TERM INT
mkfs.ext4 -F -j -L root /dev/mapper/${LOOP_DEVICE}
# No fsck because of X days without checks
tune2fs -i 0 /dev/mapper/${LOOP_DEVICE}
MOUNT_DIR=`mktemp -d -t build-debimg.XXXXXX`
mount -o loop /dev/mapper/${LOOP_DEVICE} ${MOUNT_DIR}
info "syncing rootfs to loopback"
rsync -a -t -r -S -I -H $rootfs/ ${MOUNT_DIR}
info "install extlinux"
mkdir -p ${MOUNT_DIR}/boot/extlinux
echo "default linux
timeout 1
label linux
kernel /vmlinuz
append initrd=/initrd.img root=LABEL=root biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200 ro" > ${MOUNT_DIR}/boot/extlinux/extlinux.conf
rm ${MOUNT_DIR}/extlinux.conf || true
ln ${MOUNT_DIR}/boot/extlinux/extlinux.conf ${MOUNT_DIR}/extlinux.conf
extlinux --install ${MOUNT_DIR}/boot/extlinux
info "umount loopback"
umount -d ${MOUNT_DIR}
rmdir ${MOUNT_DIR}
fsck.ext3 -f /dev/mapper/${LOOP_DEVICE} || true
#the next command failed once, so
sync
kpartx -d ${AMI_NAME}
if [ -z "$BT_DEBUG" ]; then
info "removing directory"
rm -rf $name
fi
info "creating qcow2 image"
QCOW2_NAME=$name-openstack.qcow2
QEMU_VERSION=`qemu-img --help | head -n 1 | cut -d" " -f3 | cut -d"," -f1`
if dpkg --compare-versions ${QEMU_VERSION} gt 1.0 ; then
OTHER_QEMU_IMG_OPTIONS=" -o compat=0.10"
else
OTHER_QEMU_IMG_OPTIONS=""
fi
qemu-img convert -f raw ${AMI_NAME}${OTHER_QEMU_IMG_OPTIONS} -O qcow2 ${QCOW2_NAME}