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 ...).
8 # Usage: make-memstick.sh <directory tree> <image filename>
13 PATH=/bin:/usr/bin:/sbin:/usr/sbin
19 echo "make-memstick.sh /path/to/directory /path/to/image/file"
25 if [ ! -d ${1} ]; then
26 echo "${1} must be a directory"
31 echo "won't overwrite ${2}"
36 makefs ${tempfile} ${1}
43 # Use $BLOCKSIZE for transfers to improve efficiency. When calculating
44 # how many blocks to transfer "+ 2" is to account for truncation in the
45 # division and to provide space for the label.
48 filesize=`stat -f "%z" ${tempfile}`
49 blocks=$(($filesize / ${BLOCKSIZE} + 2))
50 dd if=/dev/zero of=${2} bs=${BLOCKSIZE} count=${blocks}
52 echo "creation of image file failed"
56 unit=`mdconfig -a -t vnode -f ${2}`
58 echo "mdconfig failed"
62 fdisk -BIq /dev/${unit}
68 bsdlabel -B -w /dev/${unit}
70 echo "bsdlabel failed"
74 dd if=${tempfile} of=/dev/${unit}a bs=$BLOCKSIZE conv=sync
76 echo "copying filesystem into image file failed"
80 mdconfig -d -u ${unit}