1#!/bin/sh
2#
3# Generate an EFI bootable disk image
4
5set -e
6
7function help() {
8	echo "Usage: ${0} [OPTIONS] <ipxe.efi>"
9	echo
10	echo "where OPTIONS are:"
11	echo " -h       Show this help"
12	echo " -b       Specify boot file name (e.g. bootx64.efi)"
13	echo " -o FILE  Save disk image to file"
14}
15
16BOOT=bootx64.efi
17
18while getopts "hb:o:" opt; do
19	case ${opt} in
20		h)
21			help
22			exit 0
23			;;
24		b)
25			BOOT="${OPTARG}"
26			;;
27		o)
28			OUT="${OPTARG}"
29			;;
30	esac
31done
32
33shift $((OPTIND - 1))
34IN=$1
35
36if [ -z "${IN}" ]; then
37	echo "${0}: no input file given" >&2
38	help
39	exit 1
40fi
41
42if [ -z "${OUT}" ]; then
43	echo "${0}: no output file given" >&2
44	help
45	exit 1
46fi
47
48# Create sparse output file
49rm -f ${OUT}
50truncate -s 1440K ${OUT}
51
52# Format disk
53mformat -i ${OUT} -f 1440 ::
54
55# Create directory structure
56mmd -i ${OUT} ::efi
57mmd -i ${OUT} ::efi/boot
58
59# Copy bootable image
60mcopy -i ${OUT} ${IN} ::efi/boot/${BOOT}
61