3 # $NetBSD: sunbootcd.sh,v 1.4 2004/09/22 21:24:07 snj Exp $
5 # Copyright (c) 2003 The NetBSD Foundation, Inc.
8 # This code is derived from software contributed to The NetBSD Foundation
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
33 : ${SUNLABEL:=sunlabel} # sunlabel(8)
34 : ${CYLSIZE:=640} # Cylinder size, in 512byte blocks
37 FORMAT
="%-8s offset %4d, size %4d, file %s\n"
43 Usage: ${PROGNAME} fsimage sun4 [sun4c [sun4m [sun3|sun4d [sun3x|sun4u]]]]
44 Combine file system partitions for Sun Microsystems, Inc. computers
45 into a CD-ROM file system image suitable for booting on the
47 NetBSD/sun3: sun3, sun3x
48 NetBSD/sparc: sun4, sun4c, sun4d, sun4m
50 The architecture arguments must be bootable file system image
51 for that architecture, or \`-' if no entry is desired.
52 \`fsimage' is typically an iso9660 file system image, although
53 any time of file system can be used as long as the first 512
54 bytes of the image are not used. \`fsimage' is modified, and
55 the additional partitions are added in order. If the same
56 filename is used more than once for different architectures,
57 it will only be copied once.
62 if [ $# -lt 2 -o $# -gt 6 ]; then
67 [ "$curfile" = "-" ] && continue
68 if [ ! -f "$curfile" ]; then
69 echo 1>&2 "${PROGNAME}: ${curfile}: No such file."
76 ISOSIZE
=$
( ls -l "${ISOIMAGE}" |
awk '{print $5}' )
77 ISOBLKS
=$
(( (${ISOSIZE} + 511) / 512 ))
78 ISOCYLS
=$
(( (${ISOBLKS} + (${CYLSIZE} - 1)) / ${CYLSIZE} ))
80 printf "${FORMAT}" "fsimage:" 0 ${ISOCYLS} "${ISOIMAGE}"
85 curpart
=$
(( ${curpart} + 1 ))
86 [ "$curfile" = "-" ] && continue
90 while [ ${tpart} -lt ${curpart} ]; do
91 tfile
=$
(eval echo \
$PART${tpart}FILE
)
92 if [ "${curfile}" = "${tfile}" ]; then
93 curoff
=$
(eval echo \
$PART${tpart}OFF
)
96 tpart
=$
(( ${tpart} + 1 ))
99 cursize
=$
( ls -l "${curfile}" |
awk '{print $5}' )
100 curblks
=$
(( (${cursize} + 511) / 512 ))
101 curcyls
=$
(( (${curblks} + (${CYLSIZE} - 1)) / ${CYLSIZE} ))
102 printf "${FORMAT}" "Image ${curpart}:" ${curoff} ${curcyls} "${curfile}"
104 eval PART
${curpart}SIZE
=${cursize} \
105 PART
${curpart}BLKS
=${curblks} \
106 PART
${curpart}CYLS
=${curcyls} \
107 PART
${curpart}OFF
=${curoff} \
108 PART
${curpart}FILE
="${curfile}"
110 if [ $curoff -eq $ENDCYL ]; then # append ${curfile}
111 echo " (appending ${curfile} to ${ISOIMAGE})"
112 dd if="${curfile}" of="${ISOIMAGE}" bs=${CYLSIZE}b \
113 seek=${ENDCYL} conv=notrunc,sync 2>/dev/null
114 ENDCYL=$(( $ENDCYL + $curcyls ))
119 printf "${FORMAT}" "Final:" 0 ${ENDCYL} "${ISOIMAGE}"
121 ${SUNLABEL} -nq "${ISOIMAGE}" << _partinfo_
127 a 0 $(( ${ISOCYLS} * ${CYLSIZE} ))
128 b ${PART1OFF:-0} $(( ${PART1CYLS:-0} * ${CYLSIZE} ))
129 c ${PART2OFF:-0} $(( ${PART2CYLS:-0} * ${CYLSIZE} ))
130 d ${PART3OFF:-0} $(( ${PART3CYLS:-0} * ${CYLSIZE} ))
131 e ${PART4OFF:-0} $(( ${PART4CYLS:-0} * ${CYLSIZE} ))
132 f ${PART5OFF:-0} $(( ${PART5CYLS:-0} * ${CYLSIZE} ))