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