[PATCH 05/20] grub: generate configs boot/grub/grub.cfg and EFI/BOOT/grub.cfg if necessary
Anton Midyukov
antohami at altlinux.org
Wed Jan 8 07:24:17 MSK 2020
---
.../grub/scripts.d/20-propagator-ramdisk | 10 +++---
.../grub/scripts.d/20-propagator-rescue-hash | 8 +++--
features.in/grub/stage1/scripts.d/01-grub | 33 +++++++++++++++----
3 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/features.in/grub/scripts.d/20-propagator-ramdisk b/features.in/grub/scripts.d/20-propagator-ramdisk
index 059c60ef76..04470b6c85 100755
--- a/features.in/grub/scripts.d/20-propagator-ramdisk
+++ b/features.in/grub/scripts.d/20-propagator-ramdisk
@@ -5,13 +5,11 @@
cd "$WORKDIR"
-[ -d boot/grub ] || exit 0
+[ -f boot/grub/grub.cfg -o -f EFI/BOOT/grub.cfg ] || exit 0
-cfgs="$(find boot/grub -name '*.cfg')"
-[ -n "$cfgs" ] || {
- echo "${0##*/}: did not find any config under boot/grub " >&2
- exit 1
-}
+cfgs=
+[ ! -f boot/grub/grub.cfg ] || cfgs+='boot/grub/grub.cfg '
+[ ! -f EFI/BOOT/grub.cfg ] || cfgs+='EFI/BOOT/grub.cfg'
# apply size census while looking for potential squashfs images
find -maxdepth 1 -type f -size +1M \
diff --git a/features.in/grub/scripts.d/20-propagator-rescue-hash b/features.in/grub/scripts.d/20-propagator-rescue-hash
index 92c5972a65..3ca61591bc 100755
--- a/features.in/grub/scripts.d/20-propagator-rescue-hash
+++ b/features.in/grub/scripts.d/20-propagator-rescue-hash
@@ -5,12 +5,14 @@
cd "$WORKDIR"
-[ -d boot/grub ] || exit 0
+[ -f boot/grub/grub.cfg -o -f EFI/BOOT/grub.cfg ] || exit 0
-grep -qs "@rescue_hash@" boot/grub/*.cfg || exit 0
+cfgs=
+[ ! -f boot/grub/grub.cfg ] || cfgs+='boot/grub/grub.cfg '
+[ ! -f EFI/BOOT/grub.cfg ] || cfgs+='EFI/BOOT/grub.cfg'
find -maxdepth 1 -type f -name rescue \
| while read image; do
rescue_hash="$(sha256sum -b "$image" | cut -f1 -d' ')"
- sed -i "s, ÎÁ rescue_hash@,$rescue_hash," boot/grub/*.cfg
+ sed -i "s, ÎÁ rescue_hash@,$rescue_hash," $cfgs
done
diff --git a/features.in/grub/stage1/scripts.d/01-grub b/features.in/grub/stage1/scripts.d/01-grub
index 4c7d5e23ee..eeb3c49760 100755
--- a/features.in/grub/stage1/scripts.d/01-grub
+++ b/features.in/grub/stage1/scripts.d/01-grub
@@ -2,7 +2,8 @@
# gather grub configuration from snippets;
# copy modules; see also this feature's generate.mk
-CFG="grub.cfg"
+CFG="$WORKDIR/boot/grub/grub.cfg"
+CFG_EFI="$WORKDIR/EFI/BOOT/grub.cfg"
if [ -n "$GLOBAL_EFI_BOOTLOADER" -a ! "$GLOBAL_EFI_BOOTLOADER" = "grub-efi" ]; then
rm -fr "$WORKDIR/boot"
@@ -27,21 +28,41 @@ if [ -n "${GRUB_FILES% }" ]; then
fi
# number ordering sponsored by shell's pathname expansion
-grep -hv '^#' .in/[0-9][0-9]*.cfg > "$CFG"
+case "$GLOBAL_BOOTLOADER" in
+ grubx86boot)
+ grep -hv '^#' $(find .in/*.cfg -not -name *_efi.cfg) > "$CFG" ;;
+ ieee1275boot)
+ grep -hv '^#' $(find .in/*.cfg -not -name *_efi.cfg -not -name *_x86.cfg) > "$CFG" ;;
+esac
+
+if [ "$GLOBAL_EFI_BOOTLOADER" = "grub-efi" ]; then
+ mkdir -p "$WORKDIR/EFI/BOOT"
+ grep -hv '^#' $(find .in/*.cfg -not -name *_x86.cfg) > "$CFG_EFI"
+fi
# there should be DEFAULT directive there (at least for alterator-netinst)
-if ! grep -i '^default' .in/[0-9][0-9]*.cfg; then
- DEFAULT="$(grep -i '\-\-id ' .in/[0-9][0-9]*.cfg | head -1 | rev| cut -f2 -d' ' |rev)"
+default_change() {
+local CFG=$1
+if ! grep -i '^default' "$CFG"; then
+ DEFAULT="$(grep -i '\-\-id ' "$CFG" | head -1 | rev| cut -f2 -d' ' |rev)"
if [ -n "$DEFAULT" ]; then
echo "default=$DEFAULT" >> "$CFG"
else
- echo "error: no DEFAULT or UI directive and cannot guess" >&2
+ echo "error: no DEFAULT or UI directive and cannot guess for $CFG" >&2
exit 1
fi
fi
+}
+
+[ ! -f "$CFG" ] || default_change "$CFG"
+[ ! -f "$CFG_EFI" ] || default_change "$CFG_EFI"
# snippets are not going into the actual image
-if [ "$DEBUG" != 2 ]; then rm -r .in/; fi
+if [ "$DEBUG" != 2 ]; then
+ rm -r .in/
+ cd ..
+ [ -f "$CFG" ] || rm -r grub/
+fi
# NB: there will be final macro expansion based on actual image sizes
# done by features.in/grub/scripts.d/20-propagator-ramdisk
--
2.24.1
--------------57A0C61BE7D9EDE338E3E6C8
Content-Type: text/x-patch;
name="0006-grub-add-suffix-_efi-for-EFI-configs.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="0006-grub-add-suffix-_efi-for-EFI-configs.patch"
More information about the devel-distro
mailing list