Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/release/i386/make-memstick.sh
34677 views
1
#!/bin/sh
2
#
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 ...).
7
#
8
# Usage: make-memstick.sh <directory tree or manifest> <image filename>
9
#
10
#
11
12
set -e
13
14
scriptdir=$(dirname $(realpath $0))
15
. ${scriptdir}/../scripts/tools.subr
16
17
if [ "$(uname -s)" = "FreeBSD" ]; then
18
PATH=/bin:/usr/bin:/sbin:/usr/sbin
19
export PATH
20
fi
21
22
if [ $# -ne 2 ]; then
23
echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file"
24
exit 1
25
fi
26
27
MAKEFSARG=${1}
28
29
if [ -f ${MAKEFSARG} ]; then
30
BASEBITSDIR=`dirname ${MAKEFSARG}`
31
METALOG=${MAKEFSARG}
32
elif [ -d ${MAKEFSARG} ]; then
33
BASEBITSDIR=${MAKEFSARG}
34
METALOG=
35
else
36
echo "${MAKEFSARG} must exist"
37
exit 1
38
fi
39
40
if [ -e ${2} ]; then
41
echo "won't overwrite ${2}"
42
exit 1
43
fi
44
45
echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${BASEBITSDIR}/etc/fstab
46
echo 'root_rw_mount="NO"' > ${BASEBITSDIR}/etc/rc.conf.local
47
if [ -n "${METALOG}" ]; then
48
metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
49
cat ${METALOG} > ${metalogfilename}
50
echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
51
echo "./etc/rc.conf.local type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
52
MAKEFSARG=${metalogfilename}
53
fi
54
${MAKEFS} -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${MAKEFSARG}
55
rm ${BASEBITSDIR}/etc/fstab
56
rm ${BASEBITSDIR}/etc/rc.conf.local
57
if [ -n "${METALOG}" ]; then
58
rm ${metalogfilename}
59
fi
60
61
${MKIMG} -s mbr \
62
-b ${BASEBITSDIR}/boot/mbr \
63
-p freebsd:-"${MKIMG} -s bsd -b ${BASEBITSDIR}/boot/boot -p freebsd-ufs:=${2}.part" \
64
-o ${2}
65
rm ${2}.part
66
67
68