]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/amd64/mkisoimages.sh
Merge bmake-20220418
[FreeBSD/FreeBSD.git] / release / amd64 / mkisoimages.sh
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
26 set -e
27
28 scriptdir=$(dirname $(realpath $0))
29 . ${scriptdir}/../../tools/boot/install-boot.sh
30
31 if [ -z $ETDUMP ]; then
32         ETDUMP=etdump
33 fi
34
35 if [ -z $MAKEFS ]; then
36         MAKEFS=makefs
37 fi
38
39 if [ -z $MKIMG ]; then
40         MKIMG=mkimg
41 fi
42
43 if [ "$1" = "-b" ]; then
44         MAKEFSARG="$4"
45 else
46         MAKEFSARG="$3"
47 fi
48
49 if [ -f ${MAKEFSARG} ]; then
50         BASEBITSDIR=`dirname ${MAKEFSARG}`
51         METALOG=${MAKEFSARG}
52 elif [ -d ${MAKEFSARG} ]; then
53         BASEBITSDIR=${MAKEFSARG}
54         METALOG=
55 else
56         echo "${MAKEFSARG} must exist"
57         exit 1
58 fi
59
60 if [ "$1" = "-b" ]; then
61         # This is highly x86-centric and will be used directly below.
62         bootable="-o bootimage=i386;$BASEBITSDIR/boot/cdboot -o no-emul-boot"
63
64         # Make EFI system partition.
65         espfilename=$(mktemp /tmp/efiboot.XXXXXX)
66         # ESP file size in KB.
67         espsize="2048"
68         make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi
69         bootable="$bootable -o bootimage=i386;${espfilename} -o no-emul-boot -o platformid=efi"
70
71         shift
72 else
73         bootable=""
74 fi
75
76 if [ $# -lt 3 ]; then
77         echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]"
78         exit 1
79 fi
80
81 LABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
82 NAME="$1"; shift
83 # MAKEFSARG extracted already
84 shift
85
86 publisher="The FreeBSD Project.  https://www.FreeBSD.org/"
87 echo "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
88 if [ -n "${METALOG}" ]; then
89         metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
90         cat ${METALOG} > ${metalogfilename}
91         echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
92         MAKEFSARG=${metalogfilename}
93 fi
94 $MAKEFS -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@"
95 rm -f "$BASEBITSDIR/etc/fstab"
96 rm -f ${espfilename}
97 if [ -n "${METALOG}" ]; then
98         rm ${metalogfilename}
99 fi
100
101 if [ "$bootable" != "" ]; then
102         # Look for the EFI System Partition image we dropped in the ISO image.
103         for entry in `$ETDUMP --format shell $NAME`; do
104                 eval $entry
105                 if [ "$et_platform" = "efi" ]; then
106                         espstart=`expr $et_lba \* 2048`
107                         espsize=`expr $et_sectors \* 512`
108                         espparam="-p efi::$espsize:$espstart"
109                         break
110                 fi
111         done
112
113         # Create a GPT image containing the partitions we need for hybrid boot.
114         hybridfilename=$(mktemp /tmp/hybrid.img.XXXXXX)
115         imgsize=`stat -f %z "$NAME"`
116         $MKIMG -s gpt \
117             --capacity $imgsize \
118             -b "$BASEBITSDIR/boot/pmbr" \
119             -p freebsd-boot:="$BASEBITSDIR/boot/isoboot" \
120             $espparam \
121             -o $hybridfilename
122
123         # Drop the PMBR, GPT, and boot code into the System Area of the ISO.
124         dd if=$hybridfilename of="$NAME" bs=32k count=1 conv=notrunc
125         rm -f $hybridfilename
126 fi