From 2ec6630077d11f6c7066f6762a6cf7d85bc15127 Mon Sep 17 00:00:00 2001 From: wangyueliang Date: Tue, 25 Jun 2024 15:07:05 +0800 Subject: [PATCH] =?UTF-8?q?Refer=20to=20upstream=20optimization=20for=20li?= =?UTF-8?q?ve=20iso=20image=20efi=20startup=20process=20Reference=EF=BC=9A?= =?UTF-8?q?https://github.com/coreos/coreos-assembler/pull/2435?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cmd-buildextend-live | 111 ++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 53 deletions(-) diff --git a/src/cmd-buildextend-live b/src/cmd-buildextend-live index d1ef5968..1e212622 100755 --- a/src/cmd-buildextend-live +++ b/src/cmd-buildextend-live @@ -519,60 +519,65 @@ def generate_iso(): '--user-mode', '--subpath', "/usr/lib/bootupd/updates/EFI", buildmeta_commit, tmpimageefidir]) - -# # Find name of vendor directory -# vendor_ids = [n for n in os.listdir(tmpimageefidir) if n != "BOOT"] -# if len(vendor_ids) != 1: -# raise Exception(f"did not find exactly one EFI vendor ID: {vendor_ids}") - -# # Delete fallback and its CSV file. Its purpose is to create -# # EFI boot variables, which we don't want when booting from -# # removable media. -# # -# # A future shim release will merge fallback.efi into the main -# # shim binary and enable the fallback behavior when the CSV -# # exists. But for now, fail if fallback.efi is missing. -# for path in ensure_glob(os.path.join(tmpimageefidir, "BOOT", "fb*.efi")): -# os.unlink(path) -# # openEuler shim package has two mm*.efi that put in "BOOT" and "openEuler" dir, delete one of them here -# for path in ensure_glob(os.path.join(tmpimageefidir, "BOOT", "mm*.efi")): -# os.unlink(path) -# for path in ensure_glob(os.path.join(tmpimageefidir, vendor_ids[0], "BOOT*.CSV")): -# os.unlink(path) - -# # Drop vendor copies of shim; we already have it in BOOT*.EFI in -# # BOOT -# for path in ensure_glob(os.path.join(tmpimageefidir, vendor_ids[0], "shim*.efi")): -# os.unlink(path) - -# # Consolidate remaining files into BOOT. shim needs GRUB to be -# # there, and the rest doesn't hurt. -# for path in ensure_glob(os.path.join(tmpimageefidir, vendor_ids[0], "*")): -# shutil.move(path, os.path.join(tmpimageefidir, "BOOT")) -# os.rmdir(os.path.join(tmpimageefidir, vendor_ids[0])) - -# # Inject a stub grub.cfg pointing to the one in the main ISO image. -# # -# # When booting via El Torito, this stub is not used; GRUB reads -# # the ISO image directly using its own ISO support. This -# # happens when booting from a CD device, or when the ISO is -# # copied to a USB stick and booted on EFI firmware which prefers -# # to boot a hard disk from an El Torito image if it has one. -# # EDK II in QEMU behaves this way. -# # -# # This stub is used with EFI firmware which prefers to boot a -# # hard disk from an ESP, or which cannot boot a hard disk via El -# # Torito at all. In that case, GRUB thinks it booted from a -# # partition of the disk (a fake ESP created by isohybrid, -# # pointing to efiboot.img) and needs a grub.cfg there. -# with open(os.path.join(tmpimageefidir, "BOOT", "grub.cfg"), "w") as fh: -# fh.write(f'''search --label "{volid}" --set root --no-floppy -# set prefix=($root)/EFI/{vendor_ids[0]} -# echo "Booting via ESP..." -# configfile $prefix/grub.cfg -# boot -# ''') + #Reference:https://github.com/coreos/coreos-assembler/pull/2435 + + # Find name of vendor directory + vendor_ids = [n for n in os.listdir(tmpimageefidir) if n != "BOOT"] + if len(vendor_ids) != 1: + raise Exception(f"did not find exactly one EFI vendor ID: {vendor_ids}") + + # Delete fallback and its CSV file. Its purpose is to create + # EFI boot variables, which we don't want when booting from + # removable media. + # + # A future shim release will merge fallback.efi into the main + # shim binary and enable the fallback behavior when the CSV + # exists. But for now, fail if fallback.efi is missing. + for path in ensure_glob(os.path.join(tmpimageefidir, "BOOT", "fb*.efi")): + os.unlink(path) + # openEuler shim package has two mm*.efi that put in "BOOT" and "openEuler" dir, delete one of them here + for path in ensure_glob(os.path.join(tmpimageefidir, "BOOT", "mm*.efi")): + os.unlink(path) + + for path in ensure_glob(os.path.join(tmpimageefidir, vendor_ids[0], "BOOT*.CSV")): + os.unlink(path) + + # Drop vendor copies of shim; we already have it in BOOT*.EFI in + # BOOT + for path in ensure_glob(os.path.join(tmpimageefidir, vendor_ids[0], "shim*.efi")): + os.unlink(path) + # openEuler shim package has two fb*.efi that put in "BOOT" and "openEuler" dir, delete them all + for path in ensure_glob(os.path.join(tmpimageefidir, vendor_ids[0], "fb*.efi")): + os.unlink(path) + + # Consolidate remaining files into BOOT. shim needs GRUB to be + # there, and the rest doesn't hurt. + for path in ensure_glob(os.path.join(tmpimageefidir, vendor_ids[0], "*")): + shutil.move(path, os.path.join(tmpimageefidir, "BOOT")) + os.rmdir(os.path.join(tmpimageefidir, vendor_ids[0])) + + # Inject a stub grub.cfg pointing to the one in the main ISO image. + # + # When booting via El Torito, this stub is not used; GRUB reads + # the ISO image directly using its own ISO support. This + # happens when booting from a CD device, or when the ISO is + # copied to a USB stick and booted on EFI firmware which prefers + # to boot a hard disk from an El Torito image if it has one. + # EDK II in QEMU behaves this way. + # + # This stub is used with EFI firmware which prefers to boot a + # hard disk from an ESP, or which cannot boot a hard disk via El + # Torito at all. In that case, GRUB thinks it booted from a + # partition of the disk (a fake ESP created by isohybrid, + # pointing to efiboot.img) and needs a grub.cfg there. + with open(os.path.join(tmpimageefidir, "BOOT", "grub.cfg"), "w") as fh: + fh.write(f'''search --label "{volid}" --set root --no-floppy +set prefix=($root)/EFI/{vendor_ids[0]} +echo "Booting via ESP..." +configfile $prefix/grub.cfg +boot +''') # Install binaries from boot partition # Manually construct the tarball to ensure proper permissions and ownership -- Gitee