2010-02-18 15:45:43 +00:00
|
|
|
#!/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
|
2014-04-25 18:46:54 +00:00
|
|
|
# problem can be diagnosed (full filesystem most likely but ...).
|
2010-02-18 15:45:43 +00:00
|
|
|
#
|
2022-02-28 22:37:03 +00:00
|
|
|
# Usage: make-memstick.sh <directory tree or manifest> <image filename>
|
2010-02-18 15:45:43 +00:00
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
2017-09-05 12:57:45 +00:00
|
|
|
set -e
|
|
|
|
|
2018-12-20 19:39:37 +00:00
|
|
|
scriptdir=$(dirname $(realpath $0))
|
|
|
|
. ${scriptdir}/../../tools/boot/install-boot.sh
|
|
|
|
|
2010-02-18 15:45:43 +00:00
|
|
|
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
|
|
|
export PATH
|
|
|
|
|
|
|
|
if [ $# -ne 2 ]; then
|
2022-02-28 22:37:03 +00:00
|
|
|
echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file"
|
2014-04-25 19:43:18 +00:00
|
|
|
exit 1
|
2010-02-18 15:45:43 +00:00
|
|
|
fi
|
|
|
|
|
2022-02-28 22:37:03 +00:00
|
|
|
MAKEFSARG=${1}
|
|
|
|
|
|
|
|
if [ -f ${MAKEFSARG} ]; then
|
|
|
|
BASEBITSDIR=`dirname ${MAKEFSARG}`
|
|
|
|
METALOG=${MAKEFSARG}
|
|
|
|
elif [ -d ${MAKEFSARG} ]; then
|
|
|
|
BASEBITSDIR=${MAKEFSARG}
|
|
|
|
METALOG=
|
|
|
|
else
|
|
|
|
echo "${MAKEFSARG} must exist"
|
2014-04-25 19:43:18 +00:00
|
|
|
exit 1
|
2010-02-18 15:45:43 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e ${2} ]; then
|
2014-04-25 19:43:18 +00:00
|
|
|
echo "won't overwrite ${2}"
|
|
|
|
exit 1
|
2010-02-18 15:45:43 +00:00
|
|
|
fi
|
|
|
|
|
2022-02-28 22:37:03 +00:00
|
|
|
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 -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
|
2010-02-18 15:45:43 +00:00
|
|
|
|
2018-12-20 19:39:37 +00:00
|
|
|
# Make an ESP in a file.
|
|
|
|
espfilename=$(mktemp /tmp/efiboot.XXXXXX)
|
2022-02-28 22:37:03 +00:00
|
|
|
make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi
|
2018-12-20 19:39:37 +00:00
|
|
|
|
switch amd64 memstick installer images to MBR
A good number of BIOSes have trouble booting from GPT in non-UEFI mode.
This is commonly reported with Lenovo desktops and laptops (including
X220, X230, T430, and E31) and Dell systems. Although UEFI is the
preferred amd64 boot method on recent hardware, older hardware does not
support UEFI, a user may wish to boot via BIOS/CSM, and some systems
that support UEFI fail to boot FreeBSD via UEFI (such as an old
AMD FX-6100 that I have).
With this change amd64 memsticks remain dual-mode (booting from either
UEFI or CSM); the partitioning type is just switched from GPT to MBR.
The "vestigial swap partition" in the GPT scheme was added in r265017 to
work around some issue with loader's GPT support, so we should not need
it when using MBR.
There is some concern that future UEFI systems may not boot from MBR,
but I am not aware of any today. In any case the likely path forward
for our installers is to migrate to CD/USB combo images, and if it
becomes necessary introduce a separate memstick specifically for the
MBR BIOS/CSM case.
PR: 227954
Reviewed by: gjb, imp, tsoome
MFC after: 3 days
Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D15599
2018-05-29 15:06:13 +00:00
|
|
|
mkimg -s mbr \
|
2022-02-28 22:37:03 +00:00
|
|
|
-b ${BASEBITSDIR}/boot/mbr \
|
2018-12-20 19:39:37 +00:00
|
|
|
-p efi:=${espfilename} \
|
2022-02-28 22:37:03 +00:00
|
|
|
-p freebsd:-"mkimg -s bsd -b ${BASEBITSDIR}/boot/boot -p freebsd-ufs:=${2}.part" \
|
switch amd64 memstick installer images to MBR
A good number of BIOSes have trouble booting from GPT in non-UEFI mode.
This is commonly reported with Lenovo desktops and laptops (including
X220, X230, T430, and E31) and Dell systems. Although UEFI is the
preferred amd64 boot method on recent hardware, older hardware does not
support UEFI, a user may wish to boot via BIOS/CSM, and some systems
that support UEFI fail to boot FreeBSD via UEFI (such as an old
AMD FX-6100 that I have).
With this change amd64 memsticks remain dual-mode (booting from either
UEFI or CSM); the partitioning type is just switched from GPT to MBR.
The "vestigial swap partition" in the GPT scheme was added in r265017 to
work around some issue with loader's GPT support, so we should not need
it when using MBR.
There is some concern that future UEFI systems may not boot from MBR,
but I am not aware of any today. In any case the likely path forward
for our installers is to migrate to CD/USB combo images, and if it
becomes necessary introduce a separate memstick specifically for the
MBR BIOS/CSM case.
PR: 227954
Reviewed by: gjb, imp, tsoome
MFC after: 3 days
Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D15599
2018-05-29 15:06:13 +00:00
|
|
|
-a 2 \
|
2018-04-10 19:49:04 +00:00
|
|
|
-o ${2}
|
2018-12-20 19:39:37 +00:00
|
|
|
rm ${espfilename}
|
2014-07-02 15:23:13 +00:00
|
|
|
rm ${2}.part
|
2010-02-18 15:45:43 +00:00
|
|
|
|