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