Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- set -e
- gen_efi_boot_img(){
- local platform="$1"
- local efi_name="$2"
- local netboot_prefix="$3"
- local outdir="grub-efi-temp-${platform}"
- "${LIVE_BUILD_PATH}/efi-image" "/$outdir" "$platform" "$efi_name" "$netboot_prefix"
- mkdir -p /grub-efi-temp/EFI/boot
- mcopy -m -n -i /$outdir/efi.img '::efi/boot/boot*.efi' /grub-efi-temp/EFI/boot
- cp -a ""/$outdir/* "/grub-efi-temp/"
- # Secure Boot support:
- # - create the EFI directory in the ESP with uppercase letters to make
- # certain firmwares (eg: TianoCore) happy
- # - use shim as the boot<arch>.efi that gets loaded first by the firmware
- # - drop a grub.cfg (same reason as below) in the cfg directory as configured
- # by the signed grub efi binary creation. This is set dynamically when grub2 is
- # built with the ouput of dpkg-vendor, and can be overridden by the builder, so
- # we do the same here in live-build.
- # - the source paths are taken from shim-signed:
- # https://packages.debian.org/sid/amd64/shim-signed/filelist
- # and grub-efi-amd64-signed, currently in Ubuntu:
- # https://packages.ubuntu.com/xenial/amd64/grub-efi-amd64-signed/filelist
- # https://packages.ubuntu.com/bionic/arm64/grub-efi-arm64-signed/filelist
- # E.g., gcdx64.efi.signed is the boot loader for removable device, like CD or
- # USB flash drive, while grubx64.efi.signed is for hard drive.
- # Therefore here gcdx64.efi.signed is used for amd64 and gcdaa64.efi.signed is
- # for arm64.
- if [ -r /usr/lib/grub/$platform-signed/gcd$efi_name.efi.signed -a -r /usr/lib/shim/shim$efi_name.efi.signed -a "enable" != "disable" ]; then
- cp -a /usr/lib/grub/$platform-signed/gcd$efi_name.efi.signed /grub-efi-temp/EFI/boot/grub$efi_name.efi
- cp -a /usr/lib/shim/shim$efi_name.efi.signed /grub-efi-temp/EFI/boot/boot$efi_name.efi
- fi
- }
- PRE_EFI_IMAGE_PATH="/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
- if [ ! -e "" ] ; then
- LIVE_BUILD_PATH="/usr/lib/live/build"
- else
- LIVE_BUILD_PATH="/scripts/build"
- fi
- PATH="/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/working_dir/tmp/amd64/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${LIVE_BUILD_PATH}" # Make sure grub-cpmodules is used as if it was installed in the system
- case "amd64" in
- amd64|i386)
- gen_efi_boot_img "x86_64-efi" "x64" "debian-live/amd64"
- gen_efi_boot_img "i386-efi" "ia32" "debian-live/i386"
- PATH="${PRE_EFI_IMAGE_PATH}"
- ;;
- arm64)
- gen_efi_boot_img "arm64-efi" "aa64" "debian-live/arm64"
- PATH="${PRE_EFI_IMAGE_PATH}"
- ;;
- armhf)
- gen_efi_boot_img "arm-efi" "arm" "debian-live/arm"
- PATH="${PRE_EFI_IMAGE_PATH}"
- ;;
- esac
- # On some platforms the EFI grub image will be loaded, so grub's root
- # variable will be set to the EFI partition. This means that grub will
- # look in that partition for a grub.cfg file, and even if it finds it
- # it will not be able to find the vmlinuz and initrd.
- # Drop a minimal grub.cfg in the EFI partition that sets the root and prefix
- # to whatever partition holds the /.disk/info file, and load the grub
- # config from that same partition.
- mkdir -p /grub-efi-temp-cfg
- cat >/grub-efi-temp-cfg/grub.cfg <<EOF
- search --set=root --file /.disk/info
- set prefix=(\$root)/boot/grub
- configfile (\$root)/boot/grub/grub.cfg
- EOF
- # Set the timestamp within the efi.img file
- touch /grub-efi-temp-cfg/grub.cfg -d@1676720481
- # The code below is adapted from tools/boot/jessie/boot-x86
- # in debian-cd
- # Stuff the EFI boot files 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.
- # This is the same as in efi-image, but we need to redo it here in
- # the case of a multi-arch amd64/i386 image
- size=0
- for file in /grub-efi-temp/EFI/boot/*.efi /grub-efi-temp-cfg/grub.cfg; do
- size=$(($size + $(stat -c %s "$file")))
- done
- # directories: EFI EFI/boot boot boot/grub
- size=$(($size + 4096 * 4))
- blocks=$((($size / 1024 + 55) / 32 * 32 ))
- rm -f /grub-efi-temp/boot/grub/efi.img
- # The VOLID must be (truncated to) a 32bit hexadecimal number
- mkfs.msdos -C "/grub-efi-temp/boot/grub/efi.img" $blocks -i 63f0b961 >/dev/null
- mmd -i "/grub-efi-temp/boot/grub/efi.img" ::EFI
- mmd -i "/grub-efi-temp/boot/grub/efi.img" ::EFI/boot
- mcopy -m -o -i "/grub-efi-temp/boot/grub/efi.img" /grub-efi-temp/EFI/boot/*.efi "::EFI/boot"
- mmd -i "/grub-efi-temp/boot/grub/efi.img" ::boot
- mmd -i "/grub-efi-temp/boot/grub/efi.img" ::boot/grub
- mcopy -m -o -i "/grub-efi-temp/boot/grub/efi.img" /grub-efi-temp-cfg/grub.cfg "::boot/grub"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement