Deleted Added
full compact
make-memstick.sh (264935) make-memstick.sh (264992)
1#!/bin/sh
2#
1#!/bin/sh
2#
3# This script generates a "memstick image" for UEFI-capable systems.
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 ...).
4#
7#
5# Prerequisites:
6# - 'make release'
7# - KERNCONF *must* be VT (or vt_efifb(4) compiled into the kernel)
8#
9# Note: This only works for amd64, because i386 lacks the EFI boot bits.
10#
11# Usage: make-memstick.sh <directory tree> <image filename>
12#
8# Usage: make-memstick.sh <directory tree> <image filename>
9#
13# $FreeBSD: head/release/amd64/make-uefi-memstick.sh 264935 2014-04-25 21:11:00Z gjb $
10# $FreeBSD: head/release/amd64/make-uefi-memstick.sh 264992 2014-04-27 00:40:18Z nwhitehorn $
14#
15
16PATH=/bin:/usr/bin:/sbin:/usr/sbin
17export PATH
18
19if [ $# -ne 2 ]; then
20 echo "make-memstick.sh /path/to/directory /path/to/image/file"
21 exit 1

--- 4 unchanged lines hidden (view full) ---

26 exit 1
27fi
28
29if [ -e ${2} ]; then
30 echo "won't overwrite ${2}"
31 exit 1
32fi
33
11#
12
13PATH=/bin:/usr/bin:/sbin:/usr/sbin
14export PATH
15
16if [ $# -ne 2 ]; then
17 echo "make-memstick.sh /path/to/directory /path/to/image/file"
18 exit 1

--- 4 unchanged lines hidden (view full) ---

23 exit 1
24fi
25
26if [ -e ${2} ]; then
27 echo "won't overwrite ${2}"
28 exit 1
29fi
30
34dirsize=$(du -shLm ${1} | awk '{print $1}')
35dirsize=$(( $(( $(( ${dirsize} + 256 )) * 1024 * 1024 )) ))
36truncate -s ${dirsize} ${2}
31echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab
32makefs -B little -o label=FreeBSD_Install ${2}.part ${1}
33if [ $? -ne 0 ]; then
34 echo "makefs failed"
35 exit 1
36fi
37rm ${1}/etc/fstab
37
38
38unit=$(mdconfig -a -t vnode -f ${2})
39gpart create -s mbr /dev/${unit}
40gpart add -t '!0xEF' -s 32M /dev/${unit}
41gpart add -t freebsd /dev/${unit}
42gpart set -a active -i 2 /dev/${unit}
43gpart bootcode -b ${1}/boot/boot0 /dev/${unit}
44gpart create -s bsd -n 20 /dev/${unit}s2
45gpart add -t freebsd-ufs /dev/${unit}s2
46gpart bootcode -b ${1}/boot/boot /dev/${unit}s2
47newfs_msdos /dev/${unit}s1
48newfs -L rootfs /dev/${unit}s2a
49mkdir -p ${1}/mnt
50mount -t msdosfs /dev/${unit}s1 ${1}/mnt
51mkdir -p ${1}/mnt/efi/boot
52cp -p ${1}/boot/boot1.efi ${1}/mnt/efi/boot/BOOTx64.efi
39mkimg -s gpt -b ${1}/boot/pmbr -p freebsd-boot:=${1}/boot/gptboot -p efi:=${1}/boot/boot1.efifat -p freebsd-ufs:=${2}.part -o ${2}
40rm ${2}.part
53
41
54while ! umount ${1}/mnt; do
55 sleep 1
56done
57
58mkdir -p mnt
59mount /dev/${unit}s2a mnt
60tar -cf - -C ${1} . | tar -xf - -C mnt
61echo "/dev/ufs/rootfs / ufs ro,noatime 1 1" > mnt/etc/fstab
62
63while ! umount mnt; do
64 sleep 1
65done
66
67# Default boot selection to MBR so systems that do not support UEFI
68# do not fail to boot without human interaction.
69boot0cfg -s 2 /dev/${unit}
70
71mdconfig -d -u ${unit}
72rmdir mnt
73