Ensure GRUB finds the running ISO
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 45-grub-images
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/45-grub-images
3 # Purpose:       create grub images for use in ISO
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 ################################################################################
8
9 set -e
10 set -u
11
12 TMP_CONFIG="/tmp/grub_config_efi"
13
14 # this allows us to find this specific Grml ISO,
15 # even if there are multiple Grml ISOs present
16 bootfile="${GRML_NAME}_$(TZ=UTC date +%s)"
17 echo "$bootfile" > "${target}/"boot/grub/bootfile.txt
18
19 cat > "${target}/${TMP_CONFIG}" <<EOF
20 search.file /conf/bootfile_$bootfile root
21 set prefix=(\$root)/boot/grub
22 insmod normal
23 normal
24 echo "E: Could not find root device (for /conf/bootfile_$bootfile)!"
25 EOF
26
27 ARCHS=(i386-pc)
28 declare -A ADDITIONAL_MODULES
29 ADDITIONAL_MODULES[i386-pc]="biosdisk"
30
31 if ifclass AMD64 ; then
32   if [ -r "${target}"/usr/lib/grub/x86_64-efi/moddep.lst ] ; then
33     ARCHS+=(x86_64-efi)
34     ADDITIONAL_MODULES[x86_64-efi]="efi_gop efi_uga"
35   else
36     echo "/usr/lib/grub/x86_64-efi/moddep.lst could not be found, skipping."
37     echo "NOTE: grub-efi-amd64-bin not installed?"
38   fi
39 fi
40
41 if ifclass I386 ; then
42   if [ -r "${target}"/usr/lib/grub/i386-efi/moddep.lst ] ; then
43     ARCHS+=(i386-efi)
44     ADDITIONAL_MODULES[i386-efi]="efi_gop efi_uga"
45   else
46     echo "/usr/lib/grub/i386-efi/moddep.lst could not be found, skipping."
47     echo "NOTE: grub-efi-ia32 not installed?"
48   fi
49 fi
50
51 for arch in "${ARCHS[@]}" ; do
52   filename=''
53   case "$arch" in
54     i386-pc)    filename=/boot/grub/grub.img ;;
55     x86_64-efi) filename=/boot/bootx64.efi   ;;
56     i386-efi)   filename=/boot/bootia32.efi  ;;
57   esac
58
59   $ROOTCMD grub-mkimage -O $arch -o "$filename" --prefix=/boot/grub/ --config="$TMP_CONFIG" \
60     echo iso9660 part_msdos search_fs_file test \
61     fat ext2 reiserfs xfs btrfs squash4 part_gpt lvm \
62     ${ADDITIONAL_MODULES[$arch]}
63 done
64
65 rm -f "${target}/${TMP_CONFIG}"
66 echo "Generated Grub images"
67
68 ## END OF FILE #################################################################
69 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2