xref: /freebsd/release/amd64/mkisoimages.sh (revision 9f0f30bc1f5f08d25243952bad3fdc6e13a75c2a)
1#!/bin/sh
2#
3# Module: mkisoimages.sh
4# Author: Jordan K Hubbard
5# Date:   22 June 2001
6#
7#
8# This script is used by release/Makefile to build the (optional) ISO images
9# for a FreeBSD release.  It is considered architecture dependent since each
10# platform has a slightly unique way of making bootable CDs.  This script
11# is also allowed to generate any number of images since that is more of
12# publishing decision than anything else.
13#
14# Usage:
15#
16# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir]
17#
18# Where -b is passed if the ISO image should be made "bootable" by
19# whatever standards this architecture supports (may be unsupported),
20# image-label is the ISO image label, image-name is the filename of the
21# resulting ISO image, base-bits-dir contains the image contents and
22# extra-bits-dir, if provided, contains additional files to be merged
23# into base-bits-dir as part of making the image.
24
25set -e
26
27scriptdir=$(dirname $(realpath $0))
28. ${scriptdir}/../scripts/tools.subr
29. ${scriptdir}/../../tools/boot/install-boot.sh
30
31if [ "$1" = "-b" ]; then
32	MAKEFSARG="$4"
33else
34	MAKEFSARG="$3"
35fi
36
37if [ -f ${MAKEFSARG} ]; then
38	BASEBITSDIR=`dirname ${MAKEFSARG}`
39	METALOG=${MAKEFSARG}
40elif [ -d ${MAKEFSARG} ]; then
41	BASEBITSDIR=${MAKEFSARG}
42	METALOG=
43else
44	echo "${MAKEFSARG} must exist"
45	exit 1
46fi
47
48if [ "$1" = "-b" ]; then
49	# This is highly x86-centric and will be used directly below.
50	bootable="-o bootimage=i386;$BASEBITSDIR/boot/cdboot -o no-emul-boot"
51
52	# Make EFI system partition.
53	espfilename=$(mktemp /tmp/efiboot.XXXXXX)
54	# ESP file size in KB.
55	espsize="2048"
56	if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then
57		make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi bootx64 \
58		    ${BASEBITSDIR}/boot/loader_ia32.efi bootia32
59	else
60		make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi
61	fi
62	bootable="$bootable -o bootimage=i386;${espfilename} -o no-emul-boot -o platformid=efi"
63
64	shift
65else
66	bootable=""
67fi
68
69if [ $# -lt 3 ]; then
70	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
71	exit 1
72fi
73
74LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
75NAME="$1"; shift
76# MAKEFSARG extracted already
77shift
78
79publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
80echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
81if [ -n "${METALOG}" ]; then
82	metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
83	cat ${METALOG} > ${metalogfilename}
84	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
85	MAKEFSARG=${metalogfilename}
86fi
87$MAKEFS -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@"
88rm -f "$BASEBITSDIR/etc/fstab"
89rm -f ${espfilename}
90if [ -n "${METALOG}" ]; then
91	rm ${metalogfilename}
92fi
93
94if [ "$bootable" != "" ]; then
95	# Look for the EFI System Partition image we dropped in the ISO image.
96	for entry in `$ETDUMP --format shell $NAME`; do
97		eval $entry
98		if [ "$et_platform" = "efi" ]; then
99			espstart=`expr $et_lba \* 2048`
100			espsize=`expr $et_sectors \* 512`
101			espparam="-p efi::$espsize:$espstart"
102			break
103		fi
104	done
105
106	# Create a GPT image containing the partitions we need for hybrid boot.
107	hybridfilename=$(mktemp /tmp/hybrid.img.XXXXXX)
108	if [ "$(uname -s)" = "Linux" ]; then
109		imgsize=`stat -c %s "$NAME"`
110	else
111		imgsize=`stat -f %z "$NAME"`
112	fi
113	$MKIMG -s gpt \
114	    --capacity $imgsize \
115	    -b "$BASEBITSDIR/boot/pmbr" \
116	    -p freebsd-boot:="$BASEBITSDIR/boot/isoboot" \
117	    $espparam \
118	    -o $hybridfilename
119
120	# Drop the PMBR, GPT, and boot code into the System Area of the ISO.
121	dd if=$hybridfilename of="$NAME" bs=32k count=1 conv=notrunc
122	rm -f $hybridfilename
123fi
124