xref: /freebsd/release/amd64/mkisoimages.sh (revision cc426dd31990b8b50b210efc450e404596548ca1)
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
28if [ -z $ETDUMP ]; then
29	ETDUMP=etdump
30fi
31
32if [ -z $MAKEFS ]; then
33	MAKEFS=makefs
34fi
35
36if [ -z $MKIMG ]; then
37	MKIMG=mkimg
38fi
39
40if [ "$1" = "-b" ]; then
41	BASEBITSDIR="$4"
42	# This is highly x86-centric and will be used directly below.
43	bootable="-o bootimage=i386;$BASEBITSDIR/boot/cdboot -o no-emul-boot"
44
45	# Make EFI system partition (should be done with makefs in the future)
46	dd if=/dev/zero of=efiboot.img bs=4k count=200
47	device=`mdconfig -a -t vnode -f efiboot.img`
48	newfs_msdos -F 12 -m 0xf8 /dev/$device
49	mkdir efi
50	mount -t msdosfs /dev/$device efi
51	mkdir -p efi/efi/boot
52	cp "$BASEBITSDIR/boot/loader.efi" efi/efi/boot/bootx64.efi
53	umount efi
54	rmdir efi
55	mdconfig -d -u $device
56	bootable="$bootable -o bootimage=i386;efiboot.img -o no-emul-boot -o platformid=efi"
57
58	shift
59else
60	BASEBITSDIR="$3"
61	bootable=""
62fi
63
64if [ $# -lt 3 ]; then
65	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
66	exit 1
67fi
68
69LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
70NAME="$1"; shift
71
72publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
73echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
74$MAKEFS -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$@"
75rm -f "$BASEBITSDIR/etc/fstab"
76rm -f efiboot.img
77
78if [ "$bootable" != "" ]; then
79	# Look for the EFI System Partition image we dropped in the ISO image.
80	for entry in `$ETDUMP --format shell $NAME`; do
81		eval $entry
82		if [ "$et_platform" = "efi" ]; then
83			espstart=`expr $et_lba \* 2048`
84			espsize=`expr $et_sectors \* 512`
85			espparam="-p efi::$espsize:$espstart"
86			break
87		fi
88	done
89
90	# Create a GPT image containing the partitions we need for hybrid boot.
91	imgsize=`stat -f %z "$NAME"`
92	$MKIMG -s gpt \
93	    --capacity $imgsize \
94	    -b "$BASEBITSDIR/boot/pmbr" \
95	    $espparam \
96	    -p freebsd-boot:="$BASEBITSDIR/boot/isoboot" \
97	    -o hybrid.img
98
99	# Drop the PMBR, GPT, and boot code into the System Area of the ISO.
100	dd if=hybrid.img of="$NAME" bs=32k count=1 conv=notrunc
101	rm -f hybrid.img
102fi
103