1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# s10 boot script.
27#
28# The arguments to this script are the zone name and the zonepath.
29#
30
31. /usr/lib/brand/solaris10/common.ksh
32
33ZONENAME=$1
34ZONEPATH=$2
35ZONEROOT=$ZONEPATH/root
36
37arch=`uname -p`
38if [ "$arch" = "i386" ]; then
39	ARCH32=i86
40        ARCH64=amd64
41elif [ "$arch" = "sparc" ]; then
42	# 32-bit SPARC not supported!
43	ARCH32=
44        ARCH64=sparcv9
45else
46        echo "Unsupported architecture: $arch"
47        exit 2
48fi
49
50#
51# Run the s10_support boot hook.
52#
53/usr/lib/brand/solaris10/s10_support boot $ZONENAME
54if (( $? != 0 )) ; then
55        exit 1
56fi
57
58BRANDDIR=/.SUNWnative/usr/lib/brand/solaris10;
59FILEDIR=$BRANDDIR/files;
60EXIT_CODE=1
61
62#
63# Replace the specified file in the booting zone with a wrapper script that
64# invokes s10_isaexec_wrapper.  This is a convenience function that reduces
65# clutter and code duplication.
66#
67# Parameters:
68#	$1	The full path of the file to replace (e.g., /sbin/ifconfig)
69#	$2	The access mode of the replacement file in hex (e.g., 0555)
70#	$3	The name of the replacement file's owner (e.g., root:bin)
71#
72# NOTE: The checks performed in the 'if' statement below are not generic: they
73# depend on the success of the zone filesystem structure validation performed
74# above to ensure that intermediate directories exist and aren't symlinks.
75#
76replace_with_native() {
77	path_dname=$ZONEROOT/`dirname $1`
78	if [ ! -h $path_dname -a -d $path_dname ]; then
79		safe_replace $ZONEROOT/$1 $BRANDDIR/s10_isaexec_wrapper $2 $3 \
80		    remove
81	fi
82}
83
84#
85# Before we boot we validate and fix, if necessary, the required files within
86# the zone.  These modifications can be lost if a patch is applied within the
87# zone, so we validate and fix the zone every time it boots.
88#
89
90#
91# BINARY REPLACEMENT
92#
93# This section of the boot script is responsible for replacing Solaris 10
94# binaries within the booting zone with Nevada binaries.  This is a two-step
95# process: First, the directory structure of the zone is validated to ensure
96# that binary replacement will proceed safely.  Second, Solaris 10 binaries
97# are replaced with Nevada binaries.
98#
99# Here's an example.  Suppose that you want to replace /usr/bin/zcat with the
100# Nevada /usr/bin/zcat binary.  Then you should do the following:
101#
102#	1.  Go to the section below labeled "STEP ONE" and add the following
103#	    two lines:
104#
105#		safe_dir /usr
106#		safe_dir /usr/bin
107#
108#	    These lines ensure that both /usr and /usr/bin are directories
109#	    within the booting zone that can be safely accessed by the global
110#	    zone.
111#	2.  Go to the section below labeled "STEP TWO" and add the following
112#	    line:
113#
114#		replace_with_native /usr/bin/zcat 0555 root:bin
115#
116# Details about the binary replacement procedure can be found in the Solaris 10
117# Containers Developer Guide.
118#
119
120#
121# STEP ONE
122#
123# Validate that the zone filesystem looks like we expect it to.
124#
125safe_dir /usr
126safe_dir /usr/lib
127safe_dir /usr/bin
128safe_dir /usr/sbin
129safe_dir /sbin
130
131#
132# STEP TWO
133#
134# Replace Solaris 10 binaries with Nevada binaries.
135#
136
137#
138# Replace various network-related programs with native wrappers.
139#
140replace_with_native /sbin/ifconfig 0555 root:bin
141
142#
143# Replace automount and automountd with native wrappers.
144#
145if [ ! -h $ZONEROOT/usr/lib/fs/autofs -a -d $ZONEROOT/usr/lib/fs/autofs ]; then
146	safe_replace $ZONEROOT/usr/lib/fs/autofs/automount \
147	    $BRANDDIR/s10_automount 0555 root:bin remove
148fi
149if [ ! -h $ZONEROOT/usr/lib/autofs -a -d $ZONEROOT/usr/lib/autofs ]; then
150	safe_replace $ZONEROOT/usr/lib/autofs/automountd \
151	    $BRANDDIR/s10_automountd 0555 root:bin remove
152fi
153
154#
155# END OF STEP TWO
156#
157
158#
159# Replace add_drv and rem_drv with /usr/bin/true so that pkgs/patches which
160# install or remove drivers will work.  NOTE: add_drv and rem_drv are hard
161# linked to isaexec so we want to remove the current executable and
162# then copy true so that we don't clobber isaexec.
163#
164filename=$ZONEROOT/usr/sbin/add_drv
165[ ! -f $filename.pre_p2v ] && safe_backup $filename $filename.pre_p2v
166rm -f $filename
167safe_copy $ZONEROOT/usr/bin/true $filename
168
169filename=$ZONEROOT/usr/sbin/rem_drv
170[ ! -f $filename.pre_p2v ] && safe_backup $filename $filename.pre_p2v
171rm -f $filename
172safe_copy $ZONEROOT/usr/bin/true $filename
173
174exit 0
175