From a4c703dfb0b8d69156e2ad4c81d8452f7ea6a2e1 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Mon, 3 Jul 2023 19:39:20 +0200 Subject: [PATCH] partitioning: declare global readonly `ROOT_PART_UUID` for later hooks - re-use local `root_part_uuid` instead of running blkid multiple times --- lib/functions/image/partitioning.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/functions/image/partitioning.sh b/lib/functions/image/partitioning.sh index 11795ecf58..99a15ba99d 100644 --- a/lib/functions/image/partitioning.sh +++ b/lib/functions/image/partitioning.sh @@ -236,6 +236,9 @@ function prepare_partitions() { # stage: create fs, mount partitions, create fstab rm -f $SDCARD/etc/fstab + + declare root_part_uuid="uninitialized" + if [[ -n $rootpart ]]; then local rootdevice="${LOOP}p${rootpart}" @@ -256,13 +259,19 @@ function prepare_partitions() { local fscreateopt="-o compress-force=${BTRFS_COMPRESSION}" fi wait_for_disk_sync "after mkfs" # force writes to be really flushed - display_alert "Mounting rootfs" "$rootdevice" + + # store in readonly global for usage in later hooks + root_part_uuid="$(blkid -s UUID -o value ${LOOP}p${rootpart})" + declare -g -r ROOT_PART_UUID="${root_part_uuid}" + + display_alert "Mounting rootfs" "$rootdevice (UUID=${ROOT_PART_UUID})" run_host_command_logged mount ${fscreateopt} $rootdevice $MOUNT/ + # create fstab (and crypttab) entry local rootfs if [[ $CRYPTROOT_ENABLE == yes ]]; then # map the LUKS container partition via its UUID to be the 'cryptroot' device - echo "$ROOT_MAPPER UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart}) none luks" >> $SDCARD/etc/crypttab + echo "$ROOT_MAPPER UUID=${root_part_uuid} none luks" >> $SDCARD/etc/crypttab rootfs=$rootdevice # used in fstab else rootfs="UUID=$(blkid -s UUID -o value $rootdevice)" @@ -303,7 +312,7 @@ function prepare_partitions() { if [[ -f $SDCARD/boot/armbianEnv.txt ]]; then display_alert "Found armbianEnv.txt" "${SDCARD}/boot/armbianEnv.txt" "debug" if [[ $CRYPTROOT_ENABLE == yes ]]; then - echo "rootdev=$rootdevice cryptdevice=UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart}):$ROOT_MAPPER" >> "${SDCARD}/boot/armbianEnv.txt" + echo "rootdev=$rootdevice cryptdevice=UUID=${root_part_uuid}:$ROOT_MAPPER" >> "${SDCARD}/boot/armbianEnv.txt" else echo "rootdev=$rootfs" >> "${SDCARD}/boot/armbianEnv.txt" fi @@ -322,7 +331,7 @@ function prepare_partitions() { display_alert "Found boot.ini" "${SDCARD}/boot/boot.ini" "debug" sed -i -e "s/rootfstype \"ext4\"/rootfstype \"$ROOTFS_TYPE\"/" $SDCARD/boot/boot.ini if [[ $CRYPTROOT_ENABLE == yes ]]; then - rootpart="UUID=$(blkid -s UUID -o value ${LOOP}p${rootpart})" + rootpart="UUID=${root_part_uuid}" sed -i 's/^setenv rootdev .*/setenv rootdev "\/dev\/mapper\/'$ROOT_MAPPER' cryptdevice='$rootpart':'$ROOT_MAPPER'"/' $SDCARD/boot/boot.ini else sed -i 's/^setenv rootdev .*/setenv rootdev "'$rootfs'"/' $SDCARD/boot/boot.ini