partitioning: declare global readonly ROOT_PART_UUID for later hooks

- re-use local `root_part_uuid` instead of running blkid multiple times
This commit is contained in:
Ricardo Pardini 2023-07-03 19:39:20 +02:00 committed by Igor
parent f952ae89fb
commit a4c703dfb0

View File

@ -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