spec/posttrans: move grub config stub creation out of spec

Resolves: #RHEL-69944
Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
This commit is contained in:
Nicolas Frayer 2025-07-29 18:04:03 +02:00
parent 3b726150c9
commit f63b7984e5
3 changed files with 39 additions and 12 deletions

29
gen_grub_cfgstub Normal file
View File

@ -0,0 +1,29 @@
#!/bin/sh
set -eu
if [ $# -ne 2 ]
then
echo "Missing argument"
echo "Usage: script.sh GRUB_HOME EFI_HOME"
exit 1
fi
GRUB_HOME=$1
EFI_HOME=$2
# create a stub grub2 config in EFI
BOOT_UUID=$(grub2-probe --target=fs_uuid "${GRUB_HOME}")
GRUB_DIR=$(grub2-mkrelpath "${GRUB_HOME}")
echo "Generating grub stub config for drive " "${BOOT_UUID}"
echo "GRUB_DIR=" "${GRUB_DIR}"
echo "EFI_HOME=" "${EFI_HOME}"
cat << EOF > "${EFI_HOME}"/grub.cfg.stb
search --no-floppy --root-dev-only --fs-uuid --set=dev ${BOOT_UUID}
set prefix=(\$dev)${GRUB_DIR}
export \$prefix
configfile \$prefix/grub.cfg
EOF
mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg

View File

@ -522,6 +522,8 @@ install -m 700 %{3} $RPM_BUILD_ROOT%{efi_esp_dir}/%{3} \
%ifarch %{arm} \ %ifarch %{arm} \
install -D -m 700 %{2} $RPM_BUILD_ROOT%{efi_esp_boot}/BOOTARM.EFI \ install -D -m 700 %{2} $RPM_BUILD_ROOT%{efi_esp_boot}/BOOTARM.EFI \
%endif \ %endif \
install -D -m 700 %{SOURCE13} \\\
${RPM_BUILD_ROOT}/usr/bin/gen_grub_cfgstub \
install -D -m 700 unicode.pf2 \\\ install -D -m 700 unicode.pf2 \\\
${RPM_BUILD_ROOT}/boot/%{name}/fonts/unicode.pf2 \ ${RPM_BUILD_ROOT}/boot/%{name}/fonts/unicode.pf2 \
${RPM_BUILD_ROOT}/%{_bindir}/%{name}-editenv \\\ ${RPM_BUILD_ROOT}/%{_bindir}/%{name}-editenv \\\
@ -633,6 +635,7 @@ ln -s ../boot/%{name}/grub.cfg \\\
%attr(0700,root,root) %verify(not mtime) %{efi_esp_boot}/BOOTARM.EFI \ %attr(0700,root,root) %verify(not mtime) %{efi_esp_boot}/BOOTARM.EFI \
%endif \ %endif \
%attr(0700,root,root)/boot/%{name}/fonts \ %attr(0700,root,root)/boot/%{name}/fonts \
%attr(0700,root,root)/usr/bin/gen_grub_cfgstub \
%dir %attr(0700,root,root)/boot/loader/entries \ %dir %attr(0700,root,root)/boot/loader/entries \
%ghost %config(noreplace) %attr(0600,root,root)/boot/%{name}/grub.cfg \ %ghost %config(noreplace) %attr(0600,root,root)/boot/%{name}/grub.cfg \
%ghost %config(noreplace) %verify(not mtime) %attr(0700,root,root)%{efi_esp_dir}/grub.cfg \ %ghost %config(noreplace) %verify(not mtime) %attr(0700,root,root)%{efi_esp_dir}/grub.cfg \

View File

@ -16,7 +16,7 @@
Name: grub2 Name: grub2
Epoch: 1 Epoch: 1
Version: 2.06 Version: 2.06
Release: 110%{?dist} Release: 111%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more Summary: Bootloader with support for Linux, Multiboot and more
License: GPLv3+ License: GPLv3+
URL: http://www.gnu.org/software/grub/ URL: http://www.gnu.org/software/grub/
@ -34,6 +34,7 @@ Source9: strtoull_test.c
Source10: 20-grub.install Source10: 20-grub.install
Source11: grub.patches Source11: grub.patches
Source12: sbat.csv.in Source12: sbat.csv.in
Source13: gen_grub_cfgstub
%include %{SOURCE1} %include %{SOURCE1}
@ -361,23 +362,13 @@ if test -f ${EFI_HOME}/grub.cfg; then
fi fi
# create a stub grub2 config in EFI # create a stub grub2 config in EFI
BOOT_UUID=$(%{name}-probe --target=fs_uuid ${GRUB_HOME}) gen_grub_cfgstub $GRUB_HOME $EFI_HOME || :
GRUB_DIR=$(%{name}-mkrelpath ${GRUB_HOME})
cat << EOF > ${EFI_HOME}/grub.cfg.stb
search --no-floppy --root-dev-only --fs-uuid --set=dev ${BOOT_UUID}
set prefix=(\$dev)${GRUB_DIR}
export \$prefix
configfile \$prefix/grub.cfg
EOF
if test -f ${EFI_HOME}/grubenv; then if test -f ${EFI_HOME}/grubenv; then
cp -a ${EFI_HOME}/grubenv ${EFI_HOME}/grubenv.rpmsave cp -a ${EFI_HOME}/grubenv ${EFI_HOME}/grubenv.rpmsave
mv --force ${EFI_HOME}/grubenv ${GRUB_HOME}/grubenv mv --force ${EFI_HOME}/grubenv ${GRUB_HOME}/grubenv
fi fi
mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
%files common -f grub.lang %files common -f grub.lang
%dir %{_libdir}/grub/ %dir %{_libdir}/grub/
%dir %{_datarootdir}/grub/ %dir %{_datarootdir}/grub/
@ -547,6 +538,10 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
%endif %endif
%changelog %changelog
* Tue Jul 29 2025 Nicolas Frayer <nfrayer@redhat.com> 2.06-111
- spec/posttrans: move grub config stub creation out of spec
- Resolves: #RHEL-69944
* Fri Jun 6 2025 Nicolas Frayer <nfrayer@redhat.com> - 2.06-110 * Fri Jun 6 2025 Nicolas Frayer <nfrayer@redhat.com> - 2.06-110
- osdep/linux/getroot: Detect DDF container similar to IMSM - osdep/linux/getroot: Detect DDF container similar to IMSM
- Resolves: #RHEL-44336 - Resolves: #RHEL-44336