summarylogtreecommitdiffstats
path: root/grub
blob: c79c9da2b9a19cb95b8bffe7db5a912cb4b782b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /bin/sh -e
########################################################
# This script generates an iPXE entry on grub.cfg      #
# if ipxe is installed on the system.                  #
########################################################

prefix="/usr"
exec_prefix="${prefix}"

datarootdir="/usr/share"
datadir="${datarootdir}"

. "${datadir}/grub/grub-mkconfig_lib"

IPXE_BZIMAGE="/boot/ipxe/ipxe.lkrn"
case $(uname -m) in
	x86_64)
		IPXE_EFI="/usr/lib/ipxe/efi-x86_64.efi" ;;
	*)
		IPXE_EFI="/usr/lib/ipxe/efi-i386.efi" ;;
esac
EFI_MOUNT="$(lsblk -l -o 'MOUNTPOINT,PARTTYPE' -n | grep 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' | head -n1 | cut -d' ' -f1)"
IPXE_EFI_DEST="${EFI_MOUNT}/EFI/ipxe/ipxe.efi"
CLASS="--class ipxe --class gnu --class tool"

if [ -d /sys/firmware/efi ]; then
	if [ -n "${EFI_MOUNT}" ]; then
		# EFI system
		# This can chainload from EFI system partition only!
		echo "Setting up iPXE for EFI chainloading" >&2
		mkdir -p "$(dirname ${IPXE_EFI_DEST})"
		cp ${IPXE_EFI} "${IPXE_EFI_DEST}"
		echo "menuentry \"iPXE - Open Source Boot Firmware\" ${CLASS} {"
		prepare_grub_to_access_device $(${grub_probe} --target=device ${IPXE_EFI_DEST}) | sed -e "s/^/\t/"
		echo -e "\techo 'Loading iPXE EFI ...'"
		echo -e "\tchainloader $(make_system_path_relative_to_its_root ${IPXE_EFI_DEST})"
		echo "}"
	fi
else
	if [ -e ${IPXE_BZIMAGE} ] && is_path_readable_by_grub ${IPXE_BZIMAGE}; then
		# image exists, create menu entry
		echo "Found iPXE bzImage: ${IPXE_BZIMAGE}" >&2
		echo "menuentry \"iPXE - Open Source Boot Firmware\" ${CLASS} {"
		prepare_grub_to_access_device $(${grub_probe} --target=device ${IPXE_BZIMAGE}) | sed -e "s/^/\t/"
		echo -e "\techo 'Loading iPXE ...'"
		echo -e "\tlinux16 $(make_system_path_relative_to_its_root ${IPXE_BZIMAGE})"
		echo "}"
	fi
fi