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}"
35 echo '/dev/da0s3 / ufs ro,noatime 1 1' > ${1}/etc/fstab
37 makefs -B big ${tempfile} ${1}
45 # Use $BLOCKSIZE for transfers to improve efficiency. When calculating
46 # how many blocks to transfer "+ 2" is to account for truncation in the
47 # division and to provide space for the label.
50 filesize=`stat -f "%z" ${tempfile}`
51 blocks=$(($filesize / ${BLOCKSIZE} + 1728))
52 dd if=/dev/zero of=${2} bs=${BLOCKSIZE} count=${blocks}
54 echo "creation of image file failed"
58 unit=`mdconfig -a -t vnode -f ${2}`
60 echo "mdconfig failed"
64 gpart create -s APM ${unit}
65 gpart add -t freebsd-boot -s 800K ${unit}
66 gpart bootcode -p ${1}/boot/boot1.hfs -i 1 ${unit}
67 gpart add -t freebsd-ufs -l FreeBSD_Install ${unit}
69 dd if=${tempfile} of=/dev/${unit}s3 bs=$BLOCKSIZE conv=sync
71 echo "copying filesystem into image file failed"
75 mdconfig -d -u ${unit}