xref: /illumos-gate/usr/src/cmd/svc/milestone/fs-root (revision b1593d50e783f7d66722dde093752b74ffa95176)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
66927f468Sdp# Common Development and Distribution License (the "License").
76927f468Sdp# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23*b1593d50SJason Beloro# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate#
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate# Make sure that the libraries essential to this stage of booting can be found.
307c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gatelibc_mount() {
337c478bd9Sstevel@tonic-gate	#
347c478bd9Sstevel@tonic-gate	# If there is an optimized libc available in /usr that fits this
357c478bd9Sstevel@tonic-gate	# processor, mount it on top of the base libc.
367c478bd9Sstevel@tonic-gate	#
37*b1593d50SJason Beloro	LIBC_MOE_32=`/usr/bin/moe -32 '/usr/lib/libc/$HWCAP'`
38*b1593d50SJason Beloro	if [ -n "$LIBC_MOE_32" ]; then
397c478bd9Sstevel@tonic-gate		/usr/sbin/mount | egrep -s "^/lib/libc.so.1 on "
407c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
41*b1593d50SJason Beloro			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 /lib/libc.so.1
42*b1593d50SJason Beloro		fi
43*b1593d50SJason Beloro	fi
44*b1593d50SJason Beloro
45*b1593d50SJason Beloro	ARCH64=`isainfo | awk '{print $1}'`
46*b1593d50SJason Beloro	LIBC_MOE_64=`/usr/bin/moe -64 /usr/lib/$ARCH64/libc/'$HWCAP'`
47*b1593d50SJason Beloro	if [ -n "$LIBC_MOE_64" ]; then
48*b1593d50SJason Beloro		/usr/sbin/mount | egrep -s "^/lib/$ARCH64/libc.so.1 on "
49*b1593d50SJason Beloro		if [ $? -ne 0 ]; then
50*b1593d50SJason Beloro			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
51*b1593d50SJason Beloro				/lib/$ARCH64/libc.so.1
527c478bd9Sstevel@tonic-gate		fi
537c478bd9Sstevel@tonic-gate	fi
547c478bd9Sstevel@tonic-gate}
557c478bd9Sstevel@tonic-gate
561b349f08Sck142721# This mount function is sun4v only. It may be melded with the sun4u-us3
571b349f08Sck142721# version later.
581b349f08Sck142721sun4v_libc_psr_mount() {
5922defd95Sae112802	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
607c478bd9Sstevel@tonic-gate	if [ -n "$LIBC_MOE_32" ]; then
611b349f08Sck142721		/usr/sbin/mount |
6222defd95Sae112802		    egrep -s "^/platform/[^/]*/lib/libc_psr.so.1 on "
637c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
641b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
6522defd95Sae112802			    /platform/$PLAT/lib/libc_psr.so.1
667c478bd9Sstevel@tonic-gate		fi
677c478bd9Sstevel@tonic-gate	fi
687c478bd9Sstevel@tonic-gate
691b349f08Sck142721	LIBC_MOE_64=`/usr/bin/moe -64 \
7022defd95Sae112802	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
717c478bd9Sstevel@tonic-gate	if [ -n "$LIBC_MOE_64" ]; then
721b349f08Sck142721		/usr/sbin/mount |
7322defd95Sae112802		    egrep -s "^/platform/[^/]*/lib/sparcv9/libc_psr.so.1 on "
747c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
751b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
7622defd95Sae112802			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
771b349f08Sck142721		fi
781b349f08Sck142721	fi
791b349f08Sck142721}
801b349f08Sck142721
811b349f08Sck142721# This is specific to sun4u[-us3].
821b349f08Sck142721# try to intelligently handle the various ways that a hwcap library can
831b349f08Sck142721# be present for libc_psr for sun4u.
841b349f08Sck142721sun4u_libc_psr_mount() {
851b349f08Sck142721	# first look for $PLAT specific
861b349f08Sck142721	# the string $HWCAP is not an env var but part of the argument to moe
871b349f08Sck142721	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
881b349f08Sck142721	if [ -n "$LIBC_MOE_32" ]; then
891b349f08Sck142721		/usr/sbin/mount |
901b349f08Sck142721		    egrep -s "^/platform/$PLAT/lib/libc_psr.so.1 on "
911b349f08Sck142721		if [ $? -ne 0 ]; then
921b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
931b349f08Sck142721			    /platform/$PLAT/lib/libc_psr.so.1
941b349f08Sck142721		fi
951b349f08Sck142721	else
961b349f08Sck142721		# try the 'generic' one under $ARCH
971b349f08Sck142721		LIBC_MOE_32=`/usr/bin/moe -32 \
981b349f08Sck142721		    /platform/$ARCH/lib/libc_psr/'$HWCAP'`
991b349f08Sck142721		if [ -n "$LIBC_MOE_32" ]; then
1001b349f08Sck142721			/usr/sbin/mount |
1011b349f08Sck142721			    egrep -s "^/platform/$ARCH/lib/libc_psr.so.1 on "
1021b349f08Sck142721			if [ $? -ne 0 ]; then
1031b349f08Sck142721				/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
1041b349f08Sck142721				    /platform/$ARCH/lib/libc_psr.so.1
1051b349f08Sck142721			fi
1061b349f08Sck142721		fi
1071b349f08Sck142721
1081b349f08Sck142721	fi
1091b349f08Sck142721
1101b349f08Sck142721	# now repeat for 64 bit.
1111b349f08Sck142721
1121b349f08Sck142721	LIBC_MOE_64=`/usr/bin/moe -64 \
1131b349f08Sck142721	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
1141b349f08Sck142721	if [ -n "$LIBC_MOE_64" ]; then
1151b349f08Sck142721		/usr/sbin/mount |
1161b349f08Sck142721		    egrep -s "^/platform/$PLAT/lib/sparcv9/libc_psr.so.1 on "
1171b349f08Sck142721		if [ $? -ne 0 ]; then
1181b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
1191b349f08Sck142721			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
1201b349f08Sck142721		fi
1211b349f08Sck142721	else
1221b349f08Sck142721		# now try $ARCH version
1231b349f08Sck142721		LIBC_MOE_64=`/usr/bin/moe -64 \
1241b349f08Sck142721		    /platform/$ARCH/lib/sparcv9/libc_psr/'$HWCAP'`
1251b349f08Sck142721		if [ -n "$LIBC_MOE_64" ]; then
1261b349f08Sck142721			/usr/sbin/mount |
1271b349f08Sck142721			    egrep -s \
1281b349f08Sck142721			    "^/platform/$ARCH/lib/sparcv9/libc_psr.so.1 on "
1291b349f08Sck142721			if [ $? -ne 0 ]; then
1301b349f08Sck142721				/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
1311b349f08Sck142721				    /platform/$ARCH/lib/sparcv9/libc_psr.so.1
1321b349f08Sck142721			fi
1337c478bd9Sstevel@tonic-gate		fi
1347c478bd9Sstevel@tonic-gate	fi
1357c478bd9Sstevel@tonic-gate}
1367c478bd9Sstevel@tonic-gate
137bc13c17bSae112802#
138bc13c17bSae112802# Discover architecture and find and mount optimal libc_psr
139bc13c17bSae112802#
140bc13c17bSae112802libc_psr_mount() {
141bc13c17bSae112802	PLAT=`/usr/bin/uname -i`
142bc13c17bSae112802	ARCH=`/usr/bin/uname -m`
143bc13c17bSae112802	if [ "$ARCH" = "sun4v" ]; then
144*b1593d50SJason Beloro		# Check if we already loaded libc_hwcapX.so.1 thru libc_mount
145*b1593d50SJason Beloro		# We can get rid of this check (and the libc_psr mount),
146*b1593d50SJason Beloro		# if all the sun4v platforms start using libc_hwcap.
147*b1593d50SJason Beloro		if [ ! -n "$LIBC_MOE_32" ]; then
148bc13c17bSae112802			sun4v_libc_psr_mount
149*b1593d50SJason Beloro		fi
150bc13c17bSae112802	elif [ "$ARCH" = "sun4u" ]; then
151bc13c17bSae112802		if [ -h /platform/$PLAT/lib/libc_psr.so.1 ]; then
152bc13c17bSae112802			LINKSTO=`/usr/bin/ls -l \
153bc13c17bSae112802			    /platform/$PLAT/lib/libc_psr.so.1 |
154bc13c17bSae112802			    /usr/bin/awk '{print $NF}'`
155bc13c17bSae112802			if [ "$LINKSTO" = \
156bc13c17bSae112802			    "../../sun4u-us3/lib/libc_psr.so.1" ]; then
157bc13c17bSae112802				ARCH=sun4u-us3
158bc13c17bSae112802			fi
159bc13c17bSae112802		fi
160bc13c17bSae112802		sun4u_libc_psr_mount
161bc13c17bSae112802	fi
162bc13c17bSae112802}
163bc13c17bSae112802
1646927f468Sdp. /lib/svc/share/smf_include.sh
1656927f468Sdp. /lib/svc/share/fs_include.sh
1666927f468Sdp
1677c478bd9Sstevel@tonic-gate#
1687c478bd9Sstevel@tonic-gate# Most of the operations in this script are only necessary in the global
1697c478bd9Sstevel@tonic-gate# zone but due to the way initialization scripts like this are packaged,
1707c478bd9Sstevel@tonic-gate# it needs to currently exist for all zones.
1717c478bd9Sstevel@tonic-gate#
1726927f468Sdpif smf_is_nonglobalzone; then
1737c478bd9Sstevel@tonic-gate	libc_mount
174bc13c17bSae112802	libc_psr_mount
1756927f468Sdp	exit $SMF_EXIT_OK
1767c478bd9Sstevel@tonic-gatefi
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate#
1797c478bd9Sstevel@tonic-gate# Root is already mounted (by the kernel), but still needs to be
1807c478bd9Sstevel@tonic-gate# checked, possibly remounted and entered into mnttab.  First
181a227b7f4Shs24103# mount /usr if it is a separate file system.  If the file system
182a227b7f4Shs24103# type is something other than zfs, mount it read-only.  This must
1837c478bd9Sstevel@tonic-gate# be done first to allow utilities such as fsck and setmnt to
1847c478bd9Sstevel@tonic-gate# reside on /usr minimizing the space required by the root file
1857c478bd9Sstevel@tonic-gate# system.
1867c478bd9Sstevel@tonic-gate#
1877c478bd9Sstevel@tonic-gatereadvfstab "/usr" < $vfstab
1887c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
1897c478bd9Sstevel@tonic-gate	if [ "$fstype" = cachefs ]; then
1907c478bd9Sstevel@tonic-gate		#
1917c478bd9Sstevel@tonic-gate		# Mount without the cache initially.  We'll enable it
1927c478bd9Sstevel@tonic-gate		# later at remount time.  This lets us avoid
1937c478bd9Sstevel@tonic-gate		# teaching the statically linked mount program about
1947c478bd9Sstevel@tonic-gate		# cachefs.  Here we determine the backfstype.
1957c478bd9Sstevel@tonic-gate		# This is not pretty, but we have no tools for parsing
1967c478bd9Sstevel@tonic-gate		# the option string until we get /usr mounted...
1977c478bd9Sstevel@tonic-gate		#
1987c478bd9Sstevel@tonic-gate		case "$mntopts" in
1997c478bd9Sstevel@tonic-gate		*backfstype=nfs*)
2007c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
2017c478bd9Sstevel@tonic-gate			;;
2027c478bd9Sstevel@tonic-gate		*backfstype=hsfs*)
2037c478bd9Sstevel@tonic-gate			cfsbacktype=hsfs
2047c478bd9Sstevel@tonic-gate			;;
2057c478bd9Sstevel@tonic-gate		*)
2067c478bd9Sstevel@tonic-gate			msg='invalid vfstab entry for /usr'
2077c478bd9Sstevel@tonic-gate			echo $msg
2087c478bd9Sstevel@tonic-gate			echo "$SMF_FMRI:" $msg >/dev/msglog
2097c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
2107c478bd9Sstevel@tonic-gate			;;
2117c478bd9Sstevel@tonic-gate		esac
2127c478bd9Sstevel@tonic-gate		mountfs - /usr $cfsbacktype ro $special ||
2137c478bd9Sstevel@tonic-gate		    exit $SMF_EXIT_ERR_FATAL
214a227b7f4Shs24103	elif [ "$fstype" = zfs ]; then
215a227b7f4Shs24103		mountfs - /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2167c478bd9Sstevel@tonic-gate	else
2177c478bd9Sstevel@tonic-gate		#
2187c478bd9Sstevel@tonic-gate		# Must use -o largefiles here to ensure the
2197c478bd9Sstevel@tonic-gate		# read-only mount does not fail as a result of
2207c478bd9Sstevel@tonic-gate		# having a large file present on /usr. This gives
2217c478bd9Sstevel@tonic-gate		# fsck a chance to fix up the largefiles flag
2227c478bd9Sstevel@tonic-gate		# before we remount /usr read-write.
2237c478bd9Sstevel@tonic-gate		#
2247c478bd9Sstevel@tonic-gate		if [ "x$mntopts" = x- ]; then
2257c478bd9Sstevel@tonic-gate			mntopts='ro,largefiles'
2267c478bd9Sstevel@tonic-gate		else
2277c478bd9Sstevel@tonic-gate			checkopt largefiles $mntopts
2287c478bd9Sstevel@tonic-gate			if [ "x$option" != xlargefiles ]; then
2297c478bd9Sstevel@tonic-gate				mntopts="largefiles,$mntopts"
2307c478bd9Sstevel@tonic-gate			fi
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate			checkopt ro $mntopts
2337c478bd9Sstevel@tonic-gate			if [ "x$option" != xro ]; then
2347c478bd9Sstevel@tonic-gate				mntopts="ro,$mntopts"
2357c478bd9Sstevel@tonic-gate			fi
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate			#
2387c478bd9Sstevel@tonic-gate			# Requesting logging on a read-only mount
2397c478bd9Sstevel@tonic-gate			# causes errors to be displayed, so remove
2407c478bd9Sstevel@tonic-gate			# "logging" from the list of options for now.
2417c478bd9Sstevel@tonic-gate			# The read-write mount performed later will
2427c478bd9Sstevel@tonic-gate			# specify the logging option if appropriate.
2437c478bd9Sstevel@tonic-gate			#
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate			checkopt logging $mntopts
2467c478bd9Sstevel@tonic-gate			if [ "x$option" = xlogging ]; then
2477c478bd9Sstevel@tonic-gate				mntopts="$otherops"
2487c478bd9Sstevel@tonic-gate			fi
2497c478bd9Sstevel@tonic-gate		fi
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2527c478bd9Sstevel@tonic-gate	fi
2537c478bd9Sstevel@tonic-gatefi
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate#
256a227b7f4Shs24103# if we are booted from zfs, the /usr mount probably won't be a
257a227b7f4Shs24103# legacy mount.  Use the standard zfs mount command instead.
258a227b7f4Shs24103
259a227b7f4Shs24103readmnttab "/" < /etc/mnttab
260a227b7f4Shs24103if [ "$fstype" = zfs ]; then
261a227b7f4Shs24103	mountp=`/sbin/zfs get -H -o value mountpoint $special/usr 2>/dev/null`
262a227b7f4Shs24103	#
263a227b7f4Shs24103	# if mountp = /usr, there is a non-legacy mount of /usr
264a227b7f4Shs24103	# in the boot environment being booted.
265a227b7f4Shs24103	#
266a227b7f4Shs24103	if [ "x$mountp" = "x/usr" ] ; then
267a227b7f4Shs24103		/sbin/zfs mount $special/usr
268a227b7f4Shs24103		if [ $? != 0 ] ; then
269a227b7f4Shs24103				msg='zfs-mount failed'
270a227b7f4Shs24103				echo $msg
271a227b7f4Shs24103				echo "$SMF_FMRI:" $msg >/dev/msglog
272a227b7f4Shs24103		 	exit $SMF_EXIT_ERR_FATAL
273a227b7f4Shs24103		fi
274a227b7f4Shs24103	fi
275a227b7f4Shs24103fi
276a227b7f4Shs24103
277a227b7f4Shs24103#
2787c478bd9Sstevel@tonic-gate# Also mount /boot now so that things like keymap.sh can access
2797c478bd9Sstevel@tonic-gate# boot properties through eeprom.  Readonly isn't required because
2807c478bd9Sstevel@tonic-gate# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
2817c478bd9Sstevel@tonic-gate# Also, we don't account for caching /boot as it must be on a local
2827c478bd9Sstevel@tonic-gate# disk.  So what's in vfstab is fine as it stands; just look to see
2837c478bd9Sstevel@tonic-gate# if it's there and avoid the mount if not.
2847c478bd9Sstevel@tonic-gate#
2857c478bd9Sstevel@tonic-gatereadvfstab "/boot" < $vfstab
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
2887c478bd9Sstevel@tonic-gate	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2897c478bd9Sstevel@tonic-gatefi
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate#
2927c478bd9Sstevel@tonic-gate# Update kernel driver.conf cache with any additional driver.conf
2937c478bd9Sstevel@tonic-gate# files found on /usr, and device permissions from /etc/minor_perm.
2947c478bd9Sstevel@tonic-gate#
2957c478bd9Sstevel@tonic-gate/usr/sbin/devfsadm -I -P
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gatelibc_mount
298bc13c17bSae112802libc_psr_mount
2997c478bd9Sstevel@tonic-gate
3006927f468Sdpexit $SMF_EXIT_OK
301