]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/i386/make-memstick.sh
zfs: merge openzfs/zfs@feff9dfed
[FreeBSD/FreeBSD.git] / release / i386 / make-memstick.sh
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 # $FreeBSD$
11 #
12
13 set -e
14
15 if [ "$(uname -s)" = "FreeBSD" ]; then
16         PATH=/bin:/usr/bin:/sbin:/usr/sbin
17         export PATH
18 fi
19
20 if [ $# -ne 2 ]; then
21         echo "make-memstick.sh /path/to/directory/or/manifest /path/to/image/file"
22         exit 1
23 fi
24
25 MAKEFSARG=${1}
26
27 if [ -f ${MAKEFSARG} ]; then
28         BASEBITSDIR=`dirname ${MAKEFSARG}`
29         METALOG=${MAKEFSARG}
30 elif [ -d ${MAKEFSARG} ]; then
31         BASEBITSDIR=${MAKEFSARG}
32         METALOG=
33 else
34         echo "${MAKEFSARG} must exist"
35         exit 1
36 fi
37
38 if [ -e ${2} ]; then
39         echo "won't overwrite ${2}"
40         exit 1
41 fi
42
43 echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${BASEBITSDIR}/etc/fstab
44 echo 'root_rw_mount="NO"' > ${BASEBITSDIR}/etc/rc.conf.local
45 if [ -n "${METALOG}" ]; then
46         metalogfilename=$(mktemp /tmp/metalog.XXXXXX)
47         cat ${METALOG} > ${metalogfilename}
48         echo "./etc/fstab type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
49         echo "./etc/rc.conf.local type=file uname=root gname=wheel mode=0644" >> ${metalogfilename}
50         MAKEFSARG=${metalogfilename}
51 fi
52 makefs -D -N ${BASEBITSDIR}/etc -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${MAKEFSARG}
53 rm ${BASEBITSDIR}/etc/fstab
54 rm ${BASEBITSDIR}/etc/rc.conf.local
55 if [ -n "${METALOG}" ]; then
56         rm ${metalogfilename}
57 fi
58
59 mkimg -s mbr \
60     -b ${BASEBITSDIR}/boot/mbr \
61     -p freebsd:-"mkimg -s bsd -b ${BASEBITSDIR}/boot/boot -p freebsd-ufs:=${2}.part" \
62     -o ${2}
63 rm ${2}.part
64