From a75d7e5f7e582b3bbbaf5f0d16e1f243c4c3a8bf Mon Sep 17 00:00:00 2001 From: nl6720 Date: Thu, 28 Sep 2023 10:45:43 +0300 Subject: 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. --- archiso/mkarchiso | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'archiso/mkarchiso') diff --git a/archiso/mkarchiso b/archiso/mkarchiso index a727a1a..7890615 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -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})")" \ -- cgit v1.2.3-54-g00ecf