1264935Sgjb#!/bin/sh
2264935Sgjb#
3264992Snwhitehorn# This script generates a "memstick image" (image that can be copied to a
4264992Snwhitehorn# USB memory stick) from a directory tree.  Note that the script does not
5264992Snwhitehorn# clean up after itself very well for error conditions on purpose so the
6264992Snwhitehorn# problem can be diagnosed (full filesystem most likely but ...).
7264935Sgjb#
8264935Sgjb# Usage: make-memstick.sh <directory tree> <image filename>
9264935Sgjb#
10264935Sgjb# $FreeBSD: stable/11/release/arm64/make-memstick.sh 332639 2018-04-17 00:46:21Z emaste $
11264935Sgjb#
12264935Sgjb
13323476Semasteset -e
14323476Semaste
15264935SgjbPATH=/bin:/usr/bin:/sbin:/usr/sbin
16264935Sgjbexport PATH
17264935Sgjb
18264935Sgjbif [ $# -ne 2 ]; then
19264935Sgjb	echo "make-memstick.sh /path/to/directory /path/to/image/file"
20264935Sgjb	exit 1
21264935Sgjbfi
22264935Sgjb
23264935Sgjbif [ ! -d ${1} ]; then
24264935Sgjb	echo "${1} must be a directory"
25264935Sgjb	exit 1
26264935Sgjbfi
27264935Sgjb
28264935Sgjbif [ -e ${2} ]; then
29264935Sgjb	echo "won't overwrite ${2}"
30264935Sgjb	exit 1
31264935Sgjbfi
32264935Sgjb
33264992Snwhitehornecho '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab
34293188Sgjbecho 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local
35324395Semastemakefs -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${1}
36264992Snwhitehornrm ${1}/etc/fstab
37293188Sgjbrm ${1}/etc/rc.conf.local
38264935Sgjb
39332639Semastemkimg -s gpt \
40332639Semaste    -p efi:=${1}/boot/boot1.efifat \
41332639Semaste    -p freebsd:=${2}.part \
42332639Semaste    -o ${2}
43264992Snwhitehornrm ${2}.part
44264935Sgjb
45