xref: /freebsd/release/i386/make-memstick.sh (revision 8df8b2d3e51d1b816201d8a1fe8bc29fe192e562)
1#!/bin/sh
2#
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 ...).
7#
8# Usage: make-memstick.sh <directory tree> <image filename>
9#
10# $FreeBSD$
11#
12
13set -e
14
15scriptdir=$(dirname $(realpath $0))
16. ${scriptdir}/../../tools/boot/install-boot.sh
17
18PATH=/bin:/usr/bin:/sbin:/usr/sbin
19export PATH
20
21if [ $# -ne 2 ]; then
22	echo "make-memstick.sh /path/to/directory /path/to/image/file"
23	exit 1
24fi
25
26if [ ! -d ${1} ]; then
27	echo "${1} must be a directory"
28	exit 1
29fi
30
31if [ -e ${2} ]; then
32	echo "won't overwrite ${2}"
33	exit 1
34fi
35
36echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab
37echo 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local
38makefs -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${1}
39rm ${1}/etc/fstab
40rm ${1}/etc/rc.conf.local
41
42# Make an ESP in a file.
43espfilename=$(mktemp /tmp/efiboot.XXXXXX)
44make_esp_file ${espfilename} ${fat32min} ${1}/boot/loader.efi
45
46mkimg -s mbr \
47    -b ${1}/boot/mbr \
48    -p efi:=${espfilename} \
49    -p freebsd:-"mkimg -s bsd -b ${1}/boot/boot -p freebsd-ufs:=${2}.part" \
50    -o ${2}
51rm ${espfilename}
52rm ${2}.part
53
54