make-memstick.sh revision 265171
1208600Srdivacky#!/bin/sh
2198092Srdivacky#
3198092Srdivacky# This script generates a "memstick image" (image that can be copied to a
4198092Srdivacky# USB memory stick) from a directory tree.  Note that the script does not
5198092Srdivacky# clean up after itself very well for error conditions on purpose so the
6198092Srdivacky# problem can be diagnosed (full filesystem most likely but ...).
7198092Srdivacky#
8198092Srdivacky# Usage: make-memstick.sh <directory tree> <image filename>
9198092Srdivacky#
10249423Sdim# $FreeBSD: head/release/powerpc/make-memstick.sh 265171 2014-05-01 03:24:41Z nwhitehorn $
11239462Sdim#
12198092Srdivacky
13218893SdimPATH=/bin:/usr/bin:/sbin:/usr/sbin
14198092Srdivackyexport PATH
15198092Srdivacky
16198092SrdivackyBLOCKSIZE=10240
17198092Srdivacky
18198092Srdivackyif [ $# -ne 2 ]; then
19218893Sdim  echo "make-memstick.sh /path/to/directory /path/to/image/file"
20249423Sdim  exit 1
21249423Sdimfi
22207619Srdivacky
23207619Srdivackytempfile="${2}.$$"
24198092Srdivacky
25198092Srdivackyif [ ! -d ${1} ]; then
26198092Srdivacky  echo "${1} must be a directory"
27208600Srdivacky  exit 1
28198092Srdivackyfi
29210299Sed
30210299Sedif [ -e ${2} ]; then
31210299Sed  echo "won't overwrite ${2}"
32210299Sed  exit 1
33210299Sedfi
34210299Sed
35210299Sedecho '/dev/da0s3 / ufs ro,noatime 1 1' > ${1}/etc/fstab
36210299Sedrm -f ${tempfile}
37210299Sedmakefs -B big ${tempfile} ${1}
38210299Sedif [ $? -ne 0 ]; then
39210299Sed  echo "makefs failed"
40210299Sed  exit 1
41210299Sedfi
42210299Sedrm ${1}/etc/fstab
43210299Sed
44210299Sedmkimg -s apm -p freebsd-boot:=${1}/boot/boot1.hfs -p freebsd-ufs/FreeBSD_Install:=${tempfile} -o ${2}
45210299Sed
46210299Sedrm -f ${tempfile}
47210299Sed
48226633Sdim