diff --git a/release/amd64/make-memstick.sh b/release/amd64/make-memstick.sh --- a/release/amd64/make-memstick.sh +++ b/release/amd64/make-memstick.sh @@ -1,78 +1,22 @@ #!/bin/sh -# -# This script generates a "memstick image" (image that can be copied to a -# USB memory stick) from a directory tree. Note that the script does not -# clean up after itself very well for error conditions on purpose so the -# problem can be diagnosed (full filesystem most likely but ...). -# -# Usage: make-memstick.sh -# -# set -e -scriptdir=$(dirname $(realpath $0)) -. ${scriptdir}/../../tools/boot/install-boot.sh - -if [ "$(uname -s)" = "FreeBSD" ]; then - PATH=/bin:/usr/bin:/sbin:/usr/sbin - export PATH -fi - -if [ $# -ne 2 ]; then - echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file" - exit 1 -fi - -MAKEFSARG=${1} +memstick_mkimg() +{ + espfilename="" + memstick_make_esp_file -if [ -f ${MAKEFSARG} ]; then - BASEBITSDIR=`dirname ${MAKEFSARG}` - METALOG=${MAKEFSARG} -elif [ -d ${MAKEFSARG} ]; then - BASEBITSDIR=${MAKEFSARG} - METALOG= -else - echo "${MAKEFSARG} must exist" - exit 1 -fi + mkimg -s mbr \ + -b ${BASEBITSDIR}/boot/mbr \ + -p efi:=${espfilename} \ + -p freebsd:-"mkimg -s bsd -b ${BASEBITSDIR}/boot/boot -p freebsd-ufs:=${IMAGEFILE}.part" \ + -a 2 \ + -o ${IMAGEFILE} -if [ -e ${2} ]; then - echo "won't overwrite ${2}" - exit 1 -fi - -echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${BASEBITSDIR}/etc/fstab -echo 'root_rw_mount="NO"' > ${BASEBITSDIR}/etc/rc.conf.local -if [ -n "${METALOG}" ]; then - metalogfilename=$(mktemp /tmp/metalog.XXXXXX) - cat ${METALOG} > ${metalogfilename} - echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} - echo "./etc/rc.conf.local type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} - MAKEFSARG=${metalogfilename} -fi -makefs -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${MAKEFSARG} -rm ${BASEBITSDIR}/etc/fstab -rm ${BASEBITSDIR}/etc/rc.conf.local -if [ -n "${METALOG}" ]; then - rm ${metalogfilename} -fi - -# Make an ESP in a file. -espfilename=$(mktemp /tmp/efiboot.XXXXXX) -if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then - make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi bootx64 \ - ${BASEBITSDIR}/boot/loader_ia32.efi bootia32 -else - make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi -fi - -mkimg -s mbr \ - -b ${BASEBITSDIR}/boot/mbr \ - -p efi:=${espfilename} \ - -p freebsd:-"mkimg -s bsd -b ${BASEBITSDIR}/boot/boot -p freebsd-ufs:=${2}.part" \ - -a 2 \ - -o ${2} -rm ${espfilename} -rm ${2}.part + rm ${espfilename} +} +# Include the common framework. See description there. +scriptdir=$(dirname $(realpath $0)) +. ${scriptdir}/../scripts/make-memstick.sh diff --git a/release/arm64/make-memstick.sh b/release/arm64/make-memstick.sh --- a/release/arm64/make-memstick.sh +++ b/release/arm64/make-memstick.sh @@ -1,71 +1,20 @@ #!/bin/sh -# -# This script generates a "memstick image" (image that can be copied to a -# USB memory stick) from a directory tree. Note that the script does not -# clean up after itself very well for error conditions on purpose so the -# problem can be diagnosed (full filesystem most likely but ...). -# -# Usage: make-memstick.sh -# -# set -e -if [ "$(uname -s)" = "FreeBSD" ]; then - PATH=/bin:/usr/bin:/sbin:/usr/sbin - export PATH -fi +memstick_mkimg() +{ + espfilename="" + memstick_make_esp_file -scriptdir=$(dirname $(realpath $0)) -. ${scriptdir}/../../tools/boot/install-boot.sh - -if [ $# -ne 2 ]; then - echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file" - exit 1 -fi - -MAKEFSARG=${1} - -if [ -f ${MAKEFSARG} ]; then - BASEBITSDIR=`dirname ${MAKEFSARG}` - METALOG=${MAKEFSARG} -elif [ -d ${MAKEFSARG} ]; then - BASEBITSDIR=${MAKEFSARG} - METALOG= -else - echo "${MAKEFSARG} must exist" - exit 1 -fi + mkimg -s gpt \ + -p efi:=${espfilename} \ + -p freebsd-ufs:=${IMAGEFILE}.part \ + -o ${IMAGEFILE} -if [ -e ${2} ]; then - echo "won't overwrite ${2}" - exit 1 -fi - -echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${BASEBITSDIR}/etc/fstab -echo 'root_rw_mount="NO"' > ${BASEBITSDIR}/etc/rc.conf.local -if [ -n "${METALOG}" ]; then - metalogfilename=$(mktemp /tmp/metalog.XXXXXX) - cat ${METALOG} > ${metalogfilename} - echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} - echo "./etc/rc.conf.local type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} - MAKEFSARG=${metalogfilename} -fi -makefs -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${MAKEFSARG} -rm ${BASEBITSDIR}/etc/fstab -rm ${BASEBITSDIR}/etc/rc.conf.local -if [ -n "${METALOG}" ]; then - rm ${metalogfilename} -fi - -# Make an ESP in a file. -espfilename=$(mktemp /tmp/efiboot.XXXXXX) -make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi - -mkimg -s gpt \ - -p efi:=${espfilename} \ - -p freebsd-ufs:=${2}.part \ - -o ${2} -rm ${espfilename} -rm ${2}.part + rm ${espfilename} +} +# Include the common framework. See description there. +scriptdir=$(dirname $(realpath $0)) +. ${scriptdir}/../scripts/make-memstick.sh diff --git a/release/i386/make-memstick.sh b/release/i386/make-memstick.sh --- a/release/i386/make-memstick.sh +++ b/release/i386/make-memstick.sh @@ -1,63 +1,15 @@ #!/bin/sh -# -# This script generates a "memstick image" (image that can be copied to a -# USB memory stick) from a directory tree. Note that the script does not -# clean up after itself very well for error conditions on purpose so the -# problem can be diagnosed (full filesystem most likely but ...). -# -# Usage: make-memstick.sh -# -# set -e -if [ "$(uname -s)" = "FreeBSD" ]; then - PATH=/bin:/usr/bin:/sbin:/usr/sbin - export PATH -fi - -if [ $# -ne 2 ]; then - echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file" - exit 1 -fi - -MAKEFSARG=${1} - -if [ -f ${MAKEFSARG} ]; then - BASEBITSDIR=`dirname ${MAKEFSARG}` - METALOG=${MAKEFSARG} -elif [ -d ${MAKEFSARG} ]; then - BASEBITSDIR=${MAKEFSARG} - METALOG= -else - echo "${MAKEFSARG} must exist" - exit 1 -fi - -if [ -e ${2} ]; then - echo "won't overwrite ${2}" - exit 1 -fi - -echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${BASEBITSDIR}/etc/fstab -echo 'root_rw_mount="NO"' > ${BASEBITSDIR}/etc/rc.conf.local -if [ -n "${METALOG}" ]; then - metalogfilename=$(mktemp /tmp/metalog.XXXXXX) - cat ${METALOG} > ${metalogfilename} - echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} - echo "./etc/rc.conf.local type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} - MAKEFSARG=${metalogfilename} -fi -makefs -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${MAKEFSARG} -rm ${BASEBITSDIR}/etc/fstab -rm ${BASEBITSDIR}/etc/rc.conf.local -if [ -n "${METALOG}" ]; then - rm ${metalogfilename} -fi - -mkimg -s mbr \ - -b ${BASEBITSDIR}/boot/mbr \ - -p freebsd:-"mkimg -s bsd -b ${BASEBITSDIR}/boot/boot -p freebsd-ufs:=${2}.part" \ - -o ${2} -rm ${2}.part - +memstick_mkimg() +{ + mkimg -s mbr \ + -b ${BASEBITSDIR}/boot/mbr \ + -p freebsd:-"mkimg -s bsd -b ${BASEBITSDIR}/boot/boot -p freebsd-ufs:=${IMAGEFILE}.part" \ + -o ${IMAGEFILE} +} + +# Include the common framework. See description there. +scriptdir=$(dirname $(realpath $0)) +. ${scriptdir}/../scripts/make-memstick.sh diff --git a/release/riscv/make-memstick.sh b/release/riscv/make-memstick.sh --- a/release/riscv/make-memstick.sh +++ b/release/riscv/make-memstick.sh @@ -1,71 +1,20 @@ #!/bin/sh -# -# This script generates a "memstick image" (image that can be copied to a -# USB memory stick) from a directory tree. Note that the script does not -# clean up after itself very well for error conditions on purpose so the -# problem can be diagnosed (full filesystem most likely but ...). -# -# Usage: make-memstick.sh -# -# set -e -if [ "$(uname -s)" = "FreeBSD" ]; then - PATH=/bin:/usr/bin:/sbin:/usr/sbin - export PATH -fi +memstick_mkimg() +{ + espfilename="" + memstick_make_esp_file -scriptdir=$(dirname $(realpath $0)) -. ${scriptdir}/../../tools/boot/install-boot.sh - -if [ $# -ne 2 ]; then - echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file" - exit 1 -fi - -MAKEFSARG=${1} - -if [ -f ${MAKEFSARG} ]; then - BASEBITSDIR=`dirname ${MAKEFSARG}` - METALOG=${MAKEFSARG} -elif [ -d ${MAKEFSARG} ]; then - BASEBITSDIR=${MAKEFSARG} - METALOG= -else - echo "${MAKEFSARG} must exist" - exit 1 -fi + mkimg -s gpt \ + -p efi:=${espfilename} \ + -p freebsd-ufs:=${IMAGEFILE}.part \ + -o ${IMAGEFILE} -if [ -e ${2} ]; then - echo "won't overwrite ${2}" - exit 1 -fi - -echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${BASEBITSDIR}/etc/fstab -echo 'root_rw_mount="NO"' > ${BASEBITSDIR}/etc/rc.conf.local -if [ -n "${METALOG}" ]; then - metalogfilename=$(mktemp /tmp/metalog.XXXXXX) - cat ${METALOG} > ${metalogfilename} - echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} - echo "./etc/rc.conf.local type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} - MAKEFSARG=${metalogfilename} -fi -makefs -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${MAKEFSARG} -rm ${BASEBITSDIR}/etc/fstab -rm ${BASEBITSDIR}/etc/rc.conf.local -if [ -n "${METALOG}" ]; then - rm ${metalogfilename} -fi - -# Make an ESP in a file. -espfilename=$(mktemp /tmp/efiboot.XXXXXX) -make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi - -mkimg -s gpt \ - -p efi:=${espfilename} \ - -p freebsd-ufs:=${2}.part \ - -o ${2} -rm ${espfilename} -rm ${2}.part + rm ${espfilename} +} +# Include the common framework. See description there. +scriptdir=$(dirname $(realpath $0)) +. ${scriptdir}/../scripts/make-memstick.sh diff --git a/release/amd64/make-memstick.sh b/release/scripts/make-memstick.sh copy from release/amd64/make-memstick.sh copy to release/scripts/make-memstick.sh --- a/release/amd64/make-memstick.sh +++ b/release/scripts/make-memstick.sh @@ -7,24 +7,52 @@ # # Usage: make-memstick.sh # +# Each target architecture specific implementation currently needs to provide +# an implementation of a memstick_mkimg() function taking IMAGEFILE.part +# generated in here and providing IMAGEFILE as a result. # set -e -scriptdir=$(dirname $(realpath $0)) -. ${scriptdir}/../../tools/boot/install-boot.sh +################################################################################ -if [ "$(uname -s)" = "FreeBSD" ]; then - PATH=/bin:/usr/bin:/sbin:/usr/sbin - export PATH -fi +# +# Helper function for amd64/arm64/riscv to create the ESP. +# +memstick_make_esp_file() +{ + + # Make an ESP in a file. + scriptdir=$(dirname $(realpath $0)) + . ${scriptdir}/../../tools/boot/install-boot.sh + + espfilename=$(mktemp /tmp/efiboot.XXXXXX) + # We assume it is safe to do this here as none of the other archs + # should produce this file. + if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then + make_esp_file ${espfilename} ${fat32min} \ + ${BASEBITSDIR}/boot/loader.efi bootx64 \ + ${BASEBITSDIR}/boot/loader_ia32.efi bootia32 + else + make_esp_file ${espfilename} ${fat32min} \ + ${BASEBITSDIR}/boot/loader.efi + fi +} + +################################################################################ if [ $# -ne 2 ]; then echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file" exit 1 fi +if [ "$(uname -s)" = "FreeBSD" ]; then + PATH=/bin:/usr/bin:/sbin:/usr/sbin + export PATH +fi + MAKEFSARG=${1} +IMAGEFILE=${2} if [ -f ${MAKEFSARG} ]; then BASEBITSDIR=`dirname ${MAKEFSARG}` @@ -37,8 +65,8 @@ exit 1 fi -if [ -e ${2} ]; then - echo "won't overwrite ${2}" +if [ -e ${IMAGEFILE} ]; then + echo "won't overwrite ${IMAGEFILE}" exit 1 fi @@ -51,28 +79,14 @@ echo "./etc/rc.conf.local type=file uname=root gname=wheel mode=0644" >> ${metalogfilename} MAKEFSARG=${metalogfilename} fi -makefs -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${MAKEFSARG} +makefs -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${IMAGEFILE}.part ${MAKEFSARG} rm ${BASEBITSDIR}/etc/fstab rm ${BASEBITSDIR}/etc/rc.conf.local if [ -n "${METALOG}" ]; then rm ${metalogfilename} fi -# Make an ESP in a file. -espfilename=$(mktemp /tmp/efiboot.XXXXXX) -if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then - make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi bootx64 \ - ${BASEBITSDIR}/boot/loader_ia32.efi bootia32 -else - make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi -fi +memstick_mkimg -mkimg -s mbr \ - -b ${BASEBITSDIR}/boot/mbr \ - -p efi:=${espfilename} \ - -p freebsd:-"mkimg -s bsd -b ${BASEBITSDIR}/boot/boot -p freebsd-ufs:=${2}.part" \ - -a 2 \ - -o ${2} -rm ${espfilename} -rm ${2}.part +rm ${IMAGEFILE}.part