make-memstick.sh revision 293723
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> <image filename>
9#
10# $FreeBSD: stable/10/release/amd64/make-memstick.sh 293723 2016-01-12 02:12:40Z gjb $
11#
12
13PATH=/bin:/usr/bin:/sbin:/usr/sbin
14export PATH
15
16if [ $# -ne 2 ]; then
17	echo "make-memstick.sh /path/to/directory /path/to/image/file"
18	exit 1
19fi
20
21if [ ! -d ${1} ]; then
22	echo "${1} must be a directory"
23	exit 1
24fi
25
26if [ -e ${2} ]; then
27	echo "won't overwrite ${2}"
28	exit 1
29fi
30
31echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab
32echo 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local
33makefs -B little -o label=FreeBSD_Install ${2} ${1}
34if [ $? -ne 0 ]; then
35	echo "makefs failed"
36	exit 1
37fi
38rm ${1}/etc/fstab
39rm ${1}/etc/rc.conf.local
40
41unit=$(mdconfig -a -t vnode -f ${2})
42if [ $? -ne 0 ]; then
43	echo "mdconfig failed"
44	exit 1
45fi
46gpart create -s BSD ${unit}
47gpart bootcode -b ${1}/boot/boot ${unit}
48gpart add -t freebsd-ufs ${unit}
49mdconfig -d -u ${unit}
50
51