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 2016 Toomas Soome <tsoome@me.com>
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2014 by Delphix. All rights reserved.
42 echo "This utility is a component of the bootadm(1M) implementation"
43 echo "and it is not recommended for stand-alone use."
44 echo "Please use bootadm(1M) instead."
46 echo "Usage: ${0##*/}: [-R \<root\>] [-p \<platform\>] [--nocompress]"
47 echo "where \<platform\> is one of i86pc, sun4u or sun4v"
51 # default platform is what we're running on
55 # set path, but inherit /tmp/bfubin if owned by
56 # same uid executing this process, which must be root.
58 if [ "`echo $PATH | cut -f 1 -d :`" = /tmp
/bfubin
] && \
59 [ -O /tmp
/bfubin
] ; then
60 export PATH
=/tmp
/bfubin
61 export GZIP_CMD
=/tmp
/bfubin
/gzip
63 export PATH
=/usr
/sbin
:/usr
/bin
:/sbin
64 export GZIP_CMD
=/usr
/bin
/gzip
67 EXTRACT_FILELIST
="/boot/solaris/bin/extract_boot_filelist"
77 if [ "$ALT_ROOT" != "/" ]; then
78 echo "Creating boot_archive for $ALT_ROOT"
79 EXTRACT_ARGS
="${EXTRACT_ARGS} -R ${ALT_ROOT}"
80 EXTRACT_FILELIST
="${ALT_ROOT}${EXTRACT_FILELIST}"
83 -n|
--nocompress) compress=no
87 EXTRACT_ARGS
="${EXTRACT_ARGS} -p ${PLATFORM}"
95 if [ -x /usr
/bin
/mkisofs
-o -x /tmp
/bfubin
/mkisofs
] ; then
100 # mkisofs on s8 doesn't support functionality used by GRUB boot.
101 # Use ufs format for boot archive instead.
104 if [ "$release" = "5.8" ]; then
108 shift `expr $OPTIND - 1`
110 if [ $# -eq 1 ]; then
112 echo "Creating boot_archive for $ALT_ROOT"
133 BOOT_ARCHIVE
=platform
/$PLATFORM/boot_archive
134 BOOT_ARCHIVE_64
=platform
/$PLATFORM/$ARCH64/boot_archive
136 if [ $PLATFORM = i86pc
] ; then
137 if [ ! -x "$ALT_ROOT"/boot
/solaris
/bin
/symdef
]; then
138 # no dboot implies combined archives for example
139 # live-upgrade from s9 to s10u6 is multiboot-only
140 echo "Creating single archive at $ALT_ROOT/$BOOT_ARCHIVE"
147 SPLIT
=no
# there's only 64-bit (sparcv9), so don't split
151 [ -x $GZIP_CMD ] ||
compress=no
155 umount
-f "$rdmnt32" 2>/dev
/null
156 umount
-f "$rdmnt64" 2>/dev
/null
157 lofiadm
-d "$rdfile32" 2>/dev
/null
158 lofiadm
-d "$rdfile64" 2>/dev
/null
159 [ -n "$rddir" ] && rm -fr "$rddir" 2> /dev
/null
160 [ -n "$new_rddir" ] && rm -fr "$new_rddir" 2>/dev
/null
165 # Estimate image size and add 10% overhead for ufs stuff.
166 # Note, we can't use du here in case we're on a filesystem, e.g. zfs,
167 # in which the disk usage is less than the sum of the file sizes.
170 # {t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
172 # below rounds up the size of a file/directory, in bytes, to the
173 # next multiple of 1024. This mimics the behavior of ufs especially
174 # with directories. This results in a total size that's slightly
175 # bigger than if du was called on a ufs directory.
176 size32
=$
(cat "$list32" |
xargs -I {} ls -lLd "{}" 2> /dev
/null |
177 nawk
'{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
178 END {print int(t * 1.10 / 1024)}')
179 (( size32
+= dirsize32
))
180 size64
=$
(cat "$list64" |
xargs -I {} ls -lLd "{}" 2> /dev
/null |
181 nawk
'{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
182 END {print int(t * 1.10 / 1024)}')
183 (( size64
+= dirsize64
))
184 (( total_size
= size32
+ size64
))
186 if [ $compress = yes ] ; then
187 total_size
=`echo $total_size | nawk '{print int($1 / 2)}'`
192 # Copies all desired files to a target directory. One argument should be
193 # passed: the file containing the list of files to copy. This function also
194 # depends on several variables that must be set before calling:
196 # $ALT_ROOT - the target directory
197 # $compress - whether or not the files in the archives should be compressed
198 # $rdmnt - the target directory
205 # If compress is set, the files are gzip'd and put in the correct
206 # location in the loop. Nothing is printed, so the pipe and cpio
207 # at the end is a nop.
209 # If compress is not set, the file names are printed, which causes
210 # the cpio at the end to do the copy.
214 if [ $compress = yes ]; then
216 [ -d "$rdmnt/$dir" ] || mkdir
-p "$rdmnt/$dir"
217 $GZIP_CMD -c "$path" > "$rdmnt/$path"
221 done <"$list" |
cpio -pdum "$rdmnt" 2>/dev
/null
223 if [ $ISA = sparc
] ; then
225 find $filelist -type l
-print 2>/dev
/null |\
226 cpio -pdum "$rdmnt" 2>/dev
/null
227 if [ $compress = yes ] ; then
228 # always copy unix uncompressed
229 find $filelist -name unix
-type f
-print 2>/dev
/null |\
230 cpio -pdum "$rdmnt" 2>/dev
/null
237 # The first argument can be:
239 # "both" - create an archive with both 32-bit and 64-bit binaries
240 # "32-bit" - create an archive with only 32-bit binaries
241 # "64-bit" - create an archive with only 64-bit binaries
249 # should we exclude amd64 binaries?
250 if [ "$which" = "32-bit" ]; then
254 elif [ "$which" = "64-bit" ]; then
264 NOINUSE_CHECK
=1 newfs
$lofidev < /dev
/null
2> /dev
/null
266 mount
-F mntfs mnttab
/etc
/mnttab
> /dev
/null
2>&1
267 mount
-F ufs
-o nologging
$lofidev "$rdmnt"
275 if [ $ISA = sparc
] ; then
276 rlofidev
=`echo "$lofidev" | sed -e "s/dev\/lofi/dev\/rlofi/"`
277 bb
="$ALT_ROOT/platform/$PLATFORM/lib/fs/ufs/bootblk"
278 # installboot is not available on all platforms
279 dd if=$bb of
=$rlofidev bs
=1b oseek
=1 count
=15 conv
=sync
2>&1
283 # Check if gzip exists in /usr/bin, so we only try to run gzip
284 # on systems that have gzip. Then run gzip out of the patch to
285 # pick it up from bfubin or something like that if needed.
287 # If compress is set, the individual files in the archive are
288 # compressed, and the final compression will accomplish very
289 # little. To save time, we skip the gzip in this case.
291 if [ $ISA = i386
] && [ $compress = no
] && \
292 [ -x $GZIP_CMD ] ; then
293 gzip -c "$rdfile" > "${archive}-new"
295 cat "$rdfile" > "${archive}-new"
298 if [ $?
-ne 0 ] ; then
299 rm -f "${archive}-new"
304 # The first argument can be:
306 # "both" - create an archive with both 32-bit and 64-bit binaries
307 # "32-bit" - create an archive with only 32-bit binaries
308 # "64-bit" - create an archive with only 64-bit binaries
310 function create_isofs
315 # should we exclude amd64 binaries?
316 if [ "$which" = "32-bit" ]; then
320 elif [ "$which" = "64-bit" ]; then
330 # create image directory seed with graft points
333 isocmd
="mkisofs -quiet -graft-points -dlrDJN -relaxed-filenames"
335 if [ $ISA = sparc
] ; then
336 bb
="$ALT_ROOT/platform/$PLATFORM/lib/fs/hsfs/bootblk"
337 isocmd
="$isocmd -G \"$bb\""
341 isocmd
="$isocmd \"$rdmnt\""
345 # Check if gzip exists in /usr/bin, so we only try to run gzip
346 # on systems that have gzip. Then run gzip out of the patch to
347 # pick it up from bfubin or something like that if needed.
349 # If compress is set, the individual files in the archive are
350 # compressed, and the final compression will accomplish very
351 # little. To save time, we skip the gzip in this case.
355 if [ $ISA = i386
] &&[ $compress = no
] && [ -x $GZIP_CMD ]
357 ksh
-c "$isocmd" 2> "$errlog" | \
358 gzip > "${archive}-new"
360 ksh
-c "$isocmd" 2> "$errlog" > "${archive}-new"
363 if [ $?
-ne 0 ]; then
365 rm -f "${archive}-new" 2> /dev
/null
366 rm -f "$errlog" 2> /dev
/null
371 if [ $ISA = sparc
] ; then
372 bb
="$ALT_ROOT/platform/$PLATFORM/lib/fs/hsfs/bootblk"
373 dd if="$bb" of
="${archive}-new" bs
=1b oseek
=1 count
=15 \
374 conv
=notrunc conv
=sync
>> "$errlog" 2>&1
378 if [ -s "$errlog" ] ||
[ $dd_ret -ne 0 ] ; then
379 grep Error
: "$errlog" >/dev
/null
2>&1
380 if [ $?
-eq 0 ] ||
[ $dd_ret -ne 0 ] ; then
382 rm -f "${archive}-new"
388 function create_archive
394 echo "updating $archive"
396 if [ "$format" = "ufs" ]; then
397 create_ufs
"$which" "$archive" "$lofidev"
399 create_isofs
"$which" "$archive"
402 # sanity check the archive before moving it into place
404 ARCHIVE_SIZE
=`ls -l "${archive}-new" 2> /dev/null | nawk '{ print $5 }'`
405 if [ $compress = yes ] ||
[ $ISA = sparc
] ; then
407 # 'file' will report "English text" for uncompressed
408 # boot_archives. Checking for that doesn't seem stable,
409 # so we just check that the file exists.
411 ls "${archive}-new" >/dev
/null
2>&1
414 # the file type check also establishes that the
417 LC_MESSAGES
=C
file "${archive}-new" |
grep gzip > /dev
/null
420 if [ $?
= 1 ] && [ -x $GZIP_CMD ] ||
[ "$ARCHIVE_SIZE" -lt 10000 ]
423 # Two of these functions may be run in parallel. We
424 # need to allow the other to clean up, so we can't
425 # exit immediately. Instead, we set a flag.
427 echo "update of $archive failed"
430 lockfs
-f "/$ALT_ROOT" 2>/dev
/null
431 mv "${archive}-new" "$archive"
432 rm -f "$archive.hash"
433 digest
-a sha1
"$archive" > "$archive.hash"
434 lockfs
-f "/$ALT_ROOT" 2>/dev
/null
448 if [ ! -f "$ALT_ROOT/boot/solaris/filelist.ramdisk" ] &&
449 [ ! -f "$ALT_ROOT/etc/boot/solaris/filelist.ramdisk" ]
451 print
-u2 "Can't find filelist.ramdisk"
454 filelist
=$
($EXTRACT_FILELIST $EXTRACT_ARGS \
455 /boot
/solaris
/filelist.ramdisk \
456 /etc
/boot
/solaris
/filelist.ramdisk \
457 2>/dev
/null |
sort -u)
460 # We use /tmp/ for scratch space now. This may be changed later if there
461 # is insufficient space in /tmp/.
463 rddir
="/tmp/create_ramdisk.$$.tmp"
466 mkdir
"$rddir" || fatal_error
"Could not create temporary directory $rddir"
468 # Clean up upon exit.
471 list32
="$rddir/filelist.32"
472 list64
="$rddir/filelist.64"
474 touch $list32 $list64
477 # This loop creates the 32-bit and 64-bit lists of files. The 32-bit list
478 # is written to stdout, which is redirected at the end of the loop. The
479 # 64-bit list is appended with each write.
482 find $filelist -print 2>/dev
/null |
while read path
484 if [ $SPLIT = no
]; then
486 elif [ -d "$path" ]; then
487 if [ $format = ufs
]; then
488 size
=`ls -lLd "$path" | nawk '
489 {print ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}'`
490 if [ `basename "$path"` != "amd64" ]; then
491 (( dirsize32
+= size
))
493 (( dirsize64
+= size
))
496 case `LC_MESSAGES=C /usr/bin/file -m /dev/null "$path" 2>/dev/null` in
498 print
"$path" >> "$list64"
506 print
"$path" >> "$list64"
511 if [ $format = ufs
] ; then
512 # calculate image size
515 # check to see if there is sufficient space in tmpfs
517 tmp_free
=`df -b /tmp | tail -1 | awk '{ printf ($2) }'`
518 (( tmp_free
= tmp_free
/ 3 ))
519 if [ $SPLIT = yes ]; then
520 (( tmp_free
= tmp_free
/ 2 ))
523 if [ $total_size -gt $tmp_free ] ; then
524 # assumes we have enough scratch space on $ALT_ROOT
525 new_rddir
="/$ALT_ROOT/var/tmp/create_ramdisk.$$.tmp"
527 mkdir
"$new_rddir" || fatal_error \
528 "Could not create temporary directory $new_rddir"
530 # Save the file lists
531 mv "$list32" "$new_rddir"/
532 mv "$list64" "$new_rddir"/
533 list32
="/$new_rddir/filelist.32"
534 list64
="/$new_rddir/filelist.64"
536 # Remove the old $rddir and set the new value of rddir
543 rdfile32
="$rddir/rd.file.32"
544 rdfile64
="$rddir/rd.file.64"
545 rdmnt32
="$rddir/rd.mount.32"
546 rdmnt64
="$rddir/rd.mount.64"
547 errlog32
="$rddir/rd.errlog.32"
548 errlog64
="$rddir/rd.errlog.64"
552 if [ $SPLIT = yes ]; then
554 # We can't run lofiadm commands in parallel, so we have to do
557 if [ "$format" = "ufs" ]; then
558 mkfile
${size32}k
"$rdfile32"
559 lofidev32
=`lofiadm -a "$rdfile32"`
560 mkfile
${size64}k
"$rdfile64"
561 lofidev64
=`lofiadm -a "$rdfile64"`
563 create_archive
"32-bit" "$ALT_ROOT/$BOOT_ARCHIVE" $lofidev32 &
564 create_archive
"64-bit" "$ALT_ROOT/$BOOT_ARCHIVE_64" $lofidev64
566 if [ "$format" = "ufs" ]; then
567 lofiadm
-d "$rdfile32"
568 lofiadm
-d "$rdfile64"
571 if [ "$format" = "ufs" ]; then
572 mkfile
${total_size}k
"$rdfile32"
573 lofidev32
=`lofiadm -a "$rdfile32"`
575 create_archive
"both" "$ALT_ROOT/$BOOT_ARCHIVE" $lofidev32
576 [ "$format" = "ufs" ] && lofiadm
-d "$rdfile32"
578 if [ $ERROR = 1 ]; then
584 # For the diskless case, hardlink archive to /boot to make it
585 # visible via tftp. /boot is lofs mounted under /tftpboot/<hostname>.
586 # NOTE: this script must work on both client and server.
588 grep "[ ]/[ ]*nfs[ ]" "$ALT_ROOT/etc/vfstab" > /dev
/null
590 rm -f "$ALT_ROOT/boot/boot_archive" "$ALT_ROOT/boot/amd64/boot_archive"
591 ln "$ALT_ROOT/$BOOT_ARCHIVE" "$ALT_ROOT/boot/boot_archive"
592 if [ $SPLIT = yes ]; then
593 ln "$ALT_ROOT/$BOOT_ARCHIVE_64" \
594 "$ALT_ROOT/boot/amd64/boot_archive"
597 [ -n "$rddir" ] && rm -rf "$rddir"