From 299da40f9f1e00f9eb4e8e09c8456e91a83a424b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Tue, 24 Mar 2015 22:34:28 +0100 Subject: [PATCH] iso: make efi FS size adaptive, make deterministic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #6795. This was co-authored with @bobvanderlinden. (cherry picked from commit e19ac248ae59fd327c32b1ae3e37792c22a7c7ac) Signed-off-by: Domen Kožar Conflicts: nixos/modules/installer/cd-dvd/iso-image.nix --- nixos/modules/installer/cd-dvd/iso-image.nix | 32 +++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 39db7d9b8f72..8f17e720aca1 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -56,17 +56,28 @@ let echo "timeout 5" >> $out/loader/loader.conf ''; - efiImg = pkgs.runCommand "efi-image_eltorito" { buildInputs = [ pkgs.mtools ]; } + efiImg = pkgs.runCommand "efi-image_eltorito" { buildInputs = [ pkgs.mtools pkgs.libfaketime ]; } + # Be careful about determinism: du --apparent-size, + # dates (cp -p, touch, mcopy -m, faketime for label), IDs (mkfs.vfat -i) '' - #Let's hope 15M is enough - dd bs=2048 count=7680 if=/dev/zero of="$out" - ${pkgs.dosfstools}/sbin/mkfs.vfat "$out" - mcopy -svi "$out" ${efiDir}/* :: - mmd -i "$out" boot - mcopy -v -i "$out" \ - ${config.boot.kernelPackages.kernel}/bzImage ::boot/bzImage - mcopy -v -i "$out" \ - ${config.system.build.initialRamdisk}/initrd ::boot/initrd + mkdir ./contents && cd ./contents + cp -rp "${efiDir}"/* . + mkdir ./boot + cp -p "${config.boot.kernelPackages.kernel}/bzImage" \ + "${config.system.build.initialRamdisk}/initrd" ./boot/ + touch --date=@0 ./* + + usage_size=$(du -sb --apparent-size . | tr -cd '[:digit:]') + # Make the image 110% as big as the files need to make up for FAT overhead + image_size=$(( ($usage_size * 110) / 100 )) + # Make the image fit blocks of 1M + block_size=$((1024*1024)) + image_size=$(( ($image_size / $block_size + 1) * $block_size )) + echo "Usage size: $usage_size" + echo "Image size: $image_size" + truncate --size=$image_size "$out" + ${pkgs.libfaketime}/bin/faketime "2000-01-01 00:00:00" ${pkgs.dosfstools}/sbin/mkfs.vfat -i 12345678 -n EFIBOOT "$out" + mcopy -bpsvm -i "$out" ./* :: ''; # */ targetArch = if pkgs.stdenv.isi686 then @@ -155,7 +166,6 @@ in }; - config = { boot.loader.grub.version = 2;