Do not duplicate grub.cfg in efiboot.img

Instruct the embeded grub.cfg to search for a volume with a
`/.disk/%UUID_SEARCH_FILENAME%.uuid` file and load `/EFI/BOOT/grub.cfg`
from it.

This avoid duplicating GRUB configuration files in two places (ISO 9660
and FAT) and ensures there is no confusion about which is the _correct_
configuration file.

Since nothing besides EFI binaries is copied to `efibootimg`, the
`_make_common_bootmode_grub_copy_to_efibootimg` function is removed.

Fixes #208
This commit is contained in:
nl6720 2023-01-28 13:08:49 +02:00
parent 40e09767f0
commit f5ade898f9
No known key found for this signature in database
GPG Key ID: 5CE88535E188D369
2 changed files with 36 additions and 20 deletions

View File

@ -20,6 +20,8 @@ Changed
- Identify the ISO volume via a UUID instead of a file system label to avoid collisions of multiple ISOs created in the
same month.
- Honor ``SOURCE_DATE_EPOCH`` in the ``date`` command used by ``profiledef.sh`` of the shipped profiles.
- Do not duplicate ``grub.cfg`` in both ISO 9660 and the EFI system partition / El Torito image. GRUB will search for
the ISO volume and load the ``grub.cfg`` from there.
Removed
-------

View File

@ -544,18 +544,7 @@ _make_efibootimg() {
mmd -i "${efibootimg}" ::/EFI ::/EFI/BOOT
}
# Copy GRUB files to efiboot.img which is used by both IA32 UEFI and x64 UEFI.
_make_common_bootmode_grub_copy_to_efibootimg() {
local files_to_copy=()
files_to_copy+=("${work_dir}/grub/"*)
if compgen -G "${profile}/grub/!(*.cfg)" &> /dev/null; then
files_to_copy+=("${profile}/grub/"!(*.cfg))
fi
mcopy -i "${efibootimg}" "${files_to_copy[@]}" ::/EFI/BOOT/
}
# Copy GRUB files to efiboot.img which is used by both IA32 UEFI and x64 UEFI.
# Copy GRUB files to ISO 9660 which is used by both IA32 UEFI and x64 UEFI
_make_common_bootmode_grub_copy_to_isofs() {
local files_to_copy=()
@ -563,6 +552,7 @@ _make_common_bootmode_grub_copy_to_isofs() {
if compgen -G "${profile}/grub/!(*.cfg)" &> /dev/null; then
files_to_copy+=("${profile}/grub/"!(*.cfg))
fi
install -d -m 0755 -- "${isofs_dir}/EFI/BOOT"
install -m 0644 -- "${files_to_copy[@]}" "${isofs_dir}/EFI/BOOT/"
}
@ -586,9 +576,6 @@ _make_common_bootmode_grub_cfg(){
s|%UUID_SEARCH_FILENAME%|${uuid_search_filename}|g" \
"${_cfg}" > "${work_dir}/grub/${_cfg##*/}"
done
# Add all GRUB files to the list of files used to calculate the required FAT image size.
efiboot_files+=("${work_dir}/grub/"
"${profile}/grub/"!(*.cfg))
# Prepare grub.cfg that will be embedded inside the GRUB binaries
IFS='' read -r -d '' grubembedcfg <<'EOF' || true
@ -597,12 +584,39 @@ if ! [ -d "$cmdpath" ]; then
# launched from a case-insensitive FAT-formatted EFI system partition, but it seemingly cannot access that partition
# and sets cmdpath to the whole cd# device which has case-sensitive ISO 9660 + Rock Ridge + Joliet file systems.
# See https://gitlab.archlinux.org/archlinux/archiso/-/issues/183 and https://savannah.gnu.org/bugs/?62886
if regexp --set=1:isodevice '^(\([^)]+\))\/?[Ee][Ff][Ii]\/[Bb][Oo][Oo][Tt]\/?$' "$cmdpath"; then
cmdpath="${isodevice}/EFI/BOOT"
if regexp --set=1:archiso_bootdevice '^\(([^)]+)\)\/?[Ee][Ff][Ii]\/[Bb][Oo][Oo][Tt]\/?$' "${cmdpath}"; then
set cmdpath="(${archiso_bootdevice})/EFI/BOOT"
set ARCHISO_HINT="${archiso_bootdevice}"
fi
fi
configfile "${cmdpath}/grub.cfg"
# Prepare a hint for the search command using the device in cmdpath
if [ -z "${ARCHISO_HINT}" ]; then
regexp --set=1:ARCHISO_HINT '^\(([^)]+)\)' "${cmdpath}"
fi
# Search for the ISO volume
if search --no-floppy --set=archiso_device --file '/.disk/%UUID_SEARCH_FILENAME%.uuid' --hint "${ARCHISO_HINT}"; then
set ARCHISO_HINT="${archiso_device}"
if probe --set ARCHISO_UUID --fs-uuid "${ARCHISO_HINT}"; then
export ARCHISO_UUID
fi
else
echo "Could not find a volume with a '/.disk/%UUID_SEARCH_FILENAME%.uuid' file on it!"
fi
# Load grub.cfg
if [ "${ARCHISO_HINT}" == 'memdisk' -o -z "${ARCHISO_HINT}" ]; then
echo 'Could not find the ISO volume!'
elif [ -e "(${ARCHISO_HINT})/EFI/BOOT/grub.cfg" ]; then
export ARCHISO_HINT
set root="${ARCHISO_HINT}"
configfile "(${ARCHISO_HINT})/EFI/BOOT/grub.cfg"
else
echo "File '(${ARCHISO_HINT})/EFI/BOOT/grub.cfg' not found!"
fi
EOF
grubembedcfg="${grubembedcfg//'%UUID_SEARCH_FILENAME%'/"${uuid_search_filename}"}"
printf '%s\n' "$grubembedcfg" > "${work_dir}/grub-embed.cfg"
}
@ -645,7 +659,7 @@ _make_bootmode_uefi-ia32.grub.esp() {
mcopy -i "${efibootimg}" "${work_dir}/BOOTIA32.EFI" ::/EFI/BOOT/BOOTIA32.EFI
# Copy GRUB files
_run_once _make_common_bootmode_grub_copy_to_efibootimg
_run_once _make_common_bootmode_grub_copy_to_isofs
if [[ -e "${pacstrap_dir}/usr/share/edk2-shell/ia32/Shell_Full.efi" ]]; then
mcopy -i "${efibootimg}" "${pacstrap_dir}/usr/share/edk2-shell/ia32/Shell_Full.efi" ::/shellia32.efi
@ -716,7 +730,7 @@ _make_bootmode_uefi-x64.grub.esp() {
mcopy -i "${efibootimg}" "${work_dir}/BOOTx64.EFI" ::/EFI/BOOT/BOOTx64.EFI
# Copy GRUB files
_run_once _make_common_bootmode_grub_copy_to_efibootimg
_run_once _make_common_bootmode_grub_copy_to_isofs
if [[ -e "${pacstrap_dir}/usr/share/edk2-shell/x64/Shell_Full.efi" ]]; then
mcopy -i "${efibootimg}" "${pacstrap_dir}/usr/share/edk2-shell/x64/Shell_Full.efi" ::/shellx64.efi