#!/bin/bash case "$LB_BOOTLOADER" in grub2|burg) ;; *) exit 0 ;; esac bit="$(file chroot/bin/true | grep -q 'ELF 64-bit' && echo 64 || echo 32)" case "$bit" in 64) platform=x86_64-efi efi_name=x64 shell_dir=X64 ;; 32) platform=i386-efi efi_name=ia32 shell_dir=Ia32 ;; esac modules="search iso9660 configfile normal memdisk tar part_msdos fat" workdir= cleanup () { [ -z "$workdir" ] || rm -rf "$workdir" } trap cleanup EXIT HUP INT QUIT TERM workdir="$(mktemp -d efi-image.XXXXXX)" # Skeleton configuration file which finds the real boot disk. mkdir -p "$workdir/boot/grub" cat >"$workdir/boot/grub/grub.cfg" <"binary/boot/grub/$platform/grub.cfg" # fix module order ("gzio" should be loaded before "normal", otherwise a "prefix not set" error message will pop up on boot) sed -i.orig -e '/^normal:/{/gzio/!{s/$/ gzio/}}' chroot/usr/lib/grub/$platform/moddep.lst # Build the core image. (cd "$workdir"; tar -cf - boot) > chroot/memdisk.$$.img chroot chroot grub-mkimage -O "$platform" -m "/memdisk.$$.img" \ -o "/boot$efi_name.efi" -p '(memdisk)/boot/grub' $modules rm chroot/memdisk.$$.img mv "chroot/boot$efi_name.efi" "binary/efi/boot/boot$efi_name.efi" # restore original module order mv chroot/usr/lib/grub/$platform/moddep.lst{.orig,} # Copy over GRUB modules, except for those already built in. cp -a "chroot/usr/lib/grub/$platform"/*.lst "binary/boot/grub/$platform/" builtin_modules="$(m="$modules"; while [ "$m" ] && echo $m do m=$(sed -ne "s/^\($(echo -n $m | sed 's/ /\\|/g')\):\(.*\)$/\2/p" "chroot/usr/lib/grub/$platform"/moddep.lst) done | fmt -w1 | sort -u)" for x in "chroot/usr/lib/grub/$platform"/*.mod; do case $(basename "$x" .mod) in affs|afs|afs_be|befs|befs_be|minix|nilfs2|sfs|zfs|zfsinfo) # unnecessary filesystem modules ;; example_functional_test|functional_test|hello) # other cruft ;; *) grep -wq $(basename "$x" .mod) <<<"$builtin_modules" || cp -a "$x" "binary/boot/grub/$platform/" ;; esac done # include EFI shell [ -f binary/efi/boot/shell$efi_name.efi ] || \ wget -O binary/efi/boot/shell$efi_name.efi "https://github.com/tianocore/edk2-archive/raw/master/EdkShellBinPkg/FullShell/$shell_dir/Shell_Full.efi" if [ $? -ne 0 ]; then echo "E: EFI shell download failed..." else echo "Debug: EFI shell download succes..." fi # echo goes to binary.log