#!/bin/bash -e IMG_FILE="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img" unmount_image ${IMG_FILE} rm -f ${IMG_FILE} rm -rf ${ROOTFS_DIR} mkdir -p ${ROOTFS_DIR} BOOT_SIZE=$(du --apparent-size -s ${EXPORT_ROOTFS_DIR}/boot --block-size=1 | cut -f 1) TOTAL_SIZE=$(du --apparent-size -s ${EXPORT_ROOTFS_DIR} --exclude var/cache/apt/archives --block-size=1 | cut -f 1) IMG_SIZE=$((BOOT_SIZE + TOTAL_SIZE + (800 * 1024 * 1024))) truncate -s ${IMG_SIZE} ${IMG_FILE} fdisk -H 255 -S 63 ${IMG_FILE} < /dev/null mkfs.ext4 -L rootfs-O $ROOT_FEATURES $ROOT_DEV > /dev/null mount -v $ROOT_DEV ${ROOTFS_DIR} -t ext4 mkdir -p ${ROOTFS_DIR}/boot mount -v $BOOT_DEV ${ROOTFS_DIR}/boot -t vfat rsync -aHAXx --exclude var/cache/apt/archives ${EXPORT_ROOTFS_DIR}/ ${ROOTFS_DIR}/