commit: 7f6002bac7dfcd9f262b291d27501c7fe35e9171
Author: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 11 22:51:24 2024 +0000
Commit: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Fri Oct 11 22:51:24 2024 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=7f6002ba
Force all absolute paths and add lots of debug output
Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>
targets/support/create-qcow2.sh | 52 ++++++++++++++++++++++-------------------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/targets/support/create-qcow2.sh b/targets/support/create-qcow2.sh
index 8ab12b9a..d1f69f14 100755
--- a/targets/support/create-qcow2.sh
+++ b/targets/support/create-qcow2.sh
@@ -30,7 +30,9 @@ source ${clst_shdir}/support/functions.sh
# Let's assume these are deps of catalyst and thus present.
#
-mymountpoint="${1}.tmp.mnt"
+mycurrentdir="$(pwd)"
+mymountpoint="${mycurrentdir}/${1}.tmp.mnt"
+myqcow2="${mycurrentdir}/${1}"
# TODO: find next free device
modprobe -q nbd
@@ -40,59 +42,61 @@ mydevice=/dev/nbd0
qcow2die() {
echo "Something went wrong. Cleaning up..."
# here we just ignore errors
- umount "${mymountpoint}/boot"
- umount "${mymountpoint}"
+ umount "${mydevice}p1"
+ umount "${mydevice}p2"
qemu-nbd -d "${mydevice}"
die "$@"
}
-# create a new qcow2 disk image file
-qemu-img create -f qcow2 "${1}.tmp.qcow2" ${clst_qcow2_size/%iB/} || qcow2die
"Cannot create qcow2 file"
+echo "Creating a new qcow2 disk image file"
+qemu-img create -f qcow2 "${myqcow2}.tmp.qcow2" ${clst_qcow2_size/%iB/} ||
qcow2die "Cannot create qcow2 file"
-# connect the qcow2 file to a network block device
-qemu-nbd -c ${mydevice} -f qcow2 "${1}.tmp.qcow2" || qcow2die "Cannot connect
qcow2 file to nbd0"
+echo "Connecting the qcow2 file to network block device ${mydevice}"
+qemu-nbd -c ${mydevice} -f qcow2 "${myqcow2}.tmp.qcow2" || qcow2die "Cannot
connect qcow2 file to nbd0"
-# create a GPT disklabel
+echo "Creating a GPT disklabel"
parted -s ${mydevice} mklabel gpt || qcow2die "Cannot create disklabel"
-# create an EFI boot partition
+echo "Creating an EFI boot partition"
parted -s ${mydevice} -- mkpart gentoo_efi fat32 1M ${clst_qcow2_efisize} ||
qcow2die "Cannot create EFI partition"
# mark it as EFI boot partition
parted -s ${mydevice} -- type 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B ||
qcow2die "Cannot set EFI partition UUID"
# note down name
mypartefi=${mydevice}p1
-# create the root partition
+echo "Creating the root partition"
parted -s ${mydevice} -- mkpart gentoo_root ${clst_qcow2_roottype}
${clst_qcow2_efisize}GiB -1M || qcow2die "Cannot create root partition"
# mark it as generic linux filesystem partition
parted -s ${mydevice} -- type 2 0FC63DAF-8483-4772-8E79-3D69D8477DE4 ||
qcow2die "Cannot set root partition UUID"
# note down name
mypartroot=${mydevice}p2
-# re-read the partition table
+echo "Re-reading the partition table"
partprobe ${mydevice} || qcow2die "Probing partition table failed"
-# make a vfat filesystem in p1
+echo "Making a vfat filesystem in p1"
mkfs.fat -F 32 ${mypartefi} || qcow2die "Formatting EFI partition failed"
-# make an xfs filesystem in p2
+echo "Making an xfs filesystem in p2"
mkfs.xfs ${mypartroot} || qcow2die "Formatting root partition failed"
-# mount things
+echo "Mounting things"
mkdir -p "${mymountpoint}" || qcow2die "Could not create root mount point"
mount ${mypartroot} "${mymountpoint}" || qcow2die "Could not mount root
partition"
mkdir -p "${mymountpoint}"/boot || qcow2die "Could not create boot mount point"
mount ${mypartefi} "${mymountpoint}/boot" || qcow2die "Could not mount boot
partition"
# copy contents in; the source is the stage dir and not any "iso content"
+echo "Copying files into the mounted directories"
cp -a "${clst_stage_path}"/* "${mymountpoint}/" || qcow2die "Could not copy
content into mounted image"
# at this point we have a working system
-# create a CONTENTS.gz file
-# warning: $1 does not contain a full path
-( pushd "${mymountpoint}" &> /dev/null ; ls -laR ; popd &> /dev/null ) >
"${1}.CONTENTS" || qcow2die "Could not create CONTENTS file"
+echo "Creating a CONTENTS file"
+cd "${mymountpoint}/" || qcow2die "Could not cd into mountpoint"
+ls -laR > "${myqcow2}.CONTENTS" || qcow2die "Could not create CONTENTS
file"
+cd "${mycurrentdir}" || qcow2die "Could not cd out of
mountpoint"
# note: the following must already have been done by the stage2:
# - rudimentary configuration
@@ -102,18 +106,18 @@ cp -a "${clst_stage_path}"/* "${mymountpoint}/" ||
qcow2die "Could not copy cont
# - enabling of services
# luckily efi requires no image magic, just regular files...
-# unmount things
+echo "Unmounting things"
umount "${mymountpoint}/boot" || qcow2die "Could not unmount boot partition"
umount "${mymountpoint}" || qcow2die "Could not unmount root partition"
-# disconnect the nbd
-qemu-nbd -d ${mydevice} || qcow2die "Could not disconnect nbd0"
+echo "Disconnecting ${mydevice}"
+qemu-nbd -d ${mydevice} || qcow2die "Could not disconnect ${mydevice}"
-# rewrite with stream compression
-qemu-img convert -c -O qcow2 "${1}.tmp.qcow2" "${1}" || qcow2die "Could not
compress QCOW2 file"
+echo "Rewriting the qcow2 with stream compression"
+qemu-img convert -c -O qcow2 "${myqcow2}.tmp.qcow2" "${myqcow2}" || qcow2die
"Could not compress QCOW2 file"
-# clean up
-rm "${1}.tmp.qcow2" || qcow2die "Could not delete uncompressed QCOW2 file"
+echo "Cleaning up"
+rm "${myqcow2}.tmp.qcow2" || qcow2die "Could not delete uncompressed QCOW2
file"
rmdir "${mymountpoint}/boot" || qcow2die "Could not remove boot mountpoint"
rmdir "${mymountpoint}" || qcow2die "Could not remove root mountpoint"