Advertisement
Guest User

Untitled

a guest
Feb 18th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. gen_efi_boot_img(){
  6. local platform="$1"
  7. local efi_name="$2"
  8. local netboot_prefix="$3"
  9. local outdir="grub-efi-temp-${platform}"
  10. "${LIVE_BUILD_PATH}/efi-image" "/$outdir" "$platform" "$efi_name" "$netboot_prefix"
  11. mkdir -p /grub-efi-temp/EFI/boot
  12. mcopy -m -n -i /$outdir/efi.img '::efi/boot/boot*.efi' /grub-efi-temp/EFI/boot
  13. cp -a ""/$outdir/* "/grub-efi-temp/"
  14.  
  15. # Secure Boot support:
  16. # - create the EFI directory in the ESP with uppercase letters to make
  17. # certain firmwares (eg: TianoCore) happy
  18. # - use shim as the boot<arch>.efi that gets loaded first by the firmware
  19. # - drop a grub.cfg (same reason as below) in the cfg directory as configured
  20. # by the signed grub efi binary creation. This is set dynamically when grub2 is
  21. # built with the ouput of dpkg-vendor, and can be overridden by the builder, so
  22. # we do the same here in live-build.
  23. # - the source paths are taken from shim-signed:
  24. # https://packages.debian.org/sid/amd64/shim-signed/filelist
  25. # and grub-efi-amd64-signed, currently in Ubuntu:
  26. # https://packages.ubuntu.com/xenial/amd64/grub-efi-amd64-signed/filelist
  27. # https://packages.ubuntu.com/bionic/arm64/grub-efi-arm64-signed/filelist
  28. # E.g., gcdx64.efi.signed is the boot loader for removable device, like CD or
  29. # USB flash drive, while grubx64.efi.signed is for hard drive.
  30. # Therefore here gcdx64.efi.signed is used for amd64 and gcdaa64.efi.signed is
  31. # for arm64.
  32. 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
  33. cp -a /usr/lib/grub/$platform-signed/gcd$efi_name.efi.signed /grub-efi-temp/EFI/boot/grub$efi_name.efi
  34. cp -a /usr/lib/shim/shim$efi_name.efi.signed /grub-efi-temp/EFI/boot/boot$efi_name.efi
  35. fi
  36. }
  37.  
  38. 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"
  39. if [ ! -e "" ] ; then
  40. LIVE_BUILD_PATH="/usr/lib/live/build"
  41. else
  42. LIVE_BUILD_PATH="/scripts/build"
  43. fi
  44.  
  45. 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
  46.  
  47. case "amd64" in
  48. amd64|i386)
  49. gen_efi_boot_img "x86_64-efi" "x64" "debian-live/amd64"
  50. gen_efi_boot_img "i386-efi" "ia32" "debian-live/i386"
  51. PATH="${PRE_EFI_IMAGE_PATH}"
  52. ;;
  53. arm64)
  54. gen_efi_boot_img "arm64-efi" "aa64" "debian-live/arm64"
  55. PATH="${PRE_EFI_IMAGE_PATH}"
  56. ;;
  57. armhf)
  58. gen_efi_boot_img "arm-efi" "arm" "debian-live/arm"
  59. PATH="${PRE_EFI_IMAGE_PATH}"
  60. ;;
  61. esac
  62.  
  63.  
  64. # On some platforms the EFI grub image will be loaded, so grub's root
  65. # variable will be set to the EFI partition. This means that grub will
  66. # look in that partition for a grub.cfg file, and even if it finds it
  67. # it will not be able to find the vmlinuz and initrd.
  68. # Drop a minimal grub.cfg in the EFI partition that sets the root and prefix
  69. # to whatever partition holds the /.disk/info file, and load the grub
  70. # config from that same partition.
  71. mkdir -p /grub-efi-temp-cfg
  72. cat >/grub-efi-temp-cfg/grub.cfg <<EOF
  73. search --set=root --file /.disk/info
  74. set prefix=(\$root)/boot/grub
  75. configfile (\$root)/boot/grub/grub.cfg
  76. EOF
  77. # Set the timestamp within the efi.img file
  78. touch /grub-efi-temp-cfg/grub.cfg -d@1676720481
  79.  
  80. # The code below is adapted from tools/boot/jessie/boot-x86
  81. # in debian-cd
  82.  
  83. # Stuff the EFI boot files into a FAT filesystem, making it as
  84. # small as possible. 24KiB headroom seems to be enough;
  85. # (x+31)/32*32 rounds up to multiple of 32.
  86. # This is the same as in efi-image, but we need to redo it here in
  87. # the case of a multi-arch amd64/i386 image
  88.  
  89. size=0
  90. for file in /grub-efi-temp/EFI/boot/*.efi /grub-efi-temp-cfg/grub.cfg; do
  91. size=$(($size + $(stat -c %s "$file")))
  92. done
  93.  
  94. # directories: EFI EFI/boot boot boot/grub
  95. size=$(($size + 4096 * 4))
  96.  
  97. blocks=$((($size / 1024 + 55) / 32 * 32 ))
  98.  
  99. rm -f /grub-efi-temp/boot/grub/efi.img
  100. # The VOLID must be (truncated to) a 32bit hexadecimal number
  101. mkfs.msdos -C "/grub-efi-temp/boot/grub/efi.img" $blocks -i 63f0b961 >/dev/null
  102. mmd -i "/grub-efi-temp/boot/grub/efi.img" ::EFI
  103. mmd -i "/grub-efi-temp/boot/grub/efi.img" ::EFI/boot
  104. mcopy -m -o -i "/grub-efi-temp/boot/grub/efi.img" /grub-efi-temp/EFI/boot/*.efi "::EFI/boot"
  105.  
  106. mmd -i "/grub-efi-temp/boot/grub/efi.img" ::boot
  107. mmd -i "/grub-efi-temp/boot/grub/efi.img" ::boot/grub
  108. 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