make-memstick.sh revision 293188
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
6264922Sgjb# problem can be diagnosed (full filesystem most likely but ...).
7204044Skensmith#
8204044Skensmith# Usage: make-memstick.sh <directory tree> <image filename>
9204044Skensmith#
10204044Skensmith# $FreeBSD: head/release/i386/make-memstick.sh 293188 2016-01-05 03:20:45Z gjb $
11204044Skensmith#
12204044Skensmith
13204044SkensmithPATH=/bin:/usr/bin:/sbin:/usr/sbin
14204044Skensmithexport PATH
15204044Skensmith
16204044Skensmithif [ $# -ne 2 ]; then
17264933Sgjb	echo "make-memstick.sh /path/to/directory /path/to/image/file"
18264933Sgjb	exit 1
19204044Skensmithfi
20204044Skensmith
21204044Skensmithif [ ! -d ${1} ]; then
22264933Sgjb	echo "${1} must be a directory"
23264933Sgjb	exit 1
24204044Skensmithfi
25204044Skensmith
26204044Skensmithif [ -e ${2} ]; then
27264933Sgjb	echo "won't overwrite ${2}"
28264933Sgjb	exit 1
29204044Skensmithfi
30204044Skensmith
31264922Sgjbecho '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab
32293188Sgjbecho 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local
33283307Sgjbmakefs -B little -o label=FreeBSD_Install ${2}.part ${1}
34204044Skensmithif [ $? -ne 0 ]; then
35264933Sgjb	echo "makefs failed"
36264933Sgjb	exit 1
37204044Skensmithfi
38219856Snwhitehornrm ${1}/etc/fstab
39293188Sgjbrm ${1}/etc/rc.conf.local
40204044Skensmith
41283307Sgjbmkimg -s gpt -b ${1}/boot/pmbr -p freebsd-boot:=${1}/boot/gptboot -p freebsd-ufs:=${2}.part -p freebsd-swap::1M -o ${2}
42283307Sgjbrm ${2}.part
43204044Skensmith
44