diff --git a/scripts/make_grub_efi.sh b/scripts/make_grub_efi.sh index f6d6673..9bf1d51 100755 --- a/scripts/make_grub_efi.sh +++ b/scripts/make_grub_efi.sh @@ -64,6 +64,21 @@ if [ -d "${i386_EFI_DIR}" ]; then cp -Rp "${i386_EFI_DIR}" "${GRUB_BOOT_DIR}/" || exit 1 fi +# These must exist. +cp "${CHROOT_DIR}/usr/share/grub/unicode.pf2" "${GRUB_BOOT_DIR}"/ || exit 1 + +# Copy locale files +localedir="${CHROOT_DIR}/usr/share/locale" +for dir in "${localedir}"/*; do + if [ -f "${dir}/LC_MESSAGES/grub.mo" ]; then + cp -f "${dir}/LC_MESSAGES/grub.mo" "${GRUB_LOCALE_DIR}/${dir##*/}.mo" + fi +done + +# Copy splash, this is in sabayon-artwork-grub, we expect to find it +cp "${CHROOT_DIR}/usr/share/grub/default-splash.png" "${GRUB_BOOT_DIR}"/ \ + || exit 1 + # now setup SecureBoot for x86_64 using shim: # See: http://mjg59.dreamwidth.org/20303.html efi_x86_64_file="${EFI_BOOT_DIR}"/bootx64.efi @@ -91,58 +106,46 @@ if [ -f "${efi_x86_64_file}" ]; then --output "${grub_efi_file}.signed" \ "${grub_efi_file}" || exit 1 mv "${grub_efi_file}.signed" "${grub_efi_file}" || exit 1 + + # -- end of SecureBoot -- + # UEFI is currently only supported in x86_64, anyways + + # now the tricky part, create an eltorito alternative image + _efi_img="${GRUB_BOOT_DIR}"/efi.img + # 12 floppies = 2880 x 12, we need more space for SecureBoot and GRUB2 + # stuff to make isohybrid work as expected. + dd bs=512 count=$((2880 * 12)) if=/dev/zero of="${_efi_img}" || exit 1 + mkfs.msdos "${_efi_img}" || exit 1 + + tmp_dir=$(mktemp -d --suffix="make_grub_efi") + [[ -z "${tmp_dir}" ]] && exit 1 + MOUNT_DIRS+=( "${tmp_dir}" ) + mount -o loop "${_efi_img}" "${tmp_dir}" || exit 1 + mkdir -p "${tmp_dir}/efi/boot" || exit 1 + + # copy our .efi executables in place + cp -Rp "${EFI_BOOT_DIR}"/* "${tmp_dir}/efi/boot/" || exit 1 + + # in order to make isohybrid work, we need to copy the grub + # stuff inside the EFI boot image + tmp_grub_dir="${tmp_dir}/boot/grub" + mkdir -p "${tmp_grub_dir}" || exit 1 + + # This file is used by grub to determine where's the cdroot + ts=$(date +%Y%m%d%H%M%S) + img_id="${ts}${RANDOM}" + id_file="id.${img_id}.uefi" + touch "${CDROOT_DIR}/${id_file}" || exit 1 + + # copy the chainload grub.cfg version + cp "${SABAYON_MOLECULE_HOME}/boot/core/grub/grub-uefi-isohybrid.cfg" \ + "${tmp_grub_dir}/grub.cfg" || exit 1 + sed -i "s:%id_file%:${id_file}:g" "${tmp_grub_dir}/grub.cfg" || exit 1 + + # copy modules, actually, we would just need search + cp "${GRUB_BOOT_DIR}/"*-efi "${tmp_grub_dir}/" || exit 1 + + umount "${tmp_dir}" || exit 1 + rmdir "${tmp_dir}" # best effort + exit 0 fi - -# These must exist. -cp "${CHROOT_DIR}/usr/share/grub/unicode.pf2" "${GRUB_BOOT_DIR}"/ || exit 1 - -# Copy locale files -localedir="${CHROOT_DIR}/usr/share/locale" -for dir in "${localedir}"/*; do - if [ -f "${dir}/LC_MESSAGES/grub.mo" ]; then - cp -f "${dir}/LC_MESSAGES/grub.mo" "${GRUB_LOCALE_DIR}/${dir##*/}.mo" - fi -done - -# Copy splash, this is in sabayon-artwork-grub, we expect to find it -cp "${CHROOT_DIR}/usr/share/grub/default-splash.png" "${GRUB_BOOT_DIR}"/ \ - || exit 1 - -# now the tricky part, create an eltorito alternative image -_efi_img="${GRUB_BOOT_DIR}"/efi.img -# 12 floppies = 2880 x 12, we need more space for SecureBoot and GRUB2 -# stuff to make isohybrid work as expected. -dd bs=512 count=$((2880 * 12)) if=/dev/zero of="${_efi_img}" || exit 1 -mkfs.msdos "${_efi_img}" || exit 1 - -tmp_dir=$(mktemp -d --suffix="make_grub_efi") -[[ -z "${tmp_dir}" ]] && exit 1 -MOUNT_DIRS+=( "${tmp_dir}" ) -mount -o loop "${_efi_img}" "${tmp_dir}" || exit 1 -mkdir -p "${tmp_dir}/efi/boot" || exit 1 - -# copy our .efi executables in place -cp -Rp "${EFI_BOOT_DIR}"/* "${tmp_dir}/efi/boot/" || exit 1 - -# in order to make isohybrid work, we need to copy the grub -# stuff inside the EFI boot image -tmp_grub_dir="${tmp_dir}/boot/grub" -mkdir -p "${tmp_grub_dir}" || exit 1 - -# This file is used by grub to determine where's the cdroot -ts=$(date +%Y%m%d%H%M%S) -img_id="${ts}${RANDOM}" -id_file="id.${img_id}.uefi" -touch "${CDROOT_DIR}/${id_file}" || exit 1 - -# copy the chainload grub.cfg version -cp "${SABAYON_MOLECULE_HOME}/boot/core/grub/grub-uefi-isohybrid.cfg" \ - "${tmp_grub_dir}/grub.cfg" || exit 1 -sed -i "s:%id_file%:${id_file}:g" "${tmp_grub_dir}/grub.cfg" || exit 1 - -# copy modules, actually, we would just need search -cp "${GRUB_BOOT_DIR}/"*-efi "${tmp_grub_dir}/" || exit 1 - -umount "${tmp_dir}" || exit 1 -rmdir "${tmp_dir}" # best effort -exit 0