2012-11-09 11:04:13 +00:00
|
|
|
#!/bin/bash
|
2012-11-15 03:20:32 +00:00
|
|
|
#
|
|
|
|
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
2013-01-25 22:23:56 +00:00
|
|
|
#
|
2012-11-15 03:20:32 +00:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
2013-01-25 22:23:56 +00:00
|
|
|
#
|
2012-11-15 03:20:32 +00:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2013-01-25 22:23:56 +00:00
|
|
|
#
|
2012-11-15 03:20:32 +00:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2012-11-09 11:04:13 +00:00
|
|
|
|
2013-08-01 14:50:17 +00:00
|
|
|
set -eE
|
2012-11-09 11:04:13 +00:00
|
|
|
|
2017-05-03 01:31:11 +00:00
|
|
|
# Set/override locale. This ensures consistency in sorting etc. We
|
|
|
|
# need to choose a lowest-common denominator locale, as this is
|
|
|
|
# applied when running in the building chroot too (maybe a bug and we
|
|
|
|
# should prune this?). Thus "C" --centOS 7 doesn't include C.utf-8
|
|
|
|
# (fedora does, centos 8 probably will). Note: LC_ALL to really
|
|
|
|
# override this; it overrides LANG and all other LC_ vars
|
|
|
|
export LC_ALL=C
|
2013-01-28 18:08:50 +00:00
|
|
|
|
2013-04-04 19:38:19 +00:00
|
|
|
# Store our initial environment and command line args for later
|
|
|
|
export DIB_ARGS="$@"
|
2013-11-29 06:17:02 +00:00
|
|
|
export DIB_ENV=$(export | grep ' DIB_.*=')
|
2013-04-04 19:38:19 +00:00
|
|
|
|
2012-11-09 11:04:13 +00:00
|
|
|
SCRIPTNAME=$(basename $0)
|
2015-09-02 05:12:31 +00:00
|
|
|
|
2016-07-20 01:48:32 +00:00
|
|
|
if [ -z "$_LIB" ]; then
|
|
|
|
echo "_LIB not set!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-09-02 05:12:31 +00:00
|
|
|
|
2017-03-24 15:16:22 +00:00
|
|
|
_BASE_ELEMENT_DIR=$(${DIB_PYTHON_EXEC:-python} -c '
|
2016-09-09 03:11:52 +00:00
|
|
|
import diskimage_builder.paths
|
2016-07-20 01:48:32 +00:00
|
|
|
diskimage_builder.paths.show_path("elements")')
|
2015-09-02 05:12:31 +00:00
|
|
|
|
2012-11-09 11:04:13 +00:00
|
|
|
source $_LIB/die
|
|
|
|
|
2013-07-01 16:20:15 +00:00
|
|
|
IS_RAMDISK=0
|
|
|
|
if [ "$SCRIPTNAME" == "ramdisk-image-create" ]; then
|
|
|
|
IS_RAMDISK=1
|
|
|
|
fi
|
|
|
|
|
2012-11-09 11:04:13 +00:00
|
|
|
function show_options () {
|
2013-11-08 19:35:51 +00:00
|
|
|
echo "Usage: ${SCRIPTNAME} [OPTION]... [ELEMENT]..."
|
|
|
|
echo
|
2012-11-09 11:04:13 +00:00
|
|
|
echo "Options:"
|
2017-01-18 20:49:20 +00:00
|
|
|
echo " -a i386|amd64|armhf|arm64 -- set the architecture of the image(default amd64)"
|
2013-11-08 19:35:51 +00:00
|
|
|
echo " -o imagename -- set the imagename of the output image file(default image)"
|
2016-12-18 01:59:07 +00:00
|
|
|
echo " -t qcow2,tar,tgz,squashfs,vhd,docker,aci,raw -- set the image types of the output image files (default qcow2)"
|
2015-02-17 01:20:01 +00:00
|
|
|
echo " File types should be comma separated. VHD outputting requires the vhd-util"
|
2015-02-12 21:04:16 +00:00
|
|
|
echo " executable be in your PATH. ACI outputting requires the ACI_MANIFEST "
|
|
|
|
echo " environment variable be a path to a manifest file."
|
2017-02-07 04:21:09 +00:00
|
|
|
echo " -x -- turn on tracing (use -x -x for very detailed tracing)."
|
2012-12-14 00:25:18 +00:00
|
|
|
echo " -u -- uncompressed; do not compress the image - larger but faster"
|
2013-01-30 18:24:24 +00:00
|
|
|
echo " -c -- clear environment before starting work"
|
2018-10-24 01:13:26 +00:00
|
|
|
echo " --logfile -- save run output to given logfile (implies DIB_QUIET=1)"
|
2016-09-30 19:59:46 +00:00
|
|
|
echo " --checksum -- generate MD5 and SHA256 checksum files for the created image"
|
2013-11-25 18:00:01 +00:00
|
|
|
echo " --image-size size -- image size in GB for the created image"
|
2019-04-23 12:30:48 +00:00
|
|
|
echo " --image-extra-size size -- extra image size in GB for the created image"
|
2013-11-08 19:35:51 +00:00
|
|
|
echo " --image-cache directory -- location for cached images(default ~/.cache/image-create)"
|
2014-02-16 04:06:11 +00:00
|
|
|
echo " --max-online-resize size -- max number of filesystem blocks to support when resizing."
|
|
|
|
echo " Useful if you want a really large root partition when the image is deployed."
|
|
|
|
echo " Using a very large value may run into a known bug in resize2fs."
|
|
|
|
echo " Setting the value to 274877906944 will get you a 1PB root file system."
|
|
|
|
echo " Making this value unnecessarily large will consume extra disk space "
|
|
|
|
echo " on the root partition with extra file system inodes."
|
2013-08-26 11:57:34 +00:00
|
|
|
echo " --min-tmpfs size -- minimum size in GB needed in tmpfs to build the image"
|
2019-01-26 20:02:54 +00:00
|
|
|
echo " --mkfs-journal-size -- filesystem journal size in MB to pass to mkfs."
|
2015-03-17 17:06:38 +00:00
|
|
|
echo " --mkfs-options -- option flags to be passed directly to mkfs."
|
|
|
|
echo " Options should be passed as a single string value."
|
2013-05-02 21:02:38 +00:00
|
|
|
echo " --no-tmpfs -- do not use tmpfs to speed image build"
|
2013-07-17 21:17:01 +00:00
|
|
|
echo " --offline -- do not update cached resources"
|
2014-06-13 12:20:17 +00:00
|
|
|
echo " --qemu-img-options -- option flags to be passed directly to qemu-img."
|
|
|
|
echo " Options need to be comma separated, and follow the key=value pattern."
|
2014-09-16 18:11:07 +00:00
|
|
|
echo " --root-label label -- label for the root filesystem. Defaults to 'cloudimg-rootfs'."
|
2014-09-26 05:12:32 +00:00
|
|
|
echo " --ramdisk-element -- specify the main element to be used for building ramdisks."
|
2014-12-01 16:21:13 +00:00
|
|
|
echo " Defaults to 'ramdisk'. Should be set to 'dracut-ramdisk' for platforms such"
|
|
|
|
echo " as RHEL and CentOS that do not package busybox."
|
2014-10-27 16:49:30 +00:00
|
|
|
echo " --install-type -- specify the default installation type. Defaults to 'source'. Set to 'package' to use package based installations by default."
|
2015-06-07 20:44:10 +00:00
|
|
|
echo " --docker-target -- specify the repo and tag to use if the output type is docker. Defaults to the value of output imagename"
|
2013-07-01 16:20:15 +00:00
|
|
|
if [ "$IS_RAMDISK" == "0" ]; then
|
|
|
|
echo " -n skip the default inclusion of the 'base' element"
|
2018-11-23 09:09:31 +00:00
|
|
|
echo " -p package[,p2...] [-p p3] -- extra packages to install in the image. Runs once, after 'install.d' phase. Can be specified multiple times"
|
2013-07-01 16:20:15 +00:00
|
|
|
fi
|
2013-11-08 19:35:51 +00:00
|
|
|
echo " -h|--help -- display this help and exit"
|
2016-02-09 01:24:52 +00:00
|
|
|
echo " --version -- display version and exit"
|
2013-02-25 09:17:32 +00:00
|
|
|
echo
|
2017-06-16 02:09:24 +00:00
|
|
|
echo "Environment Variables:"
|
|
|
|
echo " (this is not a complete list)"
|
|
|
|
echo
|
|
|
|
echo " * ELEMENTS_PATH: specify external locations for the elements. As for \$PATH"
|
|
|
|
echo " * DIB_NO_TIMESTAMP: no timestamp prefix on output. Useful if capturing output"
|
2018-10-24 01:13:26 +00:00
|
|
|
echo " * DIB_QUIET: 1=do not output log output to stdout; 0=always ouptut to stdout. See --logfile"
|
2013-11-08 19:35:51 +00:00
|
|
|
echo
|
2013-11-26 18:59:14 +00:00
|
|
|
echo "NOTE: At least one distribution root element must be specified."
|
|
|
|
echo
|
2015-02-17 01:20:01 +00:00
|
|
|
echo "NOTE: If using the VHD output format you need to have a patched version of vhd-util installed for the image"
|
|
|
|
echo " to be bootable. The patch is available here: https://github.com/emonty/vhd-util/blob/master/debian/patches/citrix"
|
|
|
|
echo " and a PPA with the patched tool is available here: https://launchpad.net/~openstack-ci-core/+archive/ubuntu/vhd-util"
|
|
|
|
echo
|
2013-11-08 19:35:51 +00:00
|
|
|
echo "Examples:"
|
2013-12-05 10:10:28 +00:00
|
|
|
if [ "$IS_RAMDISK" == "0" ]; then
|
|
|
|
echo " ${SCRIPTNAME} -a amd64 -o ubuntu-amd64 vm ubuntu"
|
|
|
|
echo " export ELEMENTS_PATH=~/source/tripleo-image-elements/elements"
|
|
|
|
echo " ${SCRIPTNAME} -a amd64 -o fedora-amd64-heat-cfntools vm fedora heat-cfntools"
|
|
|
|
else
|
|
|
|
echo " ${SCRIPTNAME} -a amd64 -o fedora-deploy deploy fedora"
|
|
|
|
echo " ${SCRIPTNAME} -a amd64 -o ubuntu-ramdisk ramdisk ubuntu"
|
|
|
|
fi
|
2012-11-09 11:04:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 01:24:52 +00:00
|
|
|
function show_version() {
|
2017-03-24 15:16:22 +00:00
|
|
|
${DIB_PYTHON_EXEC:-python} -c "from diskimage_builder import version; print(version.version_info.version_string())"
|
2016-02-09 01:24:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-07 04:21:09 +00:00
|
|
|
DIB_DEBUG_TRACE=${DIB_DEBUG_TRACE:-0}
|
2012-12-18 20:45:02 +00:00
|
|
|
INSTALL_PACKAGES=""
|
2014-10-01 19:34:21 +00:00
|
|
|
IMAGE_TYPES=("qcow2")
|
2012-12-14 00:25:18 +00:00
|
|
|
COMPRESS_IMAGE="true"
|
2017-01-29 23:52:40 +00:00
|
|
|
ROOT_LABEL=""
|
2014-10-27 16:49:30 +00:00
|
|
|
DIB_DEFAULT_INSTALLTYPE=${DIB_DEFAULT_INSTALLTYPE:-"source"}
|
2015-03-17 17:06:38 +00:00
|
|
|
MKFS_OPTS=""
|
2015-02-12 21:04:16 +00:00
|
|
|
ACI_MANIFEST=${ACI_MANIFEST:-}
|
2015-06-07 20:44:10 +00:00
|
|
|
DOCKER_TARGET=""
|
2017-06-16 02:09:24 +00:00
|
|
|
LOGFILE=""
|
|
|
|
TEMP=`getopt -o a:ho:t:xucnp: -l checksum,no-tmpfs,offline,help,version,min-tmpfs:,image-size:,image-cache:,max-online-resize:,mkfs-options:,qemu-img-options:,ramdisk-element:,root-label:,install-type:,docker-target:,logfile: -n $SCRIPTNAME -- "$@"`
|
2013-11-08 19:35:51 +00:00
|
|
|
if [ $? -ne 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
|
2012-11-09 11:04:13 +00:00
|
|
|
|
|
|
|
# Note the quotes around `$TEMP': they are essential!
|
|
|
|
eval set -- "$TEMP"
|
|
|
|
|
|
|
|
while true ; do
|
|
|
|
case "$1" in
|
|
|
|
-a) export ARCH=$2; shift 2 ;;
|
|
|
|
-o) export IMAGE_NAME=$2; shift 2 ;;
|
2014-10-01 19:34:21 +00:00
|
|
|
-t) IFS="," read -a IMAGE_TYPES <<< "$2"; export IMAGE_TYPES ; shift 2 ;;
|
2013-11-08 19:35:51 +00:00
|
|
|
-h|--help) show_options; exit 0;;
|
2016-02-09 01:24:52 +00:00
|
|
|
--version) show_version; exit 0;;
|
2017-02-07 04:21:09 +00:00
|
|
|
-x) shift; DIB_DEBUG_TRACE=$(( $DIB_DEBUG_TRACE + 1 ));;
|
2012-12-14 00:25:18 +00:00
|
|
|
-u) shift; export COMPRESS_IMAGE="";;
|
2013-01-30 18:24:24 +00:00
|
|
|
-c) shift ; export CLEAR_ENV=1;;
|
2013-01-28 18:24:05 +00:00
|
|
|
-n) shift; export SKIP_BASE="1";;
|
2016-11-11 17:03:50 +00:00
|
|
|
-p) IFS="," read -a _INSTALL_PACKAGES <<< "$2"; export INSTALL_PACKAGES=( ${INSTALL_PACKAGES[@]} ${_INSTALL_PACKAGES[@]} ) ; shift 2 ;;
|
2016-09-30 19:59:46 +00:00
|
|
|
--checksum) shift; export DIB_CHECKSUM=1;;
|
2013-11-25 18:00:01 +00:00
|
|
|
--image-size) export DIB_IMAGE_SIZE=$2; shift 2;;
|
2019-04-23 12:30:48 +00:00
|
|
|
--image-extra-size) export DIB_IMAGE_EXTRA_SIZE=$2; shift 2;;
|
2013-09-19 13:50:48 +00:00
|
|
|
--image-cache) export DIB_IMAGE_CACHE=$2; shift 2;;
|
2014-02-16 04:06:11 +00:00
|
|
|
--max-online-resize) export MAX_ONLINE_RESIZE=$2; shift 2;;
|
2019-01-26 20:02:54 +00:00
|
|
|
--mkfs-journal-size) export DIB_JOURNAL_SIZE=$2; shift 2;;
|
2015-03-17 17:06:38 +00:00
|
|
|
--mkfs-options) MKFS_OPTS=$2; shift 2;;
|
2013-08-26 11:57:34 +00:00
|
|
|
--min-tmpfs) export DIB_MIN_TMPFS=$2; shift 2;;
|
2013-05-02 21:02:38 +00:00
|
|
|
--no-tmpfs) shift; export DIB_NO_TMPFS=1;;
|
2013-07-17 21:17:01 +00:00
|
|
|
--offline) shift; export DIB_OFFLINE=1;;
|
2014-06-13 12:20:17 +00:00
|
|
|
--qemu-img-options) QEMU_IMG_OPTIONS=$2; shift 2;;
|
2017-01-29 23:52:40 +00:00
|
|
|
--root-label) ROOT_LABEL=$2; shift 2;;
|
2014-09-26 05:12:32 +00:00
|
|
|
--ramdisk-element) RAMDISK_ELEMENT=$2; shift 2;;
|
2014-10-27 16:49:30 +00:00
|
|
|
--install-type) DIB_DEFAULT_INSTALLTYPE=$2; shift 2;;
|
2015-06-07 20:44:10 +00:00
|
|
|
--docker-target) export DOCKER_TARGET=$2; shift 2 ;;
|
2017-06-16 02:09:24 +00:00
|
|
|
--logfile) export LOGFILE=$2; shift 2 ;;
|
2012-11-09 11:04:13 +00:00
|
|
|
--) shift ; break ;;
|
|
|
|
*) echo "Internal error!" ; exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
2013-01-30 18:24:24 +00:00
|
|
|
|
2017-02-07 04:21:09 +00:00
|
|
|
export DIB_DEBUG_TRACE
|
|
|
|
|
2017-10-22 16:16:04 +00:00
|
|
|
# TODO: namespace this under ~/.cache/dib/ for consistency
|
2013-09-19 13:50:48 +00:00
|
|
|
export DIB_IMAGE_CACHE=${DIB_IMAGE_CACHE:-~/.cache/image-create}
|
2014-07-29 14:43:12 +00:00
|
|
|
mkdir -p $DIB_IMAGE_CACHE
|
2013-09-19 13:50:48 +00:00
|
|
|
|
2017-10-22 16:16:04 +00:00
|
|
|
# We have a couple of critical sections (touching parts of the host
|
|
|
|
# system or download images to common cache) that we use flock around.
|
|
|
|
# Use this directory for lockfiles.
|
|
|
|
export DIB_LOCKFILES=${DIB_LOCKFILES:-~/.cache/dib/lockfiles}
|
|
|
|
mkdir -p $DIB_LOCKFILES
|
|
|
|
|
2013-02-13 22:16:00 +00:00
|
|
|
if [ "$CLEAR_ENV" = "1" -a "$HOME" != "" ]; then
|
2013-01-30 18:24:24 +00:00
|
|
|
echo "Re-execing to clear environment."
|
|
|
|
echo "(note this will prevent much of the local_config element from working)"
|
|
|
|
exec -c $0 "$@"
|
|
|
|
fi
|
|
|
|
|
2017-06-16 02:09:24 +00:00
|
|
|
# We send stdout & stderr through "outfilter" which does timestamping,
|
|
|
|
# basic filtering and log file output.
|
|
|
|
_TS_FLAG=""
|
|
|
|
if [[ "${DIB_NO_TIMESTAMP:-0}" -eq 1 ]]; then
|
|
|
|
_TS_FLAG="--no-timestamp"
|
|
|
|
fi
|
2018-10-24 01:13:26 +00:00
|
|
|
# A logfile with *no* DIB_QUIET specified implies we just want output
|
|
|
|
# to the logfile. Explicitly setting DIB_QUIET=0 will overide this
|
|
|
|
# and log both.
|
|
|
|
if [[ -n "${LOGFILE}" && -z "${DIB_QUIET}" ]]; then
|
|
|
|
DIB_QUIET=1
|
|
|
|
fi
|
2017-06-16 02:09:24 +00:00
|
|
|
_QUIET_FLAG="-v"
|
|
|
|
if [[ "${DIB_QUIET:-0}" -eq 1 ]]; then
|
|
|
|
_QUIET_FLAG=""
|
|
|
|
fi
|
|
|
|
_LOGFILE_FLAG=""
|
|
|
|
if [[ -n "${LOGFILE}" ]]; then
|
|
|
|
echo "Output logs going to: ${LOGFILE}"
|
|
|
|
_LOGFILE_FLAG="-o ${LOGFILE}"
|
|
|
|
fi
|
2018-05-23 01:14:42 +00:00
|
|
|
|
|
|
|
# Save the existing stdout to fd3
|
|
|
|
exec 3>&1
|
|
|
|
|
2017-06-16 02:09:24 +00:00
|
|
|
exec 1> >( ${DIB_PYTHON_EXEC:-python} $_LIB/outfilter.py ${_TS_FLAG} ${_QUIET_FLAG} ${_LOGFILE_FLAG} ) 2>&1
|
|
|
|
|
2016-05-17 05:43:34 +00:00
|
|
|
|
|
|
|
# Display the current file/function/line in the debug output
|
|
|
|
function _ps4 {
|
|
|
|
IFS=" " called=($(caller 0))
|
|
|
|
local f=$(readlink -f ${called[2]})
|
2018-05-23 23:36:49 +00:00
|
|
|
# As we're being run out of the python package's lib/ dir (either
|
|
|
|
# virtualenv or system), we can strip everything before
|
|
|
|
# "site-packages" to significantly shorten the line without really
|
|
|
|
f=${f##*site-packages/}
|
2016-05-17 05:43:34 +00:00
|
|
|
printf "%-80s " "$f:${called[1]}:${called[0]}"
|
|
|
|
}
|
|
|
|
export -f _ps4
|
|
|
|
export PS4='+ $(_ps4): '
|
|
|
|
|
2012-11-09 11:04:13 +00:00
|
|
|
source $_LIB/img-defaults
|
2012-11-09 18:18:08 +00:00
|
|
|
source $_LIB/common-functions
|
2012-11-09 11:04:13 +00:00
|
|
|
source $_LIB/img-functions
|
|
|
|
|
2013-07-01 16:20:15 +00:00
|
|
|
if [ "$IS_RAMDISK" == "1" ]; then
|
|
|
|
source $_LIB/ramdisk-defaults
|
|
|
|
source $_LIB/ramdisk-functions
|
|
|
|
fi
|
|
|
|
|
2016-12-01 04:31:14 +00:00
|
|
|
echo "diskimage-builder version $(show_version)"
|
|
|
|
|
2014-11-21 18:30:21 +00:00
|
|
|
# If no elements are specified theres no way we can succeed
|
2014-11-25 21:25:31 +00:00
|
|
|
if [ -z "$*" ]; then
|
2014-11-21 18:30:21 +00:00
|
|
|
echo "ERROR: At least one distribution root element must be specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-06-20 03:48:37 +00:00
|
|
|
arg_to_elements "$@"
|
2013-01-22 01:35:31 +00:00
|
|
|
|
2017-02-07 04:21:09 +00:00
|
|
|
# start tracing after most boilerplate
|
|
|
|
if [ ${DIB_DEBUG_TRACE} -gt 0 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2014-10-01 19:34:21 +00:00
|
|
|
if [ "${#IMAGE_TYPES[@]}" = "1" ]; then
|
|
|
|
export IMAGE_NAME=${IMAGE_NAME%%\.${IMAGE_TYPES[0]}}
|
|
|
|
fi
|
|
|
|
|
2015-02-17 01:20:01 +00:00
|
|
|
# Check for required tools early on
|
|
|
|
for X in ${!IMAGE_TYPES[@]}; do
|
|
|
|
case "${IMAGE_TYPES[$X]}" in
|
|
|
|
qcow2)
|
2017-05-18 18:09:32 +00:00
|
|
|
if ! type qemu-img > /dev/null 2>&1; then
|
2015-02-17 01:20:01 +00:00
|
|
|
echo "qcow2 output format specified but qemu-img executable not found."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2016-12-17 21:41:14 +00:00
|
|
|
tgz)
|
|
|
|
# Force tar to be created.
|
|
|
|
IMAGE_TYPES+=('tar')
|
|
|
|
;;
|
2015-02-17 01:20:01 +00:00
|
|
|
vhd)
|
2017-05-18 18:09:32 +00:00
|
|
|
if ! type vhd-util > /dev/null 2>&1; then
|
2015-02-17 01:20:01 +00:00
|
|
|
echo "vhd output format specified but no vhd-util executable found."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2016-12-18 01:59:07 +00:00
|
|
|
squashfs)
|
2017-05-18 18:09:32 +00:00
|
|
|
if ! type mksquashfs > /dev/null 2>&1; then
|
2016-12-18 01:59:07 +00:00
|
|
|
echo "squashfs output format specified but no mksquashfs executable found."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2015-06-07 20:44:10 +00:00
|
|
|
docker)
|
2017-05-18 18:09:32 +00:00
|
|
|
if ! type docker > /dev/null 2>&1; then
|
2015-06-07 20:44:10 +00:00
|
|
|
echo "docker output format specified but no docker executable found."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$DOCKER_TARGET" ]; then
|
|
|
|
echo "Please set --docker-target."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2015-02-17 01:20:01 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-03-09 22:43:27 +00:00
|
|
|
# NOTE: fstrim is on most all recent systems. It is provided by the util-linux
|
|
|
|
# package.
|
2017-05-18 18:09:32 +00:00
|
|
|
if ! type fstrim > /dev/null 2>&1; then
|
2016-03-09 22:43:27 +00:00
|
|
|
echo "fstrim utility is not found. This is provided by util-linux package"
|
|
|
|
echo "Please check your PATH variable is set correctly"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-01-28 22:24:12 +00:00
|
|
|
# xattr support cannot be relied upon with tmpfs builds
|
|
|
|
# some kernels supoprt it, some don't
|
|
|
|
if [[ -n "${GENTOO_PROFILE}" ]]; then
|
|
|
|
if [[ "${GENTOO_PROFILE}" =~ "hardened" ]]; then
|
|
|
|
echo 'disabling tmpfs for gentoo hardened build'
|
|
|
|
export DIB_NO_TMPFS=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-11-09 11:04:13 +00:00
|
|
|
mk_build_dir
|
2017-04-22 07:49:22 +00:00
|
|
|
|
|
|
|
# Create the YAML file with the final and raw configuration for
|
|
|
|
# the block device layer.
|
|
|
|
mkdir -p ${TMP_BUILD_DIR}/block-device
|
|
|
|
BLOCK_DEVICE_CONFIG_YAML=${TMP_BUILD_DIR}/block-device/config.yaml
|
|
|
|
block_device_create_config_file "${BLOCK_DEVICE_CONFIG_YAML}"
|
|
|
|
|
|
|
|
# Write out the parameter file
|
|
|
|
DIB_BLOCK_DEVICE_PARAMS_YAML=${TMP_BUILD_DIR}/block-device/params.yaml
|
|
|
|
export DIB_BLOCK_DEVICE_PARAMS_YAML
|
|
|
|
cat >${DIB_BLOCK_DEVICE_PARAMS_YAML} <<EOF
|
|
|
|
config: ${BLOCK_DEVICE_CONFIG_YAML}
|
|
|
|
image-dir: ${TMP_IMAGE_DIR}
|
|
|
|
root-fs-type: ${FS_TYPE}
|
2017-01-29 23:52:40 +00:00
|
|
|
root-label: ${ROOT_LABEL}
|
2017-04-22 07:49:22 +00:00
|
|
|
mount-base: ${TMP_BUILD_DIR}/mnt
|
|
|
|
build-dir: ${TMP_BUILD_DIR}
|
|
|
|
EOF
|
|
|
|
|
2017-05-02 03:29:34 +00:00
|
|
|
dib-block-device init
|
2017-04-22 07:49:22 +00:00
|
|
|
|
2017-01-29 23:52:40 +00:00
|
|
|
# Need to get the real root label because it can be overwritten
|
|
|
|
# by the BLOCK_DEVICE_CONFIG.
|
|
|
|
DIB_ROOT_LABEL=$(dib-block-device getval root-label)
|
|
|
|
export DIB_ROOT_LABEL
|
|
|
|
|
|
|
|
# Need to get the real fs type for the root filesystem
|
|
|
|
DIB_ROOT_FSTYPE=$(dib-block-device getval root-fstype)
|
|
|
|
export DIB_ROOT_FSTYPE
|
|
|
|
|
2017-03-17 17:22:17 +00:00
|
|
|
# retrieve mount points so we can reuse in elements
|
|
|
|
DIB_MOUNTPOINTS=$(dib-block-device getval mount-points)
|
|
|
|
export DIB_MOUNTPOINTS
|
|
|
|
|
2012-11-09 11:04:13 +00:00
|
|
|
create_base
|
2014-10-27 16:49:30 +00:00
|
|
|
# This variable needs to be propagated into the chroot
|
2015-03-31 04:53:30 +00:00
|
|
|
mkdir -p $TMP_HOOKS_PATH/environment.d
|
2015-05-01 20:37:56 +00:00
|
|
|
echo "export DIB_DEFAULT_INSTALLTYPE=\${DIB_DEFAULT_INSTALLTYPE:-\"${DIB_DEFAULT_INSTALLTYPE}\"}" > $TMP_HOOKS_PATH/environment.d/11-dib-install-type.bash
|
2012-11-09 11:04:13 +00:00
|
|
|
run_d extra-data
|
2013-02-13 22:16:00 +00:00
|
|
|
# Run pre-install scripts. These do things that prepare the chroot for package installs
|
|
|
|
run_d_in_target pre-install
|
|
|
|
# Call install scripts to pull in the software users want.
|
|
|
|
run_d_in_target install
|
2017-04-03 09:13:26 +00:00
|
|
|
do_extra_package_install
|
2013-04-15 10:31:04 +00:00
|
|
|
run_d_in_target post-install
|
2018-10-18 14:49:40 +00:00
|
|
|
run_d post-root
|
2014-08-04 09:40:47 +00:00
|
|
|
# ensure we do not have a lost+found directory in the root folder
|
|
|
|
# that could cause copy to fail (it will be created again later
|
|
|
|
# when creating the file system, if it needs such directory)
|
|
|
|
if [ -e "$TMP_BUILD_DIR/mnt/lost+found" ]; then
|
|
|
|
sudo rm -rf "$TMP_BUILD_DIR/mnt/lost+found"
|
|
|
|
fi
|
2013-04-02 00:25:25 +00:00
|
|
|
# Free up /mnt
|
|
|
|
unmount_image
|
|
|
|
mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built
|
2013-05-06 19:17:42 +00:00
|
|
|
|
2017-02-07 04:21:09 +00:00
|
|
|
# save xtrace state, as we always want to turn it off to avoid
|
|
|
|
# spamming the logs with du output below.
|
2016-04-06 22:11:39 +00:00
|
|
|
xtrace=$(set +o | grep xtrace)
|
|
|
|
|
2016-08-18 05:26:30 +00:00
|
|
|
# temp file for holding du output
|
|
|
|
du_output=${TMP_BUILD_DIR}/du_output.tmp
|
|
|
|
|
2013-05-06 19:17:42 +00:00
|
|
|
if [ -n "$DIB_IMAGE_SIZE" ]; then
|
2016-03-08 00:17:59 +00:00
|
|
|
du_size=$(echo "$DIB_IMAGE_SIZE" | awk '{printf("%d\n",$1 * 1024 *1024)}')
|
2013-05-06 19:17:42 +00:00
|
|
|
else
|
2016-04-06 22:11:39 +00:00
|
|
|
set +o xtrace
|
2016-04-07 04:45:43 +00:00
|
|
|
echo "Calculating image size (this may take a minute)..."
|
2016-08-18 05:26:30 +00:00
|
|
|
sudo du -a -c -x ${TMP_BUILD_DIR}/built > ${du_output}
|
2016-03-08 00:17:59 +00:00
|
|
|
# the last line is the total size from "-c".
|
2019-04-23 12:30:48 +00:00
|
|
|
if [ -n "$DIB_IMAGE_EXTRA_SIZE" ]; then
|
2019-05-07 17:32:50 +00:00
|
|
|
# add DIB_IMAGE_EXTRA_SIZE megabytes to create a bigger image as requested
|
|
|
|
du_extra_size=$(echo "$DIB_IMAGE_EXTRA_SIZE" | awk '{printf("%d\n",$1 * 1024)}')
|
2019-04-23 12:30:48 +00:00
|
|
|
du_size_tmp=$(tail -n1 ${du_output} | cut -f1)
|
|
|
|
du_size=$(echo "$du_size_tmp $du_extra_size" | awk '{print int($1 + $2)}')
|
|
|
|
else
|
|
|
|
# scale this by 0.6 to create a slightly bigger image
|
|
|
|
du_size=$(tail -n1 ${du_output} | cut -f1 | awk '{print int($1 / 0.6)}')
|
|
|
|
fi
|
2016-04-06 22:11:39 +00:00
|
|
|
$xtrace
|
2013-05-06 19:17:42 +00:00
|
|
|
fi
|
2016-03-08 00:17:59 +00:00
|
|
|
|
|
|
|
if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
|
|
|
set +o xtrace
|
2016-08-18 05:26:30 +00:00
|
|
|
if [ ! -f "$du_output" ]; then
|
|
|
|
sudo du -a -c -x ${TMP_BUILD_DIR}/built > ${du_output}
|
2016-03-08 00:17:59 +00:00
|
|
|
fi
|
|
|
|
|
2016-08-18 05:26:30 +00:00
|
|
|
du_output_show="sort -nr ${du_output} |
|
2016-04-07 04:45:43 +00:00
|
|
|
numfmt --to=iec-i --padding=7
|
|
|
|
--suffix=B --field=1 --from-unit=1024"
|
|
|
|
|
2016-03-08 00:17:59 +00:00
|
|
|
# by default show the 10MiB and greater files & directories -- a
|
|
|
|
# dir with lots of little files will still show up, but this helps
|
|
|
|
# signal:noise ratio
|
|
|
|
if [[ ${DIB_SHOW_IMAGE_USAGE_FULL:-0} == 0 ]]; then
|
|
|
|
# numfmt will start giving a decimal place when < 10MiB
|
2016-04-07 04:45:43 +00:00
|
|
|
du_output_show+="| egrep 'MiB|GiB|TiB|PiB' | grep -v '\..MiB'"
|
2016-03-08 00:17:59 +00:00
|
|
|
echo "================================="
|
|
|
|
echo "Image size report (files > 10MiB)"
|
|
|
|
echo "================================="
|
|
|
|
else
|
|
|
|
echo "================="
|
|
|
|
echo "Image size report"
|
|
|
|
echo "================="
|
|
|
|
fi
|
|
|
|
|
2016-08-18 05:26:30 +00:00
|
|
|
eval ${du_output_show}
|
2016-04-07 04:45:43 +00:00
|
|
|
|
2016-03-08 00:17:59 +00:00
|
|
|
echo
|
|
|
|
echo "===== end image size report ====="
|
|
|
|
echo
|
|
|
|
|
|
|
|
$xtrace
|
|
|
|
fi
|
|
|
|
|
2016-08-18 05:26:30 +00:00
|
|
|
rm -f ${du_output}
|
|
|
|
|
2019-01-26 20:02:54 +00:00
|
|
|
if [ -n "$DIB_JOURNAL_SIZE" ]; then
|
|
|
|
journal_size="$DIB_JOURNAL_SIZE"
|
|
|
|
else
|
|
|
|
journal_size=64
|
|
|
|
fi
|
|
|
|
|
2017-01-29 23:52:40 +00:00
|
|
|
if [ "$DIB_ROOT_FSTYPE" = "ext4" ] ; then
|
2015-06-10 05:25:13 +00:00
|
|
|
# Very conservative to handle images being resized a lot
|
|
|
|
# We set journal size to 64M so our journal is large enough when we
|
|
|
|
# perform an FS resize.
|
2019-01-26 20:02:54 +00:00
|
|
|
MKFS_OPTS="-i 4096 -J size=$journal_size $MKFS_OPTS"
|
2015-11-05 21:49:28 +00:00
|
|
|
# Grow the image size to account for the journal, only if the user
|
|
|
|
# has not asked for a specific size.
|
|
|
|
if [ -z "$DIB_IMAGE_SIZE" ]; then
|
2019-01-26 20:02:54 +00:00
|
|
|
du_size=$(( $du_size + ($journal_size * 1024) ))
|
2015-11-05 21:49:28 +00:00
|
|
|
fi
|
2015-06-10 05:25:13 +00:00
|
|
|
fi
|
|
|
|
|
2019-08-14 05:24:03 +00:00
|
|
|
# EFI system partitions default to be quite large at 512mb for maximum
|
|
|
|
# compatability (see notes in
|
|
|
|
# 7fd52ba84180b4e749ccf4c9db8c49eafff46ea8) . We need to increase the
|
|
|
|
# total size to account for this, or we run out of space creating the
|
|
|
|
# final image. See if we have included the block-device-efi element,
|
|
|
|
# which implies we have a large EFI partition, and then pad the final
|
|
|
|
# image size.
|
|
|
|
if [[ ${IMAGE_ELEMENT} =~ "block-device-efi" ]]; then
|
|
|
|
echo "Expanding disk for EFI partition"
|
|
|
|
du_size=$(( $du_size + (525 * 1024) ))
|
|
|
|
fi
|
|
|
|
|
2015-11-05 21:49:28 +00:00
|
|
|
# Rounding down size so that is is a multiple of 64, works around a bug in
|
|
|
|
# qemu-img that may occur when compressing raw images that aren't a multiple
|
|
|
|
# of 64k. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1180021
|
Refactor: block-device handling (local loop)
Block device handling can be somewhat complex - especially
when taking things like md, lvm or encryption into account.
This patch factors out the creation and deletion of the local
loop image device handling into a python library.
The main propose of this patch is to implement the needed
infrastructure. Based on this, more advanced functions can be added.
Example: (advanced) partitioning, LVM, handling different boot
scenarios (BIOS, UEFI, ...), possibility of handling multiple images
(local loop image, iSCSI, physical hard disk, ...), handling of
different filesystems for different partitions / LVs.
Change-Id: Ib626b36a00f8a5dc3dbde8df3e2619a2438eaaf1
Signed-off-by: Andreas Florath <andreas@florath.net>
2016-05-21 19:32:35 +00:00
|
|
|
export DIB_IMAGE_SIZE=$(echo "$du_size" | awk ' { if ($1 % 64 != 0) print $1 + 64 - ( $1 % 64); else print $1; } ')
|
2014-02-16 04:06:11 +00:00
|
|
|
|
|
|
|
if [ -n "$MAX_ONLINE_RESIZE" ]; then
|
2015-03-17 17:06:38 +00:00
|
|
|
MKFS_OPTS="-E resize=$MAX_ONLINE_RESIZE $MKFS_OPTS"
|
2014-02-16 04:06:11 +00:00
|
|
|
fi
|
2013-05-06 19:17:42 +00:00
|
|
|
|
Refactor: block-device handling (local loop)
Block device handling can be somewhat complex - especially
when taking things like md, lvm or encryption into account.
This patch factors out the creation and deletion of the local
loop image device handling into a python library.
The main propose of this patch is to implement the needed
infrastructure. Based on this, more advanced functions can be added.
Example: (advanced) partitioning, LVM, handling different boot
scenarios (BIOS, UEFI, ...), possibility of handling multiple images
(local loop image, iSCSI, physical hard disk, ...), handling of
different filesystems for different partitions / LVs.
Change-Id: Ib626b36a00f8a5dc3dbde8df3e2619a2438eaaf1
Signed-off-by: Andreas Florath <andreas@florath.net>
2016-05-21 19:32:35 +00:00
|
|
|
export TMP_IMAGE_DIR
|
|
|
|
# Try the 'old fashioned' way calling the block device
|
|
|
|
# phase. If this gives no result, use the configuration based approach:
|
2013-04-02 00:25:25 +00:00
|
|
|
eval_run_d block-device "IMAGE_BLOCK_DEVICE="
|
2016-07-16 20:16:13 +00:00
|
|
|
|
Refactor: block-device handling (local loop)
Block device handling can be somewhat complex - especially
when taking things like md, lvm or encryption into account.
This patch factors out the creation and deletion of the local
loop image device handling into a python library.
The main propose of this patch is to implement the needed
infrastructure. Based on this, more advanced functions can be added.
Example: (advanced) partitioning, LVM, handling different boot
scenarios (BIOS, UEFI, ...), possibility of handling multiple images
(local loop image, iSCSI, physical hard disk, ...), handling of
different filesystems for different partitions / LVs.
Change-Id: Ib626b36a00f8a5dc3dbde8df3e2619a2438eaaf1
Signed-off-by: Andreas Florath <andreas@florath.net>
2016-05-21 19:32:35 +00:00
|
|
|
if [ -z ${IMAGE_BLOCK_DEVICE} ] ; then
|
2017-05-01 10:17:21 +00:00
|
|
|
# For compatibily reasons in addition to the YAML configuration
|
2017-04-22 07:49:22 +00:00
|
|
|
# there is the need to handle the old environment variables.
|
|
|
|
echo "image-size: ${DIB_IMAGE_SIZE}KiB" >> ${DIB_BLOCK_DEVICE_PARAMS_YAML}
|
|
|
|
|
2017-01-29 23:52:40 +00:00
|
|
|
if [ -n "${MKFS_OPTS}" ] ; then
|
|
|
|
echo "root-fs-opts: '${MKFS_OPTS}'" >> ${DIB_BLOCK_DEVICE_PARAMS_YAML}
|
|
|
|
fi
|
|
|
|
|
2017-05-01 10:17:21 +00:00
|
|
|
# After changeing the parameters, there is the need to
|
2017-04-22 07:49:22 +00:00
|
|
|
# re-run dib-block-device init because some value might
|
|
|
|
# change based on the new set parameters.
|
2017-05-02 03:29:34 +00:00
|
|
|
dib-block-device init
|
2017-04-22 07:49:22 +00:00
|
|
|
|
|
|
|
# values to dib-block-device: using the YAML config and
|
2017-05-02 03:29:34 +00:00
|
|
|
dib-block-device create
|
2017-05-01 07:19:49 +00:00
|
|
|
|
2017-06-06 02:09:24 +00:00
|
|
|
# This is the device (/dev/loopX). It's where to install the
|
|
|
|
# bootloader.
|
|
|
|
IMAGE_BLOCK_DEVICE=$(dib-block-device getval image-block-device)
|
|
|
|
export IMAGE_BLOCK_DEVICE
|
|
|
|
|
|
|
|
# Similar to above, but all mounted devices. This is handy for
|
|
|
|
# some bootloaders that have multi-partition layouts and want to
|
|
|
|
# copy things to different places other than just
|
|
|
|
# IMAGE_BLOCK_DEVICE. "eval" this into an array as needed
|
|
|
|
IMAGE_BLOCK_DEVICES=$(dib-block-device getval image-block-devices)
|
|
|
|
export IMAGE_BLOCK_DEVICES
|
2017-01-29 23:52:40 +00:00
|
|
|
|
|
|
|
# Write the fstab
|
|
|
|
dib-block-device writefstab
|
Refactor: block-device handling (local loop)
Block device handling can be somewhat complex - especially
when taking things like md, lvm or encryption into account.
This patch factors out the creation and deletion of the local
loop image device handling into a python library.
The main propose of this patch is to implement the needed
infrastructure. Based on this, more advanced functions can be added.
Example: (advanced) partitioning, LVM, handling different boot
scenarios (BIOS, UEFI, ...), possibility of handling multiple images
(local loop image, iSCSI, physical hard disk, ...), handling of
different filesystems for different partitions / LVs.
Change-Id: Ib626b36a00f8a5dc3dbde8df3e2619a2438eaaf1
Signed-off-by: Andreas Florath <andreas@florath.net>
2016-05-21 19:32:35 +00:00
|
|
|
fi
|
2016-07-16 20:16:13 +00:00
|
|
|
|
2017-06-06 02:09:24 +00:00
|
|
|
# XXX: needed?
|
|
|
|
LOOPDEV=${IMAGE_BLOCK_DEVICE}
|
2016-07-16 20:16:13 +00:00
|
|
|
|
2017-06-06 02:09:24 +00:00
|
|
|
# At this point, dib-block-device has created the raw image file
|
|
|
|
# (IMAGE_BLOCK_DEVICE) and mounted all the partitions under
|
|
|
|
# $TMP_BUILD_DIR/mnt for us. We can now copy into the final image.
|
Refactor: block-device handling (local loop)
Block device handling can be somewhat complex - especially
when taking things like md, lvm or encryption into account.
This patch factors out the creation and deletion of the local
loop image device handling into a python library.
The main propose of this patch is to implement the needed
infrastructure. Based on this, more advanced functions can be added.
Example: (advanced) partitioning, LVM, handling different boot
scenarios (BIOS, UEFI, ...), possibility of handling multiple images
(local loop image, iSCSI, physical hard disk, ...), handling of
different filesystems for different partitions / LVs.
Change-Id: Ib626b36a00f8a5dc3dbde8df3e2619a2438eaaf1
Signed-off-by: Andreas Florath <andreas@florath.net>
2016-05-21 19:32:35 +00:00
|
|
|
|
2017-05-01 10:17:21 +00:00
|
|
|
# 'mv' is not usable here - especially when a top level directory
|
|
|
|
# has the same name as a mount point of a partition. If so, 'mv'
|
|
|
|
# will complain:
|
|
|
|
# mv: inter-device move failed: '...' to '...'; \
|
|
|
|
# unable to remove target: Device or resource busy
|
|
|
|
# therefore a 'cp' and 'rm' approach is used.
|
|
|
|
sudo cp -ra ${TMP_BUILD_DIR}/built/* $TMP_BUILD_DIR/mnt
|
|
|
|
sudo rm -fr ${TMP_BUILD_DIR}/built/*
|
|
|
|
|
2013-04-02 00:25:25 +00:00
|
|
|
mount_proc_dev_sys
|
2018-10-12 01:03:26 +00:00
|
|
|
run_d pre-finalise
|
2013-04-02 00:25:25 +00:00
|
|
|
run_d_in_target finalise
|
2012-11-09 11:04:13 +00:00
|
|
|
finalise_base
|
2013-07-01 16:20:15 +00:00
|
|
|
|
2014-10-01 19:34:21 +00:00
|
|
|
for X in ${!IMAGE_TYPES[@]} ; do
|
2015-02-12 21:04:16 +00:00
|
|
|
if [[ " tar aci " =~ "${IMAGE_TYPES[$X]}" ]]; then
|
|
|
|
if [ "${IMAGE_TYPES[$X]}" = "aci" ]; then
|
|
|
|
sudo tar -C ${TMP_BUILD_DIR}/mnt -cf $IMAGE_NAME.aci --exclude ./sys \
|
|
|
|
--exclude ./proc --xattrs --xattrs-include=\* \
|
|
|
|
--transform 's,^.,rootfs,S' .
|
|
|
|
if [ -n "$ACI_MANIFEST" ]; then
|
|
|
|
cp $ACI_MANIFEST ${TMP_BUILD_DIR}/manifest
|
|
|
|
sudo tar -C ${TMP_BUILD_DIR} --append -f $IMAGE_NAME.aci manifest
|
|
|
|
else
|
|
|
|
echo "No ACI_MANIFEST specified. An ACI_MANIFEST must be specified for"
|
|
|
|
echo " this image to be usable."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
sudo tar -C ${TMP_BUILD_DIR}/mnt -cf $IMAGE_NAME.tar --exclude ./sys \
|
|
|
|
--exclude ./proc --xattrs --xattrs-include=\* .
|
|
|
|
fi
|
|
|
|
sudo chown $USER: $IMAGE_NAME.${IMAGE_TYPES[$X]}
|
2014-10-01 19:34:21 +00:00
|
|
|
unset IMAGE_TYPES[$X]
|
2016-12-18 01:59:07 +00:00
|
|
|
elif [ "${IMAGE_TYPES[$x]}" == "squashfs" ]; then
|
|
|
|
sudo mksquashfs ${TMP_BUILD_DIR}/mnt $IMAGE_NAME.squash -comp xz \
|
|
|
|
-noappend -root-becomes ${TMP_BUILD_DIR}/mnt \
|
|
|
|
-wildcards -e "proc/*" -e "sys/*" -no-recovery
|
2015-06-07 20:44:10 +00:00
|
|
|
elif [ "${IMAGE_TYPES[$X]}" == "docker" ]; then
|
|
|
|
sudo tar -C ${TMP_BUILD_DIR}/mnt -cf - --exclude ./sys \
|
|
|
|
--exclude ./proc --xattrs --xattrs-include=\* . \
|
2016-02-09 18:34:55 +00:00
|
|
|
| sudo docker import - $DOCKER_TARGET
|
2015-06-07 20:44:10 +00:00
|
|
|
unset IMAGE_TYPES[$X]
|
2014-10-01 19:34:21 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-04-28 22:33:59 +00:00
|
|
|
|
2015-06-04 08:46:18 +00:00
|
|
|
# Unmount and cleanup the /mnt and /build subdirectories, to save
|
|
|
|
# space before converting the image to some other format.
|
2017-06-06 02:09:24 +00:00
|
|
|
# XXX ? needed?
|
Refactor: block-device handling (local loop)
Block device handling can be somewhat complex - especially
when taking things like md, lvm or encryption into account.
This patch factors out the creation and deletion of the local
loop image device handling into a python library.
The main propose of this patch is to implement the needed
infrastructure. Based on this, more advanced functions can be added.
Example: (advanced) partitioning, LVM, handling different boot
scenarios (BIOS, UEFI, ...), possibility of handling multiple images
(local loop image, iSCSI, physical hard disk, ...), handling of
different filesystems for different partitions / LVs.
Change-Id: Ib626b36a00f8a5dc3dbde8df3e2619a2438eaaf1
Signed-off-by: Andreas Florath <andreas@florath.net>
2016-05-21 19:32:35 +00:00
|
|
|
export EXTRA_UNMOUNT=""
|
2012-11-09 11:04:13 +00:00
|
|
|
unmount_image
|
2017-05-02 02:13:01 +00:00
|
|
|
|
2017-05-02 03:29:34 +00:00
|
|
|
TMP_IMAGE_PATH=$(dib-block-device getval image-path)
|
2017-04-22 07:49:22 +00:00
|
|
|
export TMP_IMAGE_PATH
|
2016-07-16 20:16:13 +00:00
|
|
|
|
2017-06-06 02:09:24 +00:00
|
|
|
# remove all mounts
|
2017-05-02 03:29:34 +00:00
|
|
|
dib-block-device umount
|
|
|
|
dib-block-device cleanup
|
2016-07-16 20:16:13 +00:00
|
|
|
|
2015-06-04 08:46:18 +00:00
|
|
|
cleanup_build_dir
|
2013-07-01 16:20:15 +00:00
|
|
|
|
2016-06-24 18:29:19 +00:00
|
|
|
if [[ (! $IMAGE_ELEMENT =~ no-final-image) && "$IS_RAMDISK" == "0" ]]; then
|
|
|
|
has_raw_type=
|
2014-10-01 19:34:21 +00:00
|
|
|
for IMAGE_TYPE in ${IMAGE_TYPES[@]} ; do
|
2015-03-25 21:34:13 +00:00
|
|
|
# We have to do raw last because it is destructive
|
2015-04-01 20:28:44 +00:00
|
|
|
if [ "$IMAGE_TYPE" = "raw" ]; then
|
2015-03-25 21:34:13 +00:00
|
|
|
has_raw_type=1
|
2016-12-18 01:59:07 +00:00
|
|
|
elif [ "$IMAGE_TYPE" != "squashfs" ]; then
|
2015-03-25 21:34:13 +00:00
|
|
|
compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE
|
|
|
|
fi
|
2014-10-01 19:34:21 +00:00
|
|
|
done
|
2016-06-24 18:29:19 +00:00
|
|
|
if [ -n "$has_raw_type" ]; then
|
|
|
|
IMAGE_TYPE="raw"
|
|
|
|
compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE
|
|
|
|
fi
|
2015-03-25 21:34:13 +00:00
|
|
|
fi
|
2014-06-27 11:54:29 +00:00
|
|
|
|
2015-06-04 08:46:18 +00:00
|
|
|
# Remove the leftovers, i.e. the temporary image directory.
|
|
|
|
cleanup_image_dir
|
2015-01-27 18:45:55 +00:00
|
|
|
|
2018-05-23 01:14:42 +00:00
|
|
|
# Restore fd 1&2 from the outfilter.py redirect back to the original
|
|
|
|
# saved fd. Note small hack that we can't really wait properly for
|
|
|
|
# outfilter.py so put in a sleep (might be possible to use coproc for
|
|
|
|
# this...?)
|
|
|
|
#
|
|
|
|
# TODO(ianw): probably better to cleanup the exit handler a bit for
|
|
|
|
# this? We really want some helper functions that append to the exit
|
|
|
|
# handler so we can register multiple things.
|
|
|
|
set +o xtrace
|
|
|
|
echo "Build completed successfully"
|
|
|
|
exec 1>&3 2>&3
|
|
|
|
sleep 1
|
|
|
|
|
2014-10-01 19:34:21 +00:00
|
|
|
# All done!
|
|
|
|
trap EXIT
|