1204044Skensmith#!/bin/sh
2204044Skensmith#
3204044Skensmith# This script generates a "memstick image" (image that can be copied to a
4204044Skensmith# USB memory stick) from a directory tree.  Note that the script does not
5204044Skensmith# clean up after itself very well for error conditions on purpose so the
6204044Skensmith# problem can be diagnosed (full filesystem most likely but ...).
7204044Skensmith#
8204044Skensmith# Usage: make-memstick.sh <directory tree> <image filename>
9204044Skensmith#
10204044Skensmith# $FreeBSD$
11204044Skensmith#
12204044Skensmith
13204044SkensmithPATH=/bin:/usr/bin:/sbin:/usr/sbin
14204044Skensmithexport PATH
15204044Skensmith
16204044Skensmithif [ $# -ne 2 ]; then
17265296Sgjb	echo "make-memstick.sh /path/to/directory /path/to/image/file"
18265296Sgjb	exit 1
19204044Skensmithfi
20204044Skensmith
21204044Skensmithif [ ! -d ${1} ]; then
22265296Sgjb	echo "${1} must be a directory"
23265296Sgjb	exit 1
24204044Skensmithfi
25204044Skensmith
26204044Skensmithif [ -e ${2} ]; then
27265296Sgjb	echo "won't overwrite ${2}"
28265296Sgjb	exit 1
29204044Skensmithfi
30204044Skensmith
31226170Snwhitehornecho '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab
32226170Snwhitehornmakefs -B little -o label=FreeBSD_Install ${2} ${1}
33204044Skensmithif [ $? -ne 0 ]; then
34265296Sgjb	echo "makefs failed"
35265296Sgjb	exit 1
36204044Skensmithfi
37219856Snwhitehornrm ${1}/etc/fstab
38204044Skensmith
39265296Sgjbunit=$(mdconfig -a -t vnode -f ${2})
40204044Skensmithif [ $? -ne 0 ]; then
41265296Sgjb	echo "mdconfig failed"
42265296Sgjb	exit 1
43204044Skensmithfi
44226170Snwhitehorngpart create -s BSD ${unit}
45226170Snwhitehorngpart bootcode -b ${1}/boot/boot ${unit}
46226170Snwhitehorngpart add -t freebsd-ufs ${unit}
47204044Skensmithmdconfig -d -u ${unit}
48204044Skensmith
49