diff --git a/cleanup_image b/cleanup_image index 195f1ac..c48771f 100755 --- a/cleanup_image +++ b/cleanup_image @@ -1,30 +1,24 @@ #!/bin/sh -export IMG=$1 +export INSTALLDIR=$1 . ./builder_setup set -e if ! [ $# -eq 1 ]; then - echo "usage $0 " + echo "usage $0 " exit 1 fi -if ! [ -f $IMG ]; then - echo $IMG does not exist +if ! [ -d $INSTALLDIR ]; then + echo $INSTALLDIR does not exist exit 1 fi -ls -als $IMG -mount -o loop $IMG mnt || exit 1 -export INSTALLDIR=`pwd`/mnt/ echo "--> Cleaning up image file..." $SCRIPTSDIR/09_cleanup.sh echo "--> Compacting image file..." -fstrim mnt/ -umount mnt -ls -als $IMG - +fstrim -v "$INSTALLDIR" diff --git a/prepare_image b/prepare_image index d739da7..83d5bb6 100755 --- a/prepare_image +++ b/prepare_image @@ -45,15 +45,41 @@ echo "-> Preparing instalation of ${DIST} template..." # ------------------------------------------------------------------------------ if [ -f "${IMG}" ]; then echo "-> Image file already exists, assuming *update*..." + if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then + IMG_LOOP=$(losetup -P -f --show "$IMG") + IMG_DEV=${IMG_LOOP}p1 + else + IMG_LOOP=$(losetup -f --show "$IMG") + IMG_DEV=${IMG_LOOP} + fi else echo "-> Initializing empty image..." truncate -s 10G "${IMG}" || exit 1 + if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then + echo "-> Creating partition table" + # have static UUIDs to make partition table reproducible + sfdisk "$IMG" < Creating filesystem..." - mkfs.ext4 -q -F "${IMG}" || exit 1 + mkfs.ext4 -q -F "${IMG_DEV}" || exit 1 fi -mount -o loop "${IMG}" "${INSTALLDIR}" || exit 1 +mount "${IMG_DEV}" "${INSTALLDIR}" || exit 1 trap "umount_kill $(readlink -m ${INSTALLDIR})" EXIT "${SCRIPTSDIR}/01_install_core.sh" @@ -70,5 +96,6 @@ trap - EXIT echo "-> Unmounting prepared_image..." umount_kill "$(readlink -m ${INSTALLDIR})" || true +losetup -d ${IMG_LOOP} exit ${RETCODE} diff --git a/qubeize_image b/qubeize_image index d3b81cf..9d2dbb2 100755 --- a/qubeize_image +++ b/qubeize_image @@ -50,6 +50,7 @@ function cleanup() { trap - ERR trap umount_kill "$PWD/mnt" || true + losetup -d ${IMG_LOOP} exit $errval } trap cleanup ERR @@ -65,7 +66,14 @@ cp "$CLEANIMG" "$IMG" || exit 1 echo "--> Mounting $IMG" mkdir -p mnt -mount -o loop "$IMG" mnt || exit 1 +if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then + IMG_LOOP=$(losetup -P -f --show "$IMG") + IMG_DEV=${IMG_LOOP}p1 +else + IMG_LOOP=$(losetup -f --show "$IMG") + IMG_DEV=${IMG_LOOP} +fi +mount "$IMG_DEV" mnt || exit 1 export INSTALLDIR=mnt # ------------------------------------------------------------------------------ @@ -100,14 +108,18 @@ echo "--> Linking /usr/local to /rw/usrlocal..." mv mnt/usr/local mnt/usr/local.orig ln -sf /rw/usrlocal mnt/usr/local +echo "Reducing image size (calling cleanup_image)..." +ls -als $IMG +./cleanup_image "$INSTALLDIR" +ls -als $IMG + # ------------------------------------------------------------------------------ # Finsh - unmount image # ------------------------------------------------------------------------------ echo "--> Unmounting $IMG" umount_kill "$PWD/mnt" || true +losetup -d ${IMG_LOOP} echo "Qubeized image stored at: $IMG" -echo "Reducing image size (calling cleanup_image)..." -./cleanup_image "$IMG" chown -R --reference=. qubeized_images/$NAME