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.
40 echo "This utility is a component of the bootadm(1M) implementation"
41 echo "and it is not recommended for stand-alone use."
42 echo "Please use bootadm(1M) instead."
44 echo "Usage: ${0##*/}: [-R \<root\>] [-p \<platform\>]"
45 echo "where \<platform\> is one of: i86pc"
49 # default platform is what we're running on
52 export PATH
=/usr
/sbin
:/usr
/bin
:/sbin
53 export GZIP_CMD
=/usr
/bin
/gzip
55 EXTRACT_FILELIST
="/boot/solaris/bin/extract_boot_filelist"
65 if [ "$ALT_ROOT" != "/" ]; then
66 echo "Creating boot_archive for $ALT_ROOT"
67 EXTRACT_ARGS
="${EXTRACT_ARGS} -R ${ALT_ROOT}"
68 EXTRACT_FILELIST
="${ALT_ROOT}${EXTRACT_FILELIST}"
73 EXTRACT_ARGS
="${EXTRACT_ARGS} -p ${PLATFORM}"
81 shift `expr $OPTIND - 1`
85 echo "Creating boot_archive for $ALT_ROOT"
100 BOOT_ARCHIVE
=platform
/$PLATFORM/boot_archive
101 BOOT_ARCHIVE_64
=platform
/$PLATFORM/$ARCH64/boot_archive
107 [ -n "$rddir" ] && rm -fr "$rddir" 2> /dev
/null
108 [ -n "$new_rddir" ] && rm -fr "$new_rddir" 2>/dev
/null
113 # Estimate image size and add 10% overhead for ufs stuff.
114 # Note, we can't use du here in case we're on a filesystem, e.g. zfs,
115 # in which the disk usage is less than the sum of the file sizes.
118 # {t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
120 # below rounds up the size of a file/directory, in bytes, to the
121 # next multiple of 1024. This mimics the behavior of ufs especially
122 # with directories. This results in a total size that's slightly
123 # bigger than if du was called on a ufs directory.
124 size32
=$
(cat "$list32" |
xargs -I {} ls -lLd "{}" 2> /dev
/null |
125 nawk
'{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
126 END {print int(t * 1.10 / 1024)}')
127 (( size32
+= dirsize32
))
128 size64
=$
(cat "$list64" |
xargs -I {} ls -lLd "{}" 2> /dev
/null |
129 nawk
'{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
130 END {print int(t * 1.10 / 1024)}')
131 (( size64
+= dirsize64
))
132 (( total_size
= size32
+ size64
))
136 # The first argument can be:
138 # "both" - create an archive with both 32-bit and 64-bit binaries
139 # "32-bit" - create an archive with only 32-bit binaries
140 # "64-bit" - create an archive with only 64-bit binaries
147 # should we exclude amd64 binaries?
148 if [ "$which" = "32-bit" ]; then
149 cpiofile
="$cpiofile32"
151 elif [ "$which" = "64-bit" ]; then
152 cpiofile
="$cpiofile64"
155 cpionfile
="$cpiofile32"
159 cpio -o -H odc
< "$list" > "$cpiofile"
161 [ -x /usr
/bin
/digest
] && /usr
/bin
/digest
-a sha1
"$cpiofile" > "$archive.hash-new"
164 # Check if gzip exists in /usr/bin, so we only try to run gzip
165 # on systems that have gzip.
167 if [ -x $GZIP_CMD ] ; then
168 gzip -c "$cpiofile" > "${archive}-new"
170 cat "$cpiofile" > "${archive}-new"
173 if [ $?
-ne 0 ] ; then
174 rm -f "${archive}-new" "$achive.hash-new"
178 function create_archive
183 echo "updating $archive"
185 create_cpio
"$which" "$archive"
187 if [ ! -e "${archive}-new" ] ; then
189 # Two of these functions may be run in parallel. We
190 # need to allow the other to clean up, so we can't
191 # exit immediately. Instead, we set a flag.
193 echo "update of $archive failed"
196 mv "${archive}-new" "$archive"
197 rm -f "$archive.hash"
198 mv "$archive.hash-new" "$archive.hash" 2> /dev
/null
211 if [ ! -f "$ALT_ROOT/boot/solaris/filelist.ramdisk" ] &&
212 [ ! -f "$ALT_ROOT/etc/boot/solaris/filelist.ramdisk" ]
214 print
-u2 "Can't find filelist.ramdisk"
217 filelist
=$
($EXTRACT_FILELIST $EXTRACT_ARGS \
218 /boot
/solaris
/filelist.ramdisk \
219 /etc
/boot
/solaris
/filelist.ramdisk \
220 2>/dev
/null |
sort -u)
223 # We use /tmp/ for scratch space now. This may be changed later if there
224 # is insufficient space in /tmp/.
226 rddir
="/tmp/create_ramdisk.$$.tmp"
229 mkdir
"$rddir" || fatal_error
"Could not create temporary directory $rddir"
231 # Clean up upon exit.
234 list32
="$rddir/filelist.32"
235 list64
="$rddir/filelist.64"
237 touch $list32 $list64
240 # This loop creates the 32-bit and 64-bit lists of files. The 32-bit list
241 # is written to stdout, which is redirected at the end of the loop. The
242 # 64-bit list is appended with each write.
245 find $filelist -print 2>/dev
/null |
while read path
247 if [ $SPLIT = no
]; then
249 elif [ -d "$path" ]; then
250 size
=`ls -lLd "$path" | nawk '
251 {print ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}'`
252 if [ `basename "$path"` != "amd64" ]; then
253 (( dirsize32
+= size
))
255 (( dirsize64
+= size
))
257 case `LC_MESSAGES=C /usr/bin/file "$path" 2>/dev/null` in
259 print
"$path" >> "$list64"
267 print
"$path" >> "$list64"
272 # calculate image size
275 # check to see if there is sufficient space in tmpfs
277 tmp_free
=`df -b /tmp | tail -1 | awk '{ printf ($2) }'`
278 (( tmp_free
= tmp_free
/ 3 ))
279 if [ $SPLIT = yes ]; then
280 (( tmp_free
= tmp_free
/ 2 ))
283 if [ $total_size -gt $tmp_free ] ; then
284 # assumes we have enough scratch space on $ALT_ROOT
285 new_rddir
="/$ALT_ROOT/var/tmp/create_ramdisk.$$.tmp"
287 mkdir
"$new_rddir" || fatal_error \
288 "Could not create temporary directory $new_rddir"
290 # Save the file lists
291 mv "$list32" "$new_rddir"/
292 mv "$list64" "$new_rddir"/
293 list32
="/$new_rddir/filelist.32"
294 list64
="/$new_rddir/filelist.64"
296 # Remove the old $rddir and set the new value of rddir
302 cpiofile32
="$rddir/cpio.file.32"
303 cpiofile64
="$rddir/cpio.file.64"
305 if [ $SPLIT = yes ]; then
306 create_archive
"32-bit" "$ALT_ROOT/$BOOT_ARCHIVE" &
307 create_archive
"64-bit" "$ALT_ROOT/$BOOT_ARCHIVE_64"
310 create_archive
"both" "$ALT_ROOT/$BOOT_ARCHIVE"
312 if [ $ERROR = 1 ]; then
317 [ -n "$rddir" ] && rm -rf "$rddir"