2016-01-18 02:01:15 -01:00
|
|
|
#! /bin/sh
|
|
|
|
set -e
|
|
|
|
|
2020-03-11 09:07:21 -01:00
|
|
|
# Copyright (C) 2016-2020 The Debian Live team
|
2016-01-18 02:01:15 -01:00
|
|
|
# Copyright (C) 2010, 2011 Canonical Ltd.
|
|
|
|
# Author: Colin Watson <cjwatson@ubuntu.com>
|
|
|
|
#
|
|
|
|
# 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" <<EOF
|
|
|
|
search --file --set=root /.disk/info
|
|
|
|
set prefix=(\$root)/boot/grub
|
|
|
|
source \$prefix/$platform/grub.cfg
|
|
|
|
EOF
|
2021-01-02 15:40:55 -01:00
|
|
|
# Set the timestamps
|
|
|
|
find $workdir -newermt "$(date -d@${SOURCE_DATE_EPOCH} '+%Y-%m-%d %H:%M:%S')" -exec touch '{}' -d@${SOURCE_DATE_EPOCH} ';'
|
2016-01-18 02:01:15 -01:00
|
|
|
|
|
|
|
mkdir -p "$outdir/boot/grub/$platform"
|
|
|
|
(for i in /usr/lib/grub/$platform/part_*.mod; do
|
2020-02-10 14:48:49 -01:00
|
|
|
i=`echo $i | sed 's?^.*/??g;s?\.mod$??g;'`
|
2016-01-18 02:01:15 -01:00
|
|
|
echo "insmod $i"
|
|
|
|
done; \
|
|
|
|
echo "source /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) \
|
2020-10-04 11:51:14 +00:00
|
|
|
/ 32 * 32 )) -i ${SOURCE_DATE_EPOCH}
|
2016-01-18 02:01:15 -01:00
|
|
|
mmd -i "$outdir/efi.img" ::efi
|
|
|
|
mmd -i "$outdir/efi.img" ::efi/boot
|
2021-01-02 15:40:55 -01:00
|
|
|
# Set the timestamp of the .efi file
|
|
|
|
touch "$workdir/boot$efi_name.efi" -d@${SOURCE_DATE_EPOCH}
|
2021-01-01 15:51:02 -01:00
|
|
|
mcopy -m -i "$outdir/efi.img" "$workdir/boot$efi_name.efi" \
|
2016-01-18 02:01:15 -01:00
|
|
|
"::efi/boot/boot$efi_name.efi"
|
|
|
|
|
|
|
|
grub-cpmodules "$outdir" "$platform"
|
2021-01-01 15:51:02 -01:00
|
|
|
cp -a /usr/share/grub/unicode.pf2 "$outdir/boot/grub/"
|
2016-01-18 02:01:15 -01:00
|
|
|
|
|
|
|
exit 0
|