about summary refs log tree commit diff
path: root/nixos/modules/installer
diff options
context:
space:
mode:
authorThomas Watson <twatson52@icloud.com>2022-03-26 14:45:12 -0500
committerYour Name <you@example.com>2022-04-13 20:26:11 -0500
commit0931014baf9a4db293f8aa13c86dc7f1c0aa9395 (patch)
treeae9e52187d3ae2938779e96389ea74455601a901 /nixos/modules/installer
parentf7ad253271bc5bd8a951d8b6d3ab4e6ff7f0f18e (diff)
downloadnixlib-0931014baf9a4db293f8aa13c86dc7f1c0aa9395.tar
nixlib-0931014baf9a4db293f8aa13c86dc7f1c0aa9395.tar.gz
nixlib-0931014baf9a4db293f8aa13c86dc7f1c0aa9395.tar.bz2
nixlib-0931014baf9a4db293f8aa13c86dc7f1c0aa9395.tar.lz
nixlib-0931014baf9a4db293f8aa13c86dc7f1c0aa9395.tar.xz
nixlib-0931014baf9a4db293f8aa13c86dc7f1c0aa9395.tar.zst
nixlib-0931014baf9a4db293f8aa13c86dc7f1c0aa9395.zip
iso-image: slim down UEFI El Torito image
UEFI firmware does not have to be able to read ISO9660 filesystems, so
the El Torito mechanism provides a way to specify an embedded FAT32
image which contains files the UEFI firmware itself must be able to
read, such as UEFI executables. Once GRUB starts and reads its
configuration, it can access the ISO9660 filesystem to load other files.

This change removes the unused kernel, initrd, and GRUB font files from
the El Torito image, but keeps the GRUB configuration and UEFI
executables. These files have been present since EFI support was
originally introduced in commit 097c656. Other distribution ISOs, such
as Ubuntu 20.04, Fedora 35, and Windows 10 work this way too. This saves
24MiB on x86_64 and 61MiB on aarch64 ISOs.
Diffstat (limited to 'nixos/modules/installer')
-rw-r--r--nixos/modules/installer/cd-dvd/iso-image.nix16
1 files changed, 7 insertions, 9 deletions
diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix
index 860e240b43d4..1eaa940afb1f 100644
--- a/nixos/modules/installer/cd-dvd/iso-image.nix
+++ b/nixos/modules/installer/cd-dvd/iso-image.nix
@@ -369,10 +369,10 @@ let
     ${lib.optionalString (refindBinary != null) ''
     # GRUB apparently cannot do "chainloader" operations on "CD".
     if [ "\$root" != "cd0" ]; then
-      # Force root to be the FAT partition
-      # Otherwise it breaks rEFInd's boot
-      search --set=root --no-floppy --fs-uuid 1234-5678
       menuentry 'rEFInd' --class refind {
+        # Force root to be the FAT partition
+        # Otherwise it breaks rEFInd's boot
+        search --set=root --no-floppy --fs-uuid 1234-5678
         chainloader (\$root)/EFI/boot/${refindBinary}
       }
     fi
@@ -400,10 +400,8 @@ let
     #   dates (cp -p, touch, mcopy -m, faketime for label), IDs (mkfs.vfat -i)
     ''
       mkdir ./contents && cd ./contents
-      cp -rp "${efiDir}"/EFI .
-      mkdir ./boot
-      cp -p "${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile}" \
-        "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}" ./boot/
+      mkdir -p ./EFI/boot
+      cp -rp "${efiDir}"/EFI/boot/{grub.cfg,*.efi} ./EFI/boot
 
       # Rewrite dates for everything in the FS
       find . -exec touch --date=2000-01-01 {} +
@@ -421,11 +419,11 @@ let
       faketime "2000-01-01 00:00:00" mkfs.vfat -i 12345678 -n EFIBOOT "$out"
 
       # Force a fixed order in mcopy for better determinism, and avoid file globbing
-      for d in $(find EFI boot -type d | sort); do
+      for d in $(find EFI -type d | sort); do
         faketime "2000-01-01 00:00:00" mmd -i "$out" "::/$d"
       done
 
-      for f in $(find EFI boot -type f | sort); do
+      for f in $(find EFI -type f | sort); do
         mcopy -pvm -i "$out" "$f" "::/$f"
       done