12ef74d22SJordan K. Hubbard#!/bin/sh 22ef74d22SJordan K. Hubbard# 32ef74d22SJordan K. Hubbard# Module: mkisoimages.sh 42ef74d22SJordan K. Hubbard# Author: Jordan K Hubbard 52ef74d22SJordan K. Hubbard# Date: 22 June 2001 62ef74d22SJordan K. Hubbard# 72ef74d22SJordan K. Hubbard# 82ef74d22SJordan K. Hubbard# This script is used by release/Makefile to build the (optional) ISO images 92ef74d22SJordan K. Hubbard# for a FreeBSD release. It is considered architecture dependent since each 102ef74d22SJordan K. Hubbard# platform has a slightly unique way of making bootable CDs. This script 112ef74d22SJordan K. Hubbard# is also allowed to generate any number of images since that is more of 122ef74d22SJordan K. Hubbard# publishing decision than anything else. 132ef74d22SJordan K. Hubbard# 142ef74d22SJordan K. Hubbard# Usage: 152ef74d22SJordan K. Hubbard# 162ef74d22SJordan K. Hubbard# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir] 172ef74d22SJordan K. Hubbard# 182ef74d22SJordan K. Hubbard# Where -b is passed if the ISO image should be made "bootable" by 192ef74d22SJordan K. Hubbard# whatever standards this architecture supports (may be unsupported), 202ef74d22SJordan K. Hubbard# image-label is the ISO image label, image-name is the filename of the 212ef74d22SJordan K. Hubbard# resulting ISO image, base-bits-dir contains the image contents and 222ef74d22SJordan K. Hubbard# extra-bits-dir, if provided, contains additional files to be merged 232ef74d22SJordan K. Hubbard# into base-bits-dir as part of making the image. 242ef74d22SJordan K. Hubbard 25a7d9306aSEd Masteset -e 26a7d9306aSEd Maste 27db8b5613SRebecca Cranscriptdir=$(dirname $(realpath $0)) 28db8b5613SRebecca Cran. ${scriptdir}/../../tools/boot/install-boot.sh 29db8b5613SRebecca Cran 306ea29847SBenno Riceif [ -z $ETDUMP ]; then 316ea29847SBenno Rice ETDUMP=etdump 326ea29847SBenno Ricefi 336ea29847SBenno Rice 346ea29847SBenno Riceif [ -z $MAKEFS ]; then 356ea29847SBenno Rice MAKEFS=makefs 366ea29847SBenno Ricefi 376ea29847SBenno Rice 386ea29847SBenno Riceif [ -z $MKIMG ]; then 396ea29847SBenno Rice MKIMG=mkimg 406ea29847SBenno Ricefi 416ea29847SBenno Rice 4293cf995aSEd Masteif [ "$1" = "-b" ]; then 4313cb0041SJessica Clarke MAKEFSARG="$4" 4413cb0041SJessica Clarkeelse 4513cb0041SJessica Clarke MAKEFSARG="$3" 4613cb0041SJessica Clarkefi 4713cb0041SJessica Clarke 4813cb0041SJessica Clarkeif [ -f ${MAKEFSARG} ]; then 4913cb0041SJessica Clarke BASEBITSDIR=`dirname ${MAKEFSARG}` 5013cb0041SJessica Clarke METALOG=${MAKEFSARG} 5113cb0041SJessica Clarkeelif [ -d ${MAKEFSARG} ]; then 5213cb0041SJessica Clarke BASEBITSDIR=${MAKEFSARG} 5313cb0041SJessica Clarke METALOG= 5413cb0041SJessica Clarkeelse 5513cb0041SJessica Clarke echo "${MAKEFSARG} must exist" 5613cb0041SJessica Clarke exit 1 5713cb0041SJessica Clarkefi 5813cb0041SJessica Clarke 5913cb0041SJessica Clarkeif [ "$1" = "-b" ]; then 602ef74d22SJordan K. Hubbard # This is highly x86-centric and will be used directly below. 61470f228fSMarius Strobl bootable="-o bootimage=i386;$BASEBITSDIR/boot/cdboot -o no-emul-boot" 627fad9ac9SNathan Whitehorn 6314113f12SMatt Macy # Make EFI system partition. 64db8b5613SRebecca Cran espfilename=$(mktemp /tmp/efiboot.XXXXXX) 65a0da9a62SGlen Barber # ESP file size in KB. 66bdccfea1SGlen Barber espsize="2048" 67*599273f9SAhmad Khalifa if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then 68*599273f9SAhmad Khalifa make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi bootx64 \ 69*599273f9SAhmad Khalifa ${BASEBITSDIR}/boot/loader_ia32.efi bootia32 70*599273f9SAhmad Khalifa else 71a0da9a62SGlen Barber make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi 72*599273f9SAhmad Khalifa fi 73db8b5613SRebecca Cran bootable="$bootable -o bootimage=i386;${espfilename} -o no-emul-boot -o platformid=efi" 747fad9ac9SNathan Whitehorn 752ef74d22SJordan K. Hubbard shift 762ef74d22SJordan K. Hubbardelse 772ef74d22SJordan K. Hubbard bootable="" 782ef74d22SJordan K. Hubbardfi 792ef74d22SJordan K. Hubbard 802ef74d22SJordan K. Hubbardif [ $# -lt 3 ]; then 8127065039SDevin Teske echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]" 822ef74d22SJordan K. Hubbard exit 1 832ef74d22SJordan K. Hubbardfi 842ef74d22SJordan K. Hubbard 8527065039SDevin TeskeLABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift 8627065039SDevin TeskeNAME="$1"; shift 8713cb0041SJessica Clarke# MAKEFSARG extracted already 8813cb0041SJessica Clarkeshift 892ef74d22SJordan K. Hubbard 90a2aef24aSEitan Adlerpublisher="The FreeBSD Project. https://www.FreeBSD.org/" 91470f228fSMarius Stroblecho "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab" 9213cb0041SJessica Clarkeif [ -n "${METALOG}" ]; then 9313cb0041SJessica Clarke metalogfilename=$(mktemp /tmp/metalog.XXXXXX) 9413cb0041SJessica Clarke cat ${METALOG} > ${metalogfilename} 9513cb0041SJessica Clarke echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} 9613cb0041SJessica Clarke MAKEFSARG=${metalogfilename} 9713cb0041SJessica Clarkefi 981a9b1c36SJessica Clarke$MAKEFS -D -N ${BASEBITSDIR}/etc -t cd9660 $bootable -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME" "$MAKEFSARG" "$@" 99470f228fSMarius Stroblrm -f "$BASEBITSDIR/etc/fstab" 100db8b5613SRebecca Cranrm -f ${espfilename} 10113cb0041SJessica Clarkeif [ -n "${METALOG}" ]; then 10213cb0041SJessica Clarke rm ${metalogfilename} 10313cb0041SJessica Clarkefi 1040279ac04SBenno Rice 1050279ac04SBenno Riceif [ "$bootable" != "" ]; then 1060279ac04SBenno Rice # Look for the EFI System Partition image we dropped in the ISO image. 1076ea29847SBenno Rice for entry in `$ETDUMP --format shell $NAME`; do 1080279ac04SBenno Rice eval $entry 1090279ac04SBenno Rice if [ "$et_platform" = "efi" ]; then 1100279ac04SBenno Rice espstart=`expr $et_lba \* 2048` 1110279ac04SBenno Rice espsize=`expr $et_sectors \* 512` 1120279ac04SBenno Rice espparam="-p efi::$espsize:$espstart" 1130279ac04SBenno Rice break 1140279ac04SBenno Rice fi 1150279ac04SBenno Rice done 1160279ac04SBenno Rice 1170279ac04SBenno Rice # Create a GPT image containing the partitions we need for hybrid boot. 118045c8f52SJessica Clarke hybridfilename=$(mktemp /tmp/hybrid.img.XXXXXX) 119cefe5879SJessica Clarke if [ "$(uname -s)" = "Linux" ]; then 120cefe5879SJessica Clarke imgsize=`stat -c %s "$NAME"` 121cefe5879SJessica Clarke else 122470f228fSMarius Strobl imgsize=`stat -f %z "$NAME"` 123cefe5879SJessica Clarke fi 1246ea29847SBenno Rice $MKIMG -s gpt \ 1250279ac04SBenno Rice --capacity $imgsize \ 126470f228fSMarius Strobl -b "$BASEBITSDIR/boot/pmbr" \ 127470f228fSMarius Strobl -p freebsd-boot:="$BASEBITSDIR/boot/isoboot" \ 12890d2f7c4SEmmanuel Vadot $espparam \ 129045c8f52SJessica Clarke -o $hybridfilename 1300279ac04SBenno Rice 1310279ac04SBenno Rice # Drop the PMBR, GPT, and boot code into the System Area of the ISO. 132045c8f52SJessica Clarke dd if=$hybridfilename of="$NAME" bs=32k count=1 conv=notrunc 133045c8f52SJessica Clarke rm -f $hybridfilename 1340279ac04SBenno Ricefi 135