create_ramdisk.ksh revision d71f719d9c7eacb7662f4fbb6430e0efec18b05c
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
# ident "%Z%%M% %I% %E% SMI"
ERROR=0
echo "This utility is a component of the bootadm(1M) implementation"
echo "and it is not recommended for stand-alone use."
echo "Please use bootadm(1M) instead."
echo ""
echo "Usage: ${0##*/}: [-R \<root\>] [-p \<platform\>] [--nocompress]"
echo "where \<platform\> is one of i86pc, sun4u or sun4v"
exit
}
# default platform is what we're running on
#
# same uid executing this process, which must be root.
#
else
fi
#
# Parse options
#
while [ "$1" != "" ]
do
case $1 in
-R) shift
ALT_ROOT="$1"
if [ "$ALT_ROOT" != "/" ]; then
echo "Creating boot_archive for $ALT_ROOT"
EXTRACT_ARGS="${EXTRACT_ARGS} -R ${ALT_ROOT}"
EXTRACT_FILELIST="${ALT_ROOT}${EXTRACT_FILELIST}"
fi
;;
;;
-p) shift
PLATFORM="$1"
EXTRACT_ARGS="${EXTRACT_ARGS} -p ${PLATFORM}"
;;
*) usage
;;
esac
shift
done
fi
#
# mkisofs on s8 doesn't support functionality used by GRUB boot.
# Use ufs format for boot archive instead.
#
if [ "$release" = "5.8" ]; then
fi
if [ $# -eq 1 ]; then
ALT_ROOT="$1"
echo "Creating boot_archive for $ALT_ROOT"
fi
;;
;;
;;
;;
*) usage
;;
esac
# no dboot implies combined archives for example
# live-upgrade from s9 to s10u6 is multiboot-only
echo "Creating single archive at $ALT_ROOT/$BOOT_ARCHIVE"
else
fi
else # must be sparc
fi
function cleanup
{
}
function getsize
{
# Estimate image size and add 10% overhead for ufs stuff.
# Note, we can't use du here in case we're on a filesystem, e.g. zfs,
# in which the disk usage is less than the sum of the file sizes.
# The nawk code
#
# {t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
#
# next multiple of 1024. This mimics the behavior of ufs especially
# with directories. This results in a total size that's slightly
# bigger than if du was called on a ufs directory.
nawk '{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
END {print int(t * 1.10 / 1024)}')
nawk '{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
END {print int(t * 1.10 / 1024)}')
fi
}
#
# Copies all desired files to a target directory. One argument should be
# passed: the file containing the list of files to copy. This function also
# depends on several variables that must be set before calling:
#
# $ALT_ROOT - the target directory
# $compress - whether or not the files in the archives should be compressed
# $rdmnt - the target directory
#
function copy_files
{
list="$1"
#
# If compress is set, the files are gzip'd and put in the correct
# location in the loop. Nothing is printed, so the pipe and cpio
# at the end is a nop.
#
# If compress is not set, the file names are printed, which causes
# the cpio at the end to do the copy.
#
while read path
do
dir="${path%/*}"
else
print "$path"
fi
# copy links
# always copy unix uncompressed
fi
fi
}
#
# The first argument can be:
#
# "both" - create an archive with both 32-bit and 64-bit binaries
# "32-bit" - create an archive with only 32-bit binaries
# "64-bit" - create an archive with only 64-bit binaries
#
function create_ufs
{
which=$1
archive=$2
lofidev=$3
# should we exclude amd64 binaries?
else
fi
# do the actual copy
# installboot is not available on all platforms
fi
#
# on systems that have gzip. Then run gzip out of the patch to
# pick it up from bfubin or something like that if needed.
#
# If compress is set, the individual files in the archive are
# compressed, and the final compression will accomplish very
# little. To save time, we skip the gzip in this case.
#
[ -x $GZIP_CMD ] ; then
else
fi
}
#
# The first argument can be:
#
# "both" - create an archive with both 32-bit and 64-bit binaries
# "32-bit" - create an archive with only 32-bit binaries
# "64-bit" - create an archive with only 64-bit binaries
#
function create_isofs
{
which=$1
archive=$2
# should we exclude amd64 binaries?
else
fi
# create image directory seed with graft points
isocmd="mkisofs -quiet -graft-points -dlrDJN -relaxed-filenames"
fi
#
# on systems that have gzip. Then run gzip out of the patch to
# pick it up from bfubin or something like that if needed.
#
# If compress is set, the individual files in the archive are
# compressed, and the final compression will accomplish very
# little. To save time, we skip the gzip in this case.
#
then
gzip > "${archive}-new"
else
fi
dd_ret=0
dd_ret=$?
fi
rm -f "${archive}-new"
fi
fi
}
function create_archive
{
which=$1
archive=$2
lofidev=$3
echo "updating $archive"
create_ufs "$which" "$archive" "$lofidev"
else
fi
# sanity check the archive before moving it into place
#
#
# 'file' will report "English text" for uncompressed
# boot_archives. Checking for that doesn't seem stable,
# so we just check that the file exists.
#
else
#
# the file type check also establishes that the
# file exists at all
#
fi
if [ $? = 1 ] && [ -x $GZIP_CMD ] || [ $ARCHIVE_SIZE -lt 5000 ]
then
#
# Two of these functions may be run in parallel. We
# need to allow the other to clean up, so we can't
# exit immediately. Instead, we set a flag.
#
echo "update of $archive failed"
ERROR=1
else
fi
}
function fatal_error
{
print -u2 $*
exit 1
}
#
# get filelist
#
if [ ! -f "$ALT_ROOT/boot/solaris/filelist.ramdisk" ] &&
[ ! -f "$ALT_ROOT/etc/boot/solaris/filelist.ramdisk" ]
then
print -u2 "Can't find filelist.ramdisk"
exit 1
fi
#
# We use /tmp/ for scratch space now. This may be changed later if there
# is insufficient space in /tmp/.
#
rddir="/tmp/create_ramdisk.$$.tmp"
# Clean up upon exit.
trap 'cleanup' EXIT
#
# This loop creates the 32-bit and 64-bit lists of files. The 32-bit list
# is written to stdout, which is redirected at the end of the loop. The
# 64-bit list is appended with each write.
#
cd "/$ALT_ROOT"
do
print "$path"
elif [ -d "$path" ]; then
{print ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}'`
fi
fi
else
;;
print "$path"
;;
*)
# put in both lists
print "$path"
esac
fi
done >"$list32"
# calculate image size
# check to see if there is sufficient space in tmpfs
#
# assumes we have enough scratch space on $ALT_ROOT
"Could not create temporary directory $new_rddir"
# Save the file lists
mv "$list32" "$new_rddir"/
mv "$list64" "$new_rddir"/
list32="/$new_rddir/filelist.32"
list64="/$new_rddir/filelist.64"
# Remove the old $rddir and set the new value of rddir
fi
fi
lofidev32=""
lofidev64=""
#
# We can't run lofiadm commands in parallel, so we have to do
# them here.
#
if [ "$format" = "ufs" ]; then
fi
wait
if [ "$format" = "ufs" ]; then
fi
else
if [ "$format" = "ufs" ]; then
fi
fi
if [ $ERROR = 1 ]; then
exit 1
fi
#
# For the diskless case, hardlink archive to /boot to make it
# visible via tftp. /boot is lofs mounted under /tftpboot/<hostname>.
# NOTE: this script must work on both client and server.
#
if [ $? = 0 ]; then
fi
fi