From 587c7bae95048701381599ec7bb0f1396ba1ffe2 Mon Sep 17 00:00:00 2001 From: Andrey Arapov Date: Sun, 2 Feb 2020 19:07:46 +0100 Subject: [PATCH] TAILORED: build 4k sector sized templates only https://github.com/QubesOS/qubes-issues/issues/4974#issuecomment-575955927 --- mount_root.sh | 2 +- prepare_image | 23 +++++++++++++++++------ qubeize_image | 9 +++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/mount_root.sh b/mount_root.sh index 28ec7d3..b646eac 100755 --- a/mount_root.sh +++ b/mount_root.sh @@ -18,7 +18,7 @@ mkdir -p mnt MNTDIR=$(pwd)/mnt -LOOP=$(/sbin/losetup -f --show -o $OFFSET $ROOTIMG) +LOOP=$(/sbin/losetup -b 4096 -f --show -o $OFFSET $ROOTIMG) if [ x$LOOP = x ] ; then echo "Cannot setup loopback device for the $ROOTIMG file -- perhaps a permissions problem?" diff --git a/prepare_image b/prepare_image index d2d679f..f887214 100755 --- a/prepare_image +++ b/prepare_image @@ -50,10 +50,13 @@ 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=$(/sbin/losetup -P -f --show "$IMG") + IMG_LOOP=$(/sbin/losetup -b 4096 -P -f --show "$IMG") + # BUG: losetup's partscan (-P) does nothing when trying 4096 sectors formatted images on a 512 sectors backing device. + # Hence it needs an additional partprobe run. + /sbin/partprobe $IMG_LOOP IMG_DEV=${IMG_LOOP}p3 else - IMG_LOOP=$(/sbin/losetup -f --show "$IMG") + IMG_LOOP=$(/sbin/losetup -b 4096 -f --show "$IMG") IMG_DEV=${IMG_LOOP} fi else @@ -62,8 +65,12 @@ else 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..." /sbin/mkfs.ext4 -q -F "${IMG_DEV}" || exit 1 fi +# make sure the IMG_DEV is present +c=0; while [ ! -b $IMG_DEV ]; do sleep 1; c=$((c+1)); [ $c -ge 5 ] && break; done; unset c mount "${IMG_DEV}" "${INSTALLDIR}" || exit 1 trap "umount_kill $(readlink -m ${INSTALLDIR})" EXIT "${SCRIPTSDIR}/01_install_core.sh" diff --git a/qubeize_image b/qubeize_image index d49278c..8a64829 100755 --- a/qubeize_image +++ b/qubeize_image @@ -72,12 +72,17 @@ fi echo "--> Mounting $IMG" mkdir -p mnt if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then - IMG_LOOP=$(/sbin/losetup -P -f --show "$IMG") + IMG_LOOP=$(/sbin/losetup -b 4096 -P -f --show "$IMG") + # BUG: losetup's partscan (-P) does nothing when trying 4096 sectors formatted images on a 512 sectors backing device. + # Hence it needs an additional partprobe run. + /sbin/partprobe $IMG_LOOP IMG_DEV=${IMG_LOOP}p3 else - IMG_LOOP=$(/sbin/losetup -f --show "$IMG") + IMG_LOOP=$(/sbin/losetup -b 4096 -f --show "$IMG") IMG_DEV=${IMG_LOOP} fi +# make sure the IMG_DEV is present +c=0; while [ ! -b $IMG_DEV ]; do sleep 1; c=$((c+1)); [ $c -ge 5 ] && break; done; unset c mount "$IMG_DEV" mnt || exit 1 export INSTALLDIR=mnt