xref: /freebsd/release/amd64/mkisoimages.sh (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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}/../../tools/boot/install-boot.sh
29
30if [ -z $ETDUMP ]; then
31	ETDUMP=etdump
32fi
33
34if [ -z $MAKEFS ]; then
35	MAKEFS=makefs
36fi
37
38if [ -z $MKIMG ]; then
39	MKIMG=mkimg
40fi
41
42if [ "$1" = "-b" ]; then
43	MAKEFSARG="$4"
44else
45	MAKEFSARG="$3"
46fi
47
48if [ -f ${MAKEFSARG} ]; then
49	BASEBITSDIR=`dirname ${MAKEFSARG}`
50	METALOG=${MAKEFSARG}
51elif [ -d ${MAKEFSARG} ]; then
52	BASEBITSDIR=${MAKEFSARG}
53	METALOG=
54else
55	echo "${MAKEFSARG} must exist"
56	exit 1
57fi
58
59if [ "$1" = "-b" ]; then
60	# This is highly x86-centric and will be used directly below.
61	bootable="-o bootimage=i386;$BASEBITSDIR/boot/cdboot -o no-emul-boot"
62
63	# Make EFI system partition.
64	espfilename=$(mktemp /tmp/efiboot.XXXXXX)
65	# ESP file size in KB.
66	espsize="2048"
67	make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi
68	bootable="$bootable -o bootimage=i386;${espfilename} -o no-emul-boot -o platformid=efi"
69
70	shift
71else
72	bootable=""
73fi
74
75if [ $# -lt 3 ]; then
76	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
77	exit 1
78fi
79
80LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
81NAME="$1"; shift
82# MAKEFSARG extracted already
83shift
84
85publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
86echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
87if [ -n "${METALOG}" ]; then
88	metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
89	cat ${METALOG} > ${metalogfilename}
90	echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
91	MAKEFSARG=${metalogfilename}
92fi
93$MAKEFS -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@"
94rm -f "$BASEBITSDIR/etc/fstab"
95rm -f ${espfilename}
96if [ -n "${METALOG}" ]; then
97	rm ${metalogfilename}
98fi
99
100if [ "$bootable" != "" ]; then
101	# Look for the EFI System Partition image we dropped in the ISO image.
102	for entry in `$ETDUMP --format shell $NAME`; do
103		eval $entry
104		if [ "$et_platform" = "efi" ]; then
105			espstart=`expr $et_lba \* 2048`
106			espsize=`expr $et_sectors \* 512`
107			espparam="-p efi::$espsize:$espstart"
108			break
109		fi
110	done
111
112	# Create a GPT image containing the partitions we need for hybrid boot.
113	hybridfilename=$(mktemp /tmp/hybrid.img.XXXXXX)
114	if [ "$(uname -s)" = "Linux" ]; then
115		imgsize=`stat -c %s "$NAME"`
116	else
117		imgsize=`stat -f %z "$NAME"`
118	fi
119	$MKIMG -s gpt \
120	    --capacity $imgsize \
121	    -b "$BASEBITSDIR/boot/pmbr" \
122	    -p freebsd-boot:="$BASEBITSDIR/boot/isoboot" \
123	    $espparam \
124	    -o $hybridfilename
125
126	# Drop the PMBR, GPT, and boot code into the System Area of the ISO.
127	dd if=$hybridfilename of="$NAME" bs=32k count=1 conv=notrunc
128	rm -f $hybridfilename
129fi
130