Merge remote-tracking branch 'origin/github/pr/145'
[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 # arm64 doesn't provide /usr/lib/grub/i386-efi, so we don't include
32 # i386-pc in $ARCHS (whereas on AMD64 we have both i386-pc + x86_64-efi)
33 if ifclass ARM64 ; then
34   if [ -r "${target}"/usr/lib/grub/arm64-efi/moddep.lst ] ; then
35     ARCHS=(arm64-efi)
36     # NOTE: efi_uga (EFI Universal Graphics Adapter) is deprecated + unavailable on arm64
37     ADDITIONAL_MODULES[arm64-efi]="efi_gop"  # no efi_uga available
38   else
39     echo "/usr/lib/grub/arm64-efi/moddep.lst.lst could not be found, skipping."
40     echo "NOTE: grub-efi-arm64-bin not installed?"
41   fi
42 fi
43
44 if ifclass AMD64 ; then
45   if [ -r "${target}"/usr/lib/grub/x86_64-efi/moddep.lst ] ; then
46     ARCHS+=(x86_64-efi)
47     ADDITIONAL_MODULES[x86_64-efi]="efi_gop efi_uga"
48   else
49     echo "/usr/lib/grub/x86_64-efi/moddep.lst could not be found, skipping."
50     echo "NOTE: grub-efi-amd64-bin not installed?"
51   fi
52 fi
53
54 if ifclass I386 ; then
55   if [ -r "${target}"/usr/lib/grub/i386-efi/moddep.lst ] ; then
56     ARCHS+=(i386-efi)
57     ADDITIONAL_MODULES[i386-efi]="efi_gop efi_uga"
58   else
59     echo "/usr/lib/grub/i386-efi/moddep.lst could not be found, skipping."
60     echo "NOTE: grub-efi-ia32 not installed?"
61   fi
62 fi
63
64 for arch in "${ARCHS[@]}" ; do
65   filename=''
66   case "$arch" in
67     i386-pc)    filename=/boot/grub/grub.img ;;
68     x86_64-efi) filename=/boot/bootx64.efi   ;;
69     i386-efi)   filename=/boot/bootia32.efi  ;;
70     arm64-efi)  filename=/boot/bootaa64.efi  ;;
71   esac
72
73   $ROOTCMD grub-mkimage -O $arch -o "$filename" --prefix=/boot/grub/ --config="$TMP_CONFIG" \
74     echo iso9660 part_msdos search_fs_file test \
75     fat ext2 reiserfs xfs btrfs squash4 part_gpt lvm \
76     ${ADDITIONAL_MODULES[$arch]}
77 done
78
79 rm -f "${target}/${TMP_CONFIG}"
80 echo "Generated Grub images"
81
82 ## END OF FILE #################################################################
83 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2