cache lsblk output

This commit is contained in:
oddlama 2020-10-08 22:16:26 +02:00
parent 87b75b2466
commit fdbc6fb3aa
No known key found for this signature in database
GPG Key ID: 88EA325D51D53908
2 changed files with 16 additions and 5 deletions

View File

@ -735,10 +735,14 @@ gentoo_chroot() {
mount --make-rslave "$ROOT_MOUNTPOINT/dev"; } || exit 1 mount --make-rslave "$ROOT_MOUNTPOINT/dev"; } || exit 1
) || die "Could not mount virtual filesystems" ) || 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 # Execute command
einfo "Chrooting..." einfo "Chrooting..."
EXECUTED_IN_CHROOT=true \ 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" "$@" \ exec chroot -- "$ROOT_MOUNTPOINT" "$GENTOO_INSTALL_REPO_DIR/scripts/main_chroot.sh" "$@" \
|| die "Failed to chroot into '$ROOT_MOUNTPOINT'" || die "Failed to chroot into '$ROOT_MOUNTPOINT'"
} }

View File

@ -158,13 +158,20 @@ get_device_by_uuid() {
get_device_by_blkid_field 'UUID' "$1" 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() { get_device_by_ptuuid() {
echo "get_device_by_ptuuid '$ptuuid'"
local ptuuid="${1,,}" local ptuuid="${1,,}"
local dev local dev
if [[ -n $CACHED_LSBLK_OUTPUT ]]; then
dev="$CACHED_LSBLK_OUTPUT"
else
dev="$(lsblk --all --path --pairs --output NAME,PTUUID,PARTUUID)" \ dev="$(lsblk --all --path --pairs --output NAME,PTUUID,PARTUUID)" \
|| die "Error while executing lsblk to find PTUUID=$ptuuid" || die "Error while executing lsblk to find PTUUID=$ptuuid"
echo "lsblkout: $dev" fi
dev="$(grep "ptuuid=\"$ptuuid\" partuuid=\"\"" <<< "${dev,,}")" \ dev="$(grep "ptuuid=\"$ptuuid\" partuuid=\"\"" <<< "${dev,,}")" \
|| die "Could not find PTUUID=... in lsblk output" || die "Could not find PTUUID=... in lsblk output"
dev="${dev%'" ptuuid='*}" dev="${dev%'" ptuuid='*}"