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