diff --git a/scripts/functions.sh b/scripts/functions.sh index 37f46cc..348bf4c 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -735,10 +735,14 @@ gentoo_chroot() { mount --make-rslave "$ROOT_MOUNTPOINT/dev"; } || exit 1 ) || die "Could not mount virtual filesystems" + # Cache lsblk output, because apparently it doesn't work correctly in chroot (returns almost no info for devices, e.g. empty uuids) + cache_lsblk_output + # Execute command einfo "Chrooting..." EXECUTED_IN_CHROOT=true \ - TMP_DIR=$TMP_DIR \ + TMP_DIR="$TMP_DIR" \ + CACHED_LSBLK_OUTPUT="$CACHED_LSBLK_OUTPUT" \ exec chroot -- "$ROOT_MOUNTPOINT" "$GENTOO_INSTALL_REPO_DIR/scripts/main_chroot.sh" "$@" \ || die "Failed to chroot into '$ROOT_MOUNTPOINT'" } diff --git a/scripts/utils.sh b/scripts/utils.sh index 3ed7104..0a4d1bc 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -158,13 +158,20 @@ get_device_by_uuid() { get_device_by_blkid_field 'UUID' "$1" } +cache_lsblk_output() { + CACHED_LSBLK_OUTPUT="$(lsblk --all --path --pairs --output NAME,PTUUID,PARTUUID)" \ + || die "Error while executing lsblk to cache output" +} + get_device_by_ptuuid() { - echo "get_device_by_ptuuid '$ptuuid'" local ptuuid="${1,,}" local dev - dev="$(lsblk --all --path --pairs --output NAME,PTUUID,PARTUUID)" \ - || die "Error while executing lsblk to find PTUUID=$ptuuid" - echo "lsblkout: $dev" + if [[ -n $CACHED_LSBLK_OUTPUT ]]; then + dev="$CACHED_LSBLK_OUTPUT" + else + dev="$(lsblk --all --path --pairs --output NAME,PTUUID,PARTUUID)" \ + || die "Error while executing lsblk to find PTUUID=$ptuuid" + fi dev="$(grep "ptuuid=\"$ptuuid\" partuuid=\"\"" <<< "${dev,,}")" \ || die "Could not find PTUUID=... in lsblk output" dev="${dev%'" ptuuid='*}"