2 # Filename: ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/45-efi
3 # Purpose: create grub image for use in ISO for EFI boot
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2 or any later version.
7 ################################################################################
12 BOOTX64="${target}/boot/bootx64.efi"
13 EFI_IMG="${target}/boot/efi.img"
14 TMP_CONFIG="${target}/tmp/grub_config_efi"
16 rm -f "$BOOTX64" "$EFI_IMG" "$TMP_CONFIG"
18 cat > "$TMP_CONFIG" <<EOF
19 search --set -f /conf/bootid.txt root
20 if [ -e /boot/grub/grub.cfg ]; then
21 set prefix=(\$root)/boot/grub
22 configfile /boot/grub/grub.cfg
24 echo "E: Could not find root device!"
28 BOOTX64="${BOOTX64##${target}}"
29 EFI_IMG="${EFI_IMG##${target}}"
30 TMP_CONFIG="${TMP_CONFIG##${target}}"
34 declare -A ADDITIONAL_MODULES
35 ADDITIONAL_MODULES[i386-pc]="biosdisk"
37 if ifclass AMD64 ; then
38 if [ -r "${target}"/usr/lib/grub/x86_64-efi/moddep.lst ] ; then
40 ADDITIONAL_MODULES[x86_64-efi]="efi_gop efi_uga"
42 echo "/usr/lib/grub/x86_64-efi/moddep.lst could not be found, skipping."
43 echo "NOTE: grub-efi-amd64-bin not installed?"
47 # until grub 1.99-27.1 it's called raid, starting with
48 # grub version 2.00-14 the raid.mod module no longer exists
49 if [ -r "${target}"/usr/lib/grub/i386-pc/raid.mod ] ; then
50 echo "Using raid module as file raid.mod is present"
51 ADDITIONAL_MODULES[raid]="raid"
52 elif [ -r "${target}"/usr/lib/grub/i386-pc/diskfilter.mod ] ; then
53 echo "Using diskfilter and related modules as file diskfilter.mod is present"
54 ADDITIONAL_MODULES[raid]="diskfilter mdraid09 mdraid09_be mdraid1x raid5rec raid6rec"
56 echo "Warning: no according raid module in grub directory found."
59 BOOTX64="${BOOTX64##${target}}"
60 EFI_IMG="${EFI_IMG##${target}}"
61 TMP_CONFIG="${TMP_CONFIG##${target}}"
63 for arch in ${ARCHS[@]} ; do
64 $ROOTCMD grub-mkimage -O $arch -o /boot/$arch.img --prefix=/boot/grub/ --config="$TMP_CONFIG" \
65 bitmap boot btrfs cat chain cmp configfile cpio echo elf ext2 \
66 fat gfxmenu gfxterm gzio help iso9660 jpeg linux loopback lvm \
67 memdisk minicmd multiboot normal part_gpt part_msdos play png \
68 probe regexp reiserfs search search_fs_file search_fs_uuid \
69 search_label squash4 terminal test video videoinfo xfs \
70 ${ADDITIONAL_MODULES[raid]} ${ADDITIONAL_MODULES[$arch]}
73 if [ -f "${target}/boot/i386-pc.img" ] ; then
74 mv "${target}/boot/i386-pc.img" "${target}/boot/grub/grub.img"
77 if [ -f "${target}/boot/x86_64-efi.img" ] ; then
78 mv "${target}/boot/x86_64-efi.img" "${target}/${BOOTX64}"
81 if ifclass AMD64 ; then
82 if ! [ -r "${target}/${BOOTX64}" ] ; then
83 echo "Can not access grub efi image." >&2
87 SIZE=$(du --apparent-size -sk "${target}/${BOOTX64}" | awk -F" " '{print $1}')
88 SIZE=$(((($SIZE / 32 )+2)*32))
90 dd if=/dev/zero of="${target}/${EFI_IMG}" bs=1k count="$SIZE" 2>/dev/null
91 $ROOTCMD mkfs.vfat -n GRML "$EFI_IMG" >/dev/null
92 $ROOTCMD mmd -i "$EFI_IMG" ::EFI
93 $ROOTCMD mmd -i "$EFI_IMG" ::EFI/BOOT
94 $ROOTCMD mcopy -i "$EFI_IMG" "$BOOTX64" ::EFI/BOOT/bootx64.efi >/dev/null
95 echo "Generated EFI image $BOOTX64"
96 echo "Generated bootx64 image $EFI_IMG"
99 rm -f "${target}/${TMP_CONFIG}"
100 echo "Generated Grub images"
103 ## END OF FILE #################################################################
104 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2