mkarchiso: always create /boot/grub/grubenv and /boot/grub/loopback.cfg

Even if GRUB is not used as a boot loader for the ISO, create a
`/boot/grub/grubenv` file in the ISO 9660 file system. If a
`loopback.cfg` file exists in the profile's `grub` directory, copy it
to `/boot/grub/loopback.cfg` on the ISO.

This ensures the funtionality will not be lost if the used boot loaders
are changed.
This commit is contained in:
nl6720 2023-09-28 10:45:43 +03:00
parent 4280af7474
commit a75d7e5f7e
No known key found for this signature in database
GPG Key ID: 5CE88535E188D369

View File

@ -420,6 +420,10 @@ _make_bootmodes() {
for bootmode in "${bootmodes[@]}"; do
_run_once "_make_bootmode_${bootmode}"
done
if [[ "${bootmodes[*]}" != *grub* ]]; then
_run_once _make_common_grubenv_and_loopbackcfg
fi
}
# Copy kernel and initramfs to ISO 9660
@ -638,6 +642,40 @@ EOF
>"${work_dir}/grub/grubenv"
}
# Create GRUB specific configuration files when GRUB is not used as a boot loader
_make_common_grubenv_and_loopbackcfg() {
local search_filename
install -d -m 0755 -- "${isofs_dir}/boot/grub"
# Create a /boot/grub/YYYY-mm-dd-HH-MM-SS-00.uuid file on ISO 9660. GRUB will search for it to find the ISO
# volume. This is similar to what grub-mkrescue does, except it places the file in /.disk/, but we opt to use a
# directory that does not start with a dot to avoid it being accidentally missed when copying the ISO's contents.
search_filename="/boot/grub/${iso_uuid}.uuid"
: >"${isofs_dir}/${search_filename}"
# Write grubenv
printf '%.1024s' \
"$(printf '# GRUB Environment Block\nNAME=%s\nVERSION=%s\nARCHISO_LABEL=%s\nINSTALL_DIR=%s\nARCH=%s\nARCHISO_SEARCH_FILENAME=%s\n%s' \
"${iso_name}" \
"${iso_version}" \
"${iso_label}" \
"${install_dir}" \
"${arch}" \
"${search_filename}" \
"$(printf '%0.1s' "#"{1..1024})")" \
>"${isofs_dir}/boot/grub/grubenv"
# Copy loopback.cfg to /boot/grub/ on ISO 9660
if [[ -e "${profile}/grub/loopback.cfg" ]]; then
sed "s|%ARCHISO_LABEL%|${iso_label}|g;
s|%ARCHISO_UUID%|${iso_uuid}|g;
s|%INSTALL_DIR%|${install_dir}|g;
s|%ARCH%|${arch}|g;
s|%ARCHISO_SEARCH_FILENAME%|${search_filename}|g" \
"${profile}/grub/loopback.cfg" >"${isofs_dir}/boot/grub/loopback.cfg"
fi
}
_make_bootmode_uefi-ia32.grub.esp() {
local grubmodules=()
@ -1800,8 +1838,9 @@ _make_version() {
fi
if [[ "${buildmode}" == "iso" ]]; then
# Write grubenv with version information to ISO 9660
# TODO: after sufficient time has passed, do not create this file anymore when GRUB boot modes are used.
# _make_common_bootmode_grub_cfg already creates ${isofs_dir}/boot/grub/grubenv
# TODO: after sufficient time has passed, do not create this file anymore.
# _make_common_bootmode_grub_cfg and _make_common_grubenv_and_loopbackcfg already create a
# ${isofs_dir}/boot/grub/grubenv file
rm -f -- "${isofs_dir}/${install_dir}/grubenv"
printf '%.1024s' "$(printf '# GRUB Environment Block\nNAME=%s\nVERSION=%s\n%s' \
"${iso_name}" "${iso_version}" "$(printf '%0.1s' "#"{1..1024})")" \