#!/bin/bash
-# Filename: ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/45-efi
-# Purpose: create grub image for use in ISO for EFI boot
+# Filename: ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/45-grub-images
+# Purpose: create grub images for use in ISO
# Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2 or any later version.
################################################################################
set -e
+set -u
+TMP_CONFIG="/tmp/grub_config_efi"
-BOOTX64="${target}/boot/bootx64.efi"
-EFI_IMG="${target}/boot/efi.img"
-TMP_CONFIG="${target}/tmp/grub_config_efi"
+# this allows us to find this specific Grml ISO,
+# even if there are multiple Grml ISOs present
+bootfile="${GRML_NAME}_$(TZ=UTC date +%s)"
+echo "$bootfile" > "${target}/"boot/grub/bootfile.txt
-rm -f "$BOOTX64" "$EFI_IMG" "$TMP_CONFIG"
-
-cat > "$TMP_CONFIG" <<EOF
-search --set -f /conf/bootid.txt root
-if [ -e /boot/grub/grub.cfg ]; then
- set prefix=(\$root)/boot/grub
- configfile /boot/grub/grub.cfg
-else
- echo "E: Could not find root device!"
-fi
+cat > "${target}/${TMP_CONFIG}" <<EOF
+search.file /conf/bootfile_$bootfile root
+set prefix=(\$root)/boot/grub
+insmod normal
+normal
+echo "E: Could not find root device (for /conf/bootfile_$bootfile)!"
EOF
-BOOTX64="${BOOTX64##${target}}"
-EFI_IMG="${EFI_IMG##${target}}"
-TMP_CONFIG="${TMP_CONFIG##${target}}"
-
ARCHS=(i386-pc)
-
declare -A ADDITIONAL_MODULES
ADDITIONAL_MODULES[i386-pc]="biosdisk"
fi
fi
-# until grub 1.99-27.1 it's called raid, starting with
-# grub version 2.00-14 the raid.mod module no longer exists
-if [ -r "${target}"/usr/lib/grub/i386-pc/raid.mod ] ; then
- echo "Using raid module as file raid.mod is present"
- ADDITIONAL_MODULES[raid]="raid"
-elif [ -r "${target}"/usr/lib/grub/i386-pc/diskfilter.mod ] ; then
- echo "Using diskfilter and related modules as file diskfilter.mod is present"
- ADDITIONAL_MODULES[raid]="diskfilter mdraid09 mdraid09_be mdraid1x raid5rec raid6rec"
-else
- echo "Warning: no according raid module in grub directory found."
+if ifclass I386 ; then
+ if [ -r "${target}"/usr/lib/grub/i386-efi/moddep.lst ] ; then
+ ARCHS+=(i386-efi)
+ ADDITIONAL_MODULES[i386-efi]="efi_gop efi_uga"
+ else
+ echo "/usr/lib/grub/i386-efi/moddep.lst could not be found, skipping."
+ echo "NOTE: grub-efi-ia32 not installed?"
+ fi
fi
-BOOTX64="${BOOTX64##${target}}"
-EFI_IMG="${EFI_IMG##${target}}"
-TMP_CONFIG="${TMP_CONFIG##${target}}"
-
-for arch in ${ARCHS[@]} ; do
-$ROOTCMD grub-mkimage -O $arch -o /boot/$arch.img --prefix=/boot/grub/ --config="$TMP_CONFIG" \
- bitmap boot btrfs cat chain cmp configfile cpio echo elf ext2 \
- fat gfxmenu gfxterm gzio help iso9660 jpeg linux loopback lvm \
- memdisk minicmd multiboot normal part_gpt part_msdos play png \
- probe regexp reiserfs search search_fs_file search_fs_uuid \
- search_label squash4 terminal test video videoinfo xfs \
- ${ADDITIONAL_MODULES[raid]} ${ADDITIONAL_MODULES[$arch]}
+for arch in "${ARCHS[@]}" ; do
+ filename=''
+ case "$arch" in
+ i386-pc) filename=/boot/grub/grub.img ;;
+ x86_64-efi) filename=/boot/bootx64.efi ;;
+ i386-efi) filename=/boot/bootia32.efi ;;
+ esac
+
+ $ROOTCMD grub-mkimage -O $arch -o "$filename" --prefix=/boot/grub/ --config="$TMP_CONFIG" \
+ echo iso9660 part_msdos search_fs_file test \
+ fat ext2 reiserfs xfs btrfs squash4 part_gpt lvm \
+ ${ADDITIONAL_MODULES[$arch]}
done
-if [ -f "${target}/boot/i386-pc.img" ] ; then
- mv "${target}/boot/i386-pc.img" "${target}/boot/grub/grub.img"
-fi
-
-if [ -f "${target}/boot/x86_64-efi.img" ] ; then
- mv "${target}/boot/x86_64-efi.img" "${target}/${BOOTX64}"
-fi
-
-if ifclass AMD64 ; then
-/ if ! [ -r "${target}/${BOOTX64}" ] ; then
- echo "Can not access grub efi image." >&2
- exit 1
- fi
-
- SIZE=$(du --apparent-size -sk "${target}/${BOOTX64}" | awk -F" " '{print $1}')
- SIZE=$(((($SIZE / 32 )+2)*32))
-
- dd if=/dev/zero of="${target}/${EFI_IMG}" bs=1k count="$SIZE" 2>/dev/null
- $ROOTCMD mkfs.vfat -n GRML "$EFI_IMG" >/dev/null
- $ROOTCMD mmd -i "$EFI_IMG" ::EFI
- $ROOTCMD mmd -i "$EFI_IMG" ::EFI/BOOT
- $ROOTCMD mcopy -i "$EFI_IMG" "$BOOTX64" ::EFI/BOOT/bootx64.efi >/dev/null
- echo "Generated EFI image $BOOTX64"
- echo "Generated bootx64 image $EFI_IMG"
-fi
-
rm -f "${target}/${TMP_CONFIG}"
echo "Generated Grub images"
-
## END OF FILE #################################################################
# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2