make-memstick.sh revision 271633
1169695Skan#!/bin/sh
2169695Skan#
3169695Skan# This script generates a "memstick image" (image that can be copied to a
4169695Skan# USB memory stick) from a directory tree.  Note that the script does not
5169695Skan# clean up after itself very well for error conditions on purpose so the
6169695Skan# problem can be diagnosed (full filesystem most likely but ...).
7169695Skan#
8169695Skan# Usage: make-memstick.sh <directory tree> <image filename>
9169695Skan#
10169695Skan# $FreeBSD: stable/10/release/powerpc/make-memstick.sh 271633 2014-09-15 16:47:04Z emaste $
11169695Skan#
12169695Skan
13169695SkanPATH=/bin:/usr/bin:/sbin:/usr/sbin
14169695Skanexport PATH
15169695Skan
16169695SkanBLOCKSIZE=10240
17169695Skan
18169695Skanif [ $# -ne 2 ]; then
19169695Skan  echo "make-memstick.sh /path/to/directory /path/to/image/file"
20169695Skan  exit 1
21169695Skanfi
22169695Skan
23169695Skantempfile="${2}.$$"
24169695Skan
25169695Skanif [ ! -d ${1} ]; then
26169695Skan  echo "${1} must be a directory"
27169695Skan  exit 1
28169695Skanfi
29169695Skan
30169695Skanif [ -e ${2} ]; then
31169695Skan  echo "won't overwrite ${2}"
32169695Skan  exit 1
33169695Skanfi
34169695Skan
35169695Skanecho '/dev/da0s3 / ufs ro,noatime 1 1' > ${1}/etc/fstab
36169695Skanrm -f ${tempfile}
37169695Skanmakefs -B big ${tempfile} ${1}
38169695Skanif [ $? -ne 0 ]; then
39169695Skan  echo "makefs failed"
40169695Skan  exit 1
41169695Skanfi
42169695Skanrm ${1}/etc/fstab
43169695Skan
44169695Skanmkimg -s apm -p freebsd-boot:=${1}/boot/boot1.hfs -p freebsd-ufs/FreeBSD_Install:=${tempfile} -o ${2}
45169695Skan
46169695Skanrm -f ${tempfile}
47169695Skan
48169695Skan