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