5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # Copyright 2012 Nexenta Systems, Inc. All rights reserved.
28 # utility to pack and unpack a boot/root archive
29 # both ufs and hsfs (iso9660) format archives are unpacked
30 # only ufs archives are generated
32 # usage: pack <archive> <root>
33 # unpack <archive> <root>
35 # Where <root> is the directory to unpack to and will be cleaned out
41 printf "usage: root_archive pack <archive> <root>\n"
42 printf " root_archive unpack <archive> <root>\n"
49 umount
$MNT 2> /dev
/null
53 lofiadm
-d "$TMR" 2>/dev
/null
54 if [ "$REALTHING" != true
] ; then
65 find .
-print |
cpio -pdum "$UNPACKED_ROOT" 2> /dev
/null
67 # increase the chances the unmount will succeed
74 if [ ! -f "$MR" ] ; then
75 printf "$MR: not found\n"
79 if [ `uname -i` = i86pc
] ; then
82 REALTHING
=true
; export REALTHING
86 LOFIDEV
=`/usr/sbin/lofiadm -a $TMR`
88 echo lofi plumb failed
94 FSTYP
=`fstyp $LOFIDEV`
96 if [ "$FSTYP" = ufs
] ; then
97 /usr
/sbin
/mount
-o ro
,nologging
$LOFIDEV $MNT
99 elif [ "$FSTYP" = hsfs
] ; then
100 /usr
/sbin
/mount
-F hsfs
-o ro
$LOFIDEV $MNT
103 printf "invalid root archive\n"
108 lofiadm
-d $TMR ; LOFIDEV
=
109 if [ "$REALTHING" != true
] ; then
123 for file in $filelist ; do
125 file=`echo $file | sed s#^./##`
127 # copy all files over to preserve hard links
129 echo $file |
cpio -pdum $DST 2> /dev
/null
131 if [ -f $file ] && [ -s $file ] && [ ! -h $file ] ; then
132 fiocompress
-mc $file $DST/$file &
137 wait `pgrep fiocompress`
139 # now re-copy a couple of uncompressed files
141 if [ -d "$SRC/platform/i86pc" ] ; then
142 find `cat boot/solaris/filelist.ramdisk` -type file \
143 -print 2> /dev
/null
> /tmp
/flist$$
144 find usr
/kernel
-type file -print 2> /dev
/null \
146 # some of the files are replaced with links into
147 # tmp/root on the miniroot, so find the backing files
148 # from there as well and add them to the list ti
149 # be copied uncompressed
152 find `cat ../../boot/solaris/filelist.ramdisk` \
153 -type file -print 2> /dev
/null | \
154 sed 's#^#tmp/root/#' >> /tmp
/flist$$
156 flist
=`cat /tmp/flist$$`
161 for file in $flist ; do
162 echo $file |
cpio -pdum $DST 2> /dev
/null
165 find kernel platform
-name unix | \
166 cpio -pdum $DST 2> /dev
/null
167 find kernel platform
-name genunix |
cpio -pdum $DST \
169 find kernel platform
-name platmod |
cpio -pdum $DST \
171 find `find kernel platform -name cpu` | \
172 cpio -pdum $DST 2> /dev
/null
173 find `find kernel platform -name kmdb\*` | \
174 cpio -pdum $DST 2> /dev
/null
175 find kernel
/misc
/sparcv
9/ctf kernel
/fs
/sparcv
9/dcfs \
176 etc
/system etc
/name_to_major etc
/path_to_inst \
177 etc
/name_to_sysnum etc
/driver_aliases \
178 etc
/driver_classes etc
/minor_perm | \
179 cpio -pdum $DST 2> /dev
/null
186 grep -v "set root_is_ramdisk=" "$UNPACKED_ROOT"/etc
/system | \
187 grep -v "set ramdisk_size=" > /tmp
/system.$$
188 cat /tmp
/system.$$
> "$UNPACKED_ROOT"/etc
/system
191 echo set root_is_ramdisk
=1 >> "$UNPACKED_ROOT"/etc
/system
192 echo set ramdisk_size
=$1 >> "$UNPACKED_ROOT"/etc
/system
198 [ -d "$UNPACKED_ROOT" ] || usage
200 # always compress if fiocompress exists
202 if [ -x /usr
/sbin
/fiocompress
] ; then
206 # Estimate image size and add %10 overhead for ufs stuff.
207 # Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem,
208 # e.g. zfs, in which the disk usage is less than the sum of the file
209 # sizes. The nawk code
211 # {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
213 # below rounds up the size of a file/directory, in bytes, to the
214 # next multiple of 1024. This mimics the behavior of ufs especially
215 # with directories. This results in a total size that's slightly
216 # bigger than if du was called on a ufs directory.
218 # if the operation in turn is compressing the files the amount
219 # of typical shrinkage is used to come up with a useful archive
221 size
=$
(find "$UNPACKED_ROOT" -ls | nawk
'
222 {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
223 END {print int(t * 1.10 / 1024)}')
224 if [ "$COMPRESS" = true
] ; then
225 size
=`echo $size | nawk '{s = $1} END {print int(s * 0.6)}'`
228 /usr
/sbin
/mkfile
${size}k
"$TMR"
230 LOFIDEV
=`/usr/sbin/lofiadm -a "$TMR"`
231 if [ $?
!= 0 ] ; then
232 echo lofi plumb failed
236 RLOFIDEV
=`echo $LOFIDEV | sed s/lofi/rlofi/`
237 newfs
$RLOFIDEV < /dev
/null
2> /dev
/null
239 mount
-o nologging
$LOFIDEV $MNT
240 rmdir $MNT/lost
+found
242 if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
243 root_is_ramdisk
$size
248 if [ "$COMPRESS" = true
] ; then
251 find .
-print |
cpio -pdum $MNT 2> /dev
/null
258 if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
259 "$UNPACKED_ROOT/usr/sbin/installboot" \
260 "$UNPACKED_ROOT/platform/sun4u/lib/fs/ufs/bootblk" \
269 if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
281 find "$UNPACKED_ROOT" -name amd64
-type directory |
xargs rm -rf
291 PATH
=/usr
/sbin
:/usr
/bin
:/opt
/sfw
/bin
; export PATH
293 while getopts s
:6c opt
; do
295 s
) EXTRA_SPACE
="$OPTARG"
305 shift `expr $OPTIND - 1`
317 [ "$UNPACKED_ROOT" != "/" ] || usage
319 if [ "`dirname $MR`" = .
] ; then
322 if [ "`dirname $UNPACKED_ROOT`" = .
] ; then
323 UNPACKED_ROOT
="$BASE/$UNPACKED_ROOT"
328 # always unpack into a fresh root
331 rm -rf "$UNPACKED_ROOT"
332 mkdir
-p "$UNPACKED_ROOT"
335 [ -d "$UNPACKED_ROOT" ] || usage