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