xref: /freebsd/release/amd64/mkisoimages.sh (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
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	espfilename=$(mktemp /tmp/efiboot.XXXXXX)
50	# ESP file size in KB.
51	espsize="2048"
52	make_esp_file ${espfilename} ${espsize} ${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