make-memstick.sh (219584) | make-memstick.sh (219856) |
---|---|
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# | 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: head/release/i386/make-memstick.sh 219584 2011-03-13 01:38:24Z nwhitehorn $ | 10# $FreeBSD: head/release/i386/make-memstick.sh 219856 2011-03-22 01:14:53Z nwhitehorn $ |
11# 12 13PATH=/bin:/usr/bin:/sbin:/usr/sbin 14export PATH 15 16BLOCKSIZE=10240 17 18if [ $# -ne 2 ]; then --- 8 unchanged lines hidden (view full) --- 27 exit 1 28fi 29 30if [ -e ${2} ]; then 31 echo "won't overwrite ${2}" 32 exit 1 33fi 34 | 11# 12 13PATH=/bin:/usr/bin:/sbin:/usr/sbin 14export PATH 15 16BLOCKSIZE=10240 17 18if [ $# -ne 2 ]; then --- 8 unchanged lines hidden (view full) --- 27 exit 1 28fi 29 30if [ -e ${2} ]; then 31 echo "won't overwrite ${2}" 32 exit 1 33fi 34 |
35echo '/dev/gpt/FreeBSD_Install / ufs rw,noatime 1 1' > ${1}/etc/fstab |
|
35rm -f ${tempfile} | 36rm -f ${tempfile} |
36makefs ${tempfile} ${1} | 37makefs -B little ${tempfile} ${1} |
37if [ $? -ne 0 ]; then 38 echo "makefs failed" 39 exit 1 40fi | 38if [ $? -ne 0 ]; then 39 echo "makefs failed" 40 exit 1 41fi |
42rm ${1}/etc/fstab |
|
41 42# 43# Use $BLOCKSIZE for transfers to improve efficiency. When calculating 44# how many blocks to transfer "+ 2" is to account for truncation in the 45# division and to provide space for the label. 46# 47 48filesize=`stat -f "%z" ${tempfile}` | 43 44# 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. 48# 49 50filesize=`stat -f "%z" ${tempfile}` |
49blocks=$(($filesize / ${BLOCKSIZE} + 2)) | 51blocks=$(($filesize / ${BLOCKSIZE} + 256)) |
50dd if=/dev/zero of=${2} bs=${BLOCKSIZE} count=${blocks} 51if [ $? -ne 0 ]; then 52 echo "creation of image file failed" 53 exit 1 54fi 55 56unit=`mdconfig -a -t vnode -f ${2}` 57if [ $? -ne 0 ]; then 58 echo "mdconfig failed" 59 exit 1 60fi 61 | 52dd if=/dev/zero of=${2} bs=${BLOCKSIZE} count=${blocks} 53if [ $? -ne 0 ]; then 54 echo "creation of image file failed" 55 exit 1 56fi 57 58unit=`mdconfig -a -t vnode -f ${2}` 59if [ $? -ne 0 ]; then 60 echo "mdconfig failed" 61 exit 1 62fi 63 |
62fdisk -BIq /dev/${unit} 63if [ $? -ne 0 ]; then 64 echo "fdisk failed" 65 exit 1 66fi | 64gpart create -s GPT ${unit} 65gpart add -t freebsd-boot -s 64K ${unit} 66gpart bootcode -b ${1}/boot/pmbr -p ${1}/boot/gptboot -i 1 ${unit} 67gpart add -t freebsd-ufs -l FreeBSD_Install ${unit} |
67 | 68 |
68bsdlabel -B -w /dev/${unit} | 69dd if=${tempfile} of=/dev/${unit}p2 bs=$BLOCKSIZE conv=sync |
69if [ $? -ne 0 ]; then | 70if [ $? -ne 0 ]; then |
70 echo "bsdlabel failed" 71 exit 1 72fi 73 74dd if=${tempfile} of=/dev/${unit}a bs=$BLOCKSIZE conv=sync 75if [ $? -ne 0 ]; then | |
76 echo "copying filesystem into image file failed" 77 exit 1 78fi 79 80mdconfig -d -u ${unit} 81 82rm -f ${tempfile} 83 | 71 echo "copying filesystem into image file failed" 72 exit 1 73fi 74 75mdconfig -d -u ${unit} 76 77rm -f ${tempfile} 78 |