Rework EFI file copy/moving
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 45-efi
1 #!/bin/bash
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 ################################################################################
8
9 set -e
10
11 if ! ifclass AMD64 ; then
12   echo "Not in AMD64 class but EFI feature is restricted to amd64 only, skipping."
13   exit 0
14 fi
15
16 set -u
17
18 if ! [ -r "${target}"/usr/lib/grub/x86_64-efi/moddep.lst ] ; then
19   echo "/usr/lib/grub/x86_64-efi/moddep.lst could not be found, skipping."
20   echo "NOTE: grub-efi-amd64-bin not installed?"
21   exit 0
22 fi
23
24 BOOTX64="${target}/boot/bootx64.efi"
25 EFI_IMG="${target}/boot/efi.img"
26 TMP_CONFIG="${target}/tmp/grub_config_efi"
27
28 rm -f "$BOOTX64" "$EFI_IMG" "$TMP_CONFIG"
29
30 cat > "$TMP_CONFIG" <<EOF
31 search --set -f /conf/bootid.txt root
32 if [ -e /boot/grub/grub.cfg ]; then
33  set prefix=(\$root)/boot/grub
34  configfile /boot/grub/grub.cfg
35 else
36  echo "E: Could not find root device!"
37 fi
38 EOF
39
40 BOOTX64="${BOOTX64##${target}}"
41 EFI_IMG="${EFI_IMG##${target}}"
42 TMP_CONFIG="${TMP_CONFIG##${target}}"
43
44 $ROOTCMD grub-mkimage -O x86_64-efi -o "$BOOTX64" --prefix=/boot/grub/ --config="$TMP_CONFIG" \
45   bitmap boot btrfs cat chain cmp configfile cpio echo efi_gop       \
46   efi_uga elf ext2 fat gfxmenu gfxterm gzio help iso9660 jpeg linux  \
47   loopback lvm minicmd multiboot normal part_gpt part_msdos play png \
48   probe raid regexp reiserfs search search_fs_file search_fs_uuid    \
49   search_label squash4 terminal test video videoinfo xfs
50
51 if ! [ -r "${target}/${BOOTX64}" ] ; then
52   echo "Can not access grub efi image." >&2
53   exit 1
54 fi
55
56 SIZE=$(du -sk "${target}/${BOOTX64}" | awk -F" " '{print $1'})
57 SIZE=$(((($SIZE / 32 )+2)*32))
58
59 dd if=/dev/zero of="${target}/${EFI_IMG}" bs=1k count="$SIZE" 2>/dev/null
60 $ROOTCMD mkfs.vfat -n GRML "$EFI_IMG" >/dev/null
61 $ROOTCMD mmd -i "$EFI_IMG" ::EFI
62 $ROOTCMD mmd -i "$EFI_IMG" ::EFI/BOOT
63 $ROOTCMD mcopy -i "$EFI_IMG" "$BOOTX64" ::EFI/BOOT/bootx64.efi >/dev/null
64
65 rm -f "${target}/${TMP_CONFIG}"
66
67 echo "Generated EFI image $BOOTX64"
68 echo "Generated bootx64 image $EFI_IMG"
69
70 ## END OF FILE #################################################################
71 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2