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