#! /bin/sh set -e # Copyright (C) 2016-2020 The Debian Live team # Copyright (C) 2010, 2011 Canonical Ltd. # Author: Colin Watson # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # Make an EFI boot image. if [ -z "$1" ] || [ -z "$2" ]; then echo "usage: $0 OUTPUT-DIRECTORY GRUB-PLATFORM EFI-NAME NETBOOT-PREFIX" exit 1 fi outdir="$1" platform="$2" efi_name="$3" netboot_prefix="$4" memdisk_img= workdir= cleanup () { [ -z "$memdisk_img" ] || rm -f "$memdisk_img" [ -z "$workdir" ] || rm -rf "$workdir" } trap cleanup EXIT HUP INT QUIT TERM rm -rf "$outdir" mkdir -p "$outdir" memdisk_img="$(mktemp efi-image.XXXXXX)" 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" <"$outdir/boot/grub/$platform/grub.cfg" # Build the core image. (cd "$workdir"; tar -cf - boot) >"$memdisk_img" grub-mkimage -O "$platform" -m "$memdisk_img" \ -o "$workdir/boot$efi_name.efi" -p '(memdisk)/boot/grub' \ search iso9660 configfile normal memdisk tar part_msdos part_gpt fat grub-mkimage -O "$platform" \ -o "$outdir/bootnet$efi_name.efi" -p "$netboot_prefix/grub" \ search configfile normal efinet tftp net # Stuff it into a FAT filesystem, making it as small as possible. 24KiB # headroom seems to be enough; (x+31)/32*32 rounds up to multiple of 32. mkfs.msdos -C "$outdir/efi.img" \ $(( ($(stat -c %s "$workdir/boot$efi_name.efi") / 1024 + 55) \ / 32 * 32 )) -i ${SOURCE_DATE_EPOCH} mmd -i "$outdir/efi.img" ::efi mmd -i "$outdir/efi.img" ::efi/boot # Set the timestamp of the .efi file touch "$workdir/boot$efi_name.efi" -d@${SOURCE_DATE_EPOCH} mcopy -m -i "$outdir/efi.img" "$workdir/boot$efi_name.efi" \ "::efi/boot/boot$efi_name.efi" grub-cpmodules "$outdir" "$platform" cp -a /usr/share/grub/unicode.pf2 "$outdir/boot/grub/" exit 0