xref: /titanic_41/usr/src/cmd/svc/milestone/fs-root (revision 6f45ec7b0b964c3be967c4880e8867ac1e7763a5)
1#!/sbin/sh
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 2006 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27#
28# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
29# All rights reserved.
30#
31
32# Make sure that the libraries essential to this stage of booting can be found.
33LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
34
35libc_mount() {
36	#
37	# If there is an optimized libc available in /usr that fits this
38	# processor, mount it on top of the base libc.
39	#
40	MOE=`/usr/bin/moe -32 '/usr/lib/libc/$HWCAP'`
41	if [ -n "$MOE" ]; then
42		/usr/sbin/mount | egrep -s "^/lib/libc.so.1 on "
43		if [ $? -ne 0 ]; then
44			/usr/sbin/mount -O -F lofs $MOE /lib/libc.so.1
45		fi
46	fi
47}
48
49# This mount function is sun4v only. It may be melded with the sun4u-us3
50# version later.
51sun4v_libc_psr_mount() {
52	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
53	if [ -n "$LIBC_MOE_32" ]; then
54		/usr/sbin/mount |
55		    egrep -s "^/platform/[^/]*/lib/libc_psr.so.1 on "
56		if [ $? -ne 0 ]; then
57			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
58			    /platform/$PLAT/lib/libc_psr.so.1
59		fi
60	fi
61
62	LIBC_MOE_64=`/usr/bin/moe -64 \
63	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
64	if [ -n "$LIBC_MOE_64" ]; then
65		/usr/sbin/mount |
66		    egrep -s "^/platform/[^/]*/lib/sparcv9/libc_psr.so.1 on "
67		if [ $? -ne 0 ]; then
68			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
69			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
70		fi
71	fi
72}
73
74# This is specific to sun4u[-us3].
75# try to intelligently handle the various ways that a hwcap library can
76# be present for libc_psr for sun4u.
77sun4u_libc_psr_mount() {
78	# first look for $PLAT specific
79	# the string $HWCAP is not an env var but part of the argument to moe
80	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
81	if [ -n "$LIBC_MOE_32" ]; then
82		/usr/sbin/mount |
83		    egrep -s "^/platform/$PLAT/lib/libc_psr.so.1 on "
84		if [ $? -ne 0 ]; then
85			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
86			    /platform/$PLAT/lib/libc_psr.so.1
87		fi
88	else
89		# try the 'generic' one under $ARCH
90		LIBC_MOE_32=`/usr/bin/moe -32 \
91		    /platform/$ARCH/lib/libc_psr/'$HWCAP'`
92		if [ -n "$LIBC_MOE_32" ]; then
93			/usr/sbin/mount |
94			    egrep -s "^/platform/$ARCH/lib/libc_psr.so.1 on "
95			if [ $? -ne 0 ]; then
96				/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
97				    /platform/$ARCH/lib/libc_psr.so.1
98			fi
99		fi
100
101	fi
102
103	# now repeat for 64 bit.
104
105	LIBC_MOE_64=`/usr/bin/moe -64 \
106	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
107	if [ -n "$LIBC_MOE_64" ]; then
108		/usr/sbin/mount |
109		    egrep -s "^/platform/$PLAT/lib/sparcv9/libc_psr.so.1 on "
110		if [ $? -ne 0 ]; then
111			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
112			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
113		fi
114	else
115		# now try $ARCH version
116		LIBC_MOE_64=`/usr/bin/moe -64 \
117		    /platform/$ARCH/lib/sparcv9/libc_psr/'$HWCAP'`
118		if [ -n "$LIBC_MOE_64" ]; then
119			/usr/sbin/mount |
120			    egrep -s \
121			    "^/platform/$ARCH/lib/sparcv9/libc_psr.so.1 on "
122			if [ $? -ne 0 ]; then
123				/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
124				    /platform/$ARCH/lib/sparcv9/libc_psr.so.1
125			fi
126		fi
127	fi
128}
129
130#
131# Discover architecture and find and mount optimal libc_psr
132#
133libc_psr_mount() {
134	PLAT=`/usr/bin/uname -i`
135	ARCH=`/usr/bin/uname -m`
136	if [ "$ARCH" = "sun4v" ]; then
137		sun4v_libc_psr_mount
138	elif [ "$ARCH" = "sun4u" ]; then
139		if [ -h /platform/$PLAT/lib/libc_psr.so.1 ]; then
140			LINKSTO=`/usr/bin/ls -l \
141			    /platform/$PLAT/lib/libc_psr.so.1 |
142			    /usr/bin/awk '{print $NF}'`
143			if [ "$LINKSTO" = \
144			    "../../sun4u-us3/lib/libc_psr.so.1" ]; then
145				ARCH=sun4u-us3
146			fi
147		fi
148		sun4u_libc_psr_mount
149	fi
150}
151
152. /lib/svc/share/smf_include.sh
153. /lib/svc/share/fs_include.sh
154
155#
156# Most of the operations in this script are only necessary in the global
157# zone but due to the way initialization scripts like this are packaged,
158# it needs to currently exist for all zones.
159#
160if smf_is_nonglobalzone; then
161	libc_mount
162	libc_psr_mount
163	exit $SMF_EXIT_OK
164fi
165
166#
167# Root is already mounted (by the kernel), but still needs to be
168# checked, possibly remounted and entered into mnttab. First
169# mount /usr read only if it is a separate file system. This must
170# be done first to allow utilities such as fsck and setmnt to
171# reside on /usr minimizing the space required by the root file
172# system.
173#
174readvfstab "/usr" < $vfstab
175if [ -n "$mountp" ]; then
176	if [ "$fstype" = cachefs ]; then
177		#
178		# Mount without the cache initially.  We'll enable it
179		# later at remount time.  This lets us avoid
180		# teaching the statically linked mount program about
181		# cachefs.  Here we determine the backfstype.
182		# This is not pretty, but we have no tools for parsing
183		# the option string until we get /usr mounted...
184		#
185		case "$mntopts" in
186		*backfstype=nfs*)
187			cfsbacktype=nfs
188			;;
189		*backfstype=hsfs*)
190			cfsbacktype=hsfs
191			;;
192		*)
193			msg='invalid vfstab entry for /usr'
194			echo $msg
195			echo "$SMF_FMRI:" $msg >/dev/msglog
196			cfsbacktype=nfs
197			;;
198		esac
199		mountfs - /usr $cfsbacktype ro $special ||
200		    exit $SMF_EXIT_ERR_FATAL
201	else
202		#
203		# Must use -o largefiles here to ensure the
204		# read-only mount does not fail as a result of
205		# having a large file present on /usr. This gives
206		# fsck a chance to fix up the largefiles flag
207		# before we remount /usr read-write.
208		#
209		if [ "x$mntopts" = x- ]; then
210			mntopts='ro,largefiles'
211		else
212			checkopt largefiles $mntopts
213			if [ "x$option" != xlargefiles ]; then
214				mntopts="largefiles,$mntopts"
215			fi
216
217			checkopt ro $mntopts
218			if [ "x$option" != xro ]; then
219				mntopts="ro,$mntopts"
220			fi
221
222			#
223			# Requesting logging on a read-only mount
224			# causes errors to be displayed, so remove
225			# "logging" from the list of options for now.
226			# The read-write mount performed later will
227			# specify the logging option if appropriate.
228			#
229
230			checkopt logging $mntopts
231			if [ "x$option" = xlogging ]; then
232				mntopts="$otherops"
233			fi
234		fi
235
236		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
237	fi
238fi
239
240#
241# Also mount /boot now so that things like keymap.sh can access
242# boot properties through eeprom.  Readonly isn't required because
243# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
244# Also, we don't account for caching /boot as it must be on a local
245# disk.  So what's in vfstab is fine as it stands; just look to see
246# if it's there and avoid the mount if not.
247#
248readvfstab "/boot" < $vfstab
249
250if [ -n "$mountp" ]; then
251	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
252fi
253
254#
255# Update kernel driver.conf cache with any additional driver.conf
256# files found on /usr, and device permissions from /etc/minor_perm.
257#
258/usr/sbin/devfsadm -I -P
259
260libc_mount
261libc_psr_mount
262
263exit $SMF_EXIT_OK
264