xref: /freebsd/release/amd64/mkisoimages.sh (revision 38effe887ee979f91ad5abf42a2291558e7ff8d1)
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	BASEBITSDIR="$4"
45	# This is highly x86-centric and will be used directly below.
46	bootable="-o bootimage=i386;$BASEBITSDIR/boot/cdboot -o no-emul-boot"
47
48	# Make EFI system partition.
49	# The ISO file is a special case, in that it only has a maximum of
50	# 800 KB available for the boot code. So make an 800 KB ESP
51	espfilename=$(mktemp /tmp/efiboot.XXXXXX)
52	make_esp_file ${espfilename} 800 ${BASEBITSDIR}/boot/loader.efi
53	bootable="$bootable -o bootimage=i386;${espfilename} -o no-emul-boot -o platformid=efi"
54
55	shift
56else
57	BASEBITSDIR="$3"
58	bootable=""
59fi
60
61if [ $# -lt 3 ]; then
62	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
63	exit 1
64fi
65
66LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
67NAME="$1"; shift
68
69publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
70echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
71$MAKEFS -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$@"
72rm -f "$BASEBITSDIR/etc/fstab"
73rm -f ${espfilename}
74
75if [ "$bootable" != "" ]; then
76	# Look for the EFI System Partition image we dropped in the ISO image.
77	for entry in `$ETDUMP --format shell $NAME`; do
78		eval $entry
79		if [ "$et_platform" = "efi" ]; then
80			espstart=`expr $et_lba \* 2048`
81			espsize=`expr $et_sectors \* 512`
82			espparam="-p efi::$espsize:$espstart"
83			break
84		fi
85	done
86
87	# Create a GPT image containing the partitions we need for hybrid boot.
88	imgsize=`stat -f %z "$NAME"`
89	$MKIMG -s gpt \
90	    --capacity $imgsize \
91	    -b "$BASEBITSDIR/boot/pmbr" \
92	    $espparam \
93	    -p freebsd-boot:="$BASEBITSDIR/boot/isoboot" \
94	    -o hybrid.img
95
96	# Drop the PMBR, GPT, and boot code into the System Area of the ISO.
97	dd if=hybrid.img of="$NAME" bs=32k count=1 conv=notrunc
98	rm -f hybrid.img
99fi
100