From ad71cde364b1de560ebc6abc0b50ebb1b1887945 Mon Sep 17 00:00:00 2001 From: layman Date: Tue, 8 Mar 2022 22:25:31 +0100 Subject: [PATCH] add skript to updateEfiStubs --- gentooup.sh | 9 ++++++ updateEfiStubsAndBootManager.sh | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 updateEfiStubsAndBootManager.sh diff --git a/gentooup.sh b/gentooup.sh index bcf9346..da14200 100755 --- a/gentooup.sh +++ b/gentooup.sh @@ -138,8 +138,17 @@ if [[ $(qlist -I gentoo-sources) != "" ]] ; then myemerge "${PORTAGE_OPTIONS[@]}" --deselect gentoo-sources:"${CURRENTKERNELVERSION/"-gentoo"/}" fi +<<<<<<< Updated upstream if [[ -n "$(which restart-services)" && $CHROOTED == "1" ]] ; then restart-services -l +======= +if [[ -n "$(which updateEfiStubsAndBootManager.sh)" && $CHROOTED == "1" ]] ; then + updateEfiStubsAndBootManager.sh +fi + +if [[ -n "$(which restart_services)" && $CHROOTED == "1" ]] ; then + restart_services -l +>>>>>>> Stashed changes fi echo "Started at $STARTDATE" echo " Ended at $(date -Iseconds)" diff --git a/updateEfiStubsAndBootManager.sh b/updateEfiStubsAndBootManager.sh new file mode 100755 index 0000000..bf4f292 --- /dev/null +++ b/updateEfiStubsAndBootManager.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +EFIPART="/boot" +STUBSFOLDER="/" +EFISTUBSLOC="$EFIPART/$STUBSFOLDER" +ORIGIN="/boot" +efidevice="$(findmnt -n -o SOURCE --target "$EFISTUBSLOC")" + +rootuuid=$(blkid -o value -s UUID "$(findmnt -n -o SOURCE --target "/")") + +cmdbase="ro quiet rd.luks.allow-discards rd.luks.uuid="af0f0b72-7895-4ce0-bfe4-967024fe3948" root=UUID=$rootuuid" + +function getDevice() { + local device="$1" + echo /dev/nvme0n1 +} + +function getPartNumber() { + echo 1 +} + +function toWinPath() { + echo $1 |sed -e "s,^/\+,,g" | sed -e "s,/,\\\\\\\\,g" +} + +function findInitramfs() { + local ver="$1" + if [[ -f "$EFIPART/initramfs-$ver.img" ]] ; then + echo initramfs-$ver.img + else + echo initramfs + fi +} + +shopt -s nullglob + +#if [[ ! "$(realpath "$ORIGIN")" == "$(realpath "$EFISTUBSLOC")" ]] ; then +# for image in /boot/vmlinuz* ; do +# if strings "$image" | grep -qi "EFI stub" ; then +# mv "$image" "$EFISTUBSLOC/" +# fi +# done +#fi +echo +for image in "$EFISTUBSLOC"/vmlinuz* ; do + if echo "$image" | grep -q old || ! strings "$image" | grep -qi "EFI stub" ; then + continue + fi + IFS='-' read base version <<< "$(basename "$image" | sed -e "s/\.efi//")" +# version="${SPLIT[@]:1:5}" + echo $version + imagepath="$STUBSFOLDER/$(basename $image)" + if ! efibootmgr | grep -q "$version" ; then + efibootmgr -d "$(getDevice "$efidevice")" -p $(getPartNumber "$efidevice") --create --label "Gentoo Kernel $version" --loader "$(toWinPath "$imagepath")" -u "$cmdbase initrd=$(findInitramfs $version)" + fi +done