3 # This script generates a "memstick image" (image that can be copied to a
4 # USB memory stick) from a directory tree. Note that the script does not
5 # clean up after itself very well for error conditions on purpose so the
6 # problem can be diagnosed (full filesystem most likely but ...).
8 # Usage: make-memstick.sh <directory tree or manifest> <image filename>
15 if [ "$(uname -s)" = "FreeBSD" ]; then
16 PATH=/bin:/usr/bin:/sbin:/usr/sbin
20 scriptdir=$(dirname $(realpath $0))
21 . ${scriptdir}/../../tools/boot/install-boot.sh
24 echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file"
30 if [ -f ${MAKEFSARG} ]; then
31 BASEBITSDIR=`dirname ${MAKEFSARG}`
33 elif [ -d ${MAKEFSARG} ]; then
34 BASEBITSDIR=${MAKEFSARG}
37 echo "${MAKEFSARG} must exist"
42 echo "won't overwrite ${2}"
46 echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${BASEBITSDIR}/etc/fstab
47 echo 'root_rw_mount="NO"' > ${BASEBITSDIR}/etc/rc.conf.local
48 if [ -n "${METALOG}" ]; then
49 metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
50 cat ${METALOG} > ${metalogfilename}
51 echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
52 echo "./etc/rc.conf.local type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
53 MAKEFSARG=${metalogfilename}
55 makefs -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${MAKEFSARG}
56 rm ${BASEBITSDIR}/etc/fstab
57 rm ${BASEBITSDIR}/etc/rc.conf.local
58 if [ -n "${METALOG}" ]; then
62 # Make an ESP in a file.
63 espfilename=$(mktemp /tmp/efiboot.XXXXXX)
64 make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi
67 -p efi:=${espfilename} \
68 -p freebsd-ufs:=${2}.part \