xref: /titanic_50/usr/src/cmd/svc/milestone/fs-root (revision a227b7f4f323ad89c40a86c430a5e891504a8e8b)
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*a227b7f4Shs24103# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate#
287c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
297c478bd9Sstevel@tonic-gate# All rights reserved.
307c478bd9Sstevel@tonic-gate#
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate# Make sure that the libraries essential to this stage of booting can be found.
337c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gatelibc_mount() {
367c478bd9Sstevel@tonic-gate	#
377c478bd9Sstevel@tonic-gate	# If there is an optimized libc available in /usr that fits this
387c478bd9Sstevel@tonic-gate	# processor, mount it on top of the base libc.
397c478bd9Sstevel@tonic-gate	#
407c478bd9Sstevel@tonic-gate	MOE=`/usr/bin/moe -32 '/usr/lib/libc/$HWCAP'`
417c478bd9Sstevel@tonic-gate	if [ -n "$MOE" ]; then
427c478bd9Sstevel@tonic-gate		/usr/sbin/mount | egrep -s "^/lib/libc.so.1 on "
437c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
447c478bd9Sstevel@tonic-gate			/usr/sbin/mount -O -F lofs $MOE /lib/libc.so.1
457c478bd9Sstevel@tonic-gate		fi
467c478bd9Sstevel@tonic-gate	fi
477c478bd9Sstevel@tonic-gate}
487c478bd9Sstevel@tonic-gate
491b349f08Sck142721# This mount function is sun4v only. It may be melded with the sun4u-us3
501b349f08Sck142721# version later.
511b349f08Sck142721sun4v_libc_psr_mount() {
5222defd95Sae112802	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
537c478bd9Sstevel@tonic-gate	if [ -n "$LIBC_MOE_32" ]; then
541b349f08Sck142721		/usr/sbin/mount |
5522defd95Sae112802		    egrep -s "^/platform/[^/]*/lib/libc_psr.so.1 on "
567c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
571b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
5822defd95Sae112802			    /platform/$PLAT/lib/libc_psr.so.1
597c478bd9Sstevel@tonic-gate		fi
607c478bd9Sstevel@tonic-gate	fi
617c478bd9Sstevel@tonic-gate
621b349f08Sck142721	LIBC_MOE_64=`/usr/bin/moe -64 \
6322defd95Sae112802	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
647c478bd9Sstevel@tonic-gate	if [ -n "$LIBC_MOE_64" ]; then
651b349f08Sck142721		/usr/sbin/mount |
6622defd95Sae112802		    egrep -s "^/platform/[^/]*/lib/sparcv9/libc_psr.so.1 on "
677c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
681b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
6922defd95Sae112802			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
701b349f08Sck142721		fi
711b349f08Sck142721	fi
721b349f08Sck142721}
731b349f08Sck142721
741b349f08Sck142721# This is specific to sun4u[-us3].
751b349f08Sck142721# try to intelligently handle the various ways that a hwcap library can
761b349f08Sck142721# be present for libc_psr for sun4u.
771b349f08Sck142721sun4u_libc_psr_mount() {
781b349f08Sck142721	# first look for $PLAT specific
791b349f08Sck142721	# the string $HWCAP is not an env var but part of the argument to moe
801b349f08Sck142721	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
811b349f08Sck142721	if [ -n "$LIBC_MOE_32" ]; then
821b349f08Sck142721		/usr/sbin/mount |
831b349f08Sck142721		    egrep -s "^/platform/$PLAT/lib/libc_psr.so.1 on "
841b349f08Sck142721		if [ $? -ne 0 ]; then
851b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
861b349f08Sck142721			    /platform/$PLAT/lib/libc_psr.so.1
871b349f08Sck142721		fi
881b349f08Sck142721	else
891b349f08Sck142721		# try the 'generic' one under $ARCH
901b349f08Sck142721		LIBC_MOE_32=`/usr/bin/moe -32 \
911b349f08Sck142721		    /platform/$ARCH/lib/libc_psr/'$HWCAP'`
921b349f08Sck142721		if [ -n "$LIBC_MOE_32" ]; then
931b349f08Sck142721			/usr/sbin/mount |
941b349f08Sck142721			    egrep -s "^/platform/$ARCH/lib/libc_psr.so.1 on "
951b349f08Sck142721			if [ $? -ne 0 ]; then
961b349f08Sck142721				/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
971b349f08Sck142721				    /platform/$ARCH/lib/libc_psr.so.1
981b349f08Sck142721			fi
991b349f08Sck142721		fi
1001b349f08Sck142721
1011b349f08Sck142721	fi
1021b349f08Sck142721
1031b349f08Sck142721	# now repeat for 64 bit.
1041b349f08Sck142721
1051b349f08Sck142721	LIBC_MOE_64=`/usr/bin/moe -64 \
1061b349f08Sck142721	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
1071b349f08Sck142721	if [ -n "$LIBC_MOE_64" ]; then
1081b349f08Sck142721		/usr/sbin/mount |
1091b349f08Sck142721		    egrep -s "^/platform/$PLAT/lib/sparcv9/libc_psr.so.1 on "
1101b349f08Sck142721		if [ $? -ne 0 ]; then
1111b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
1121b349f08Sck142721			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
1131b349f08Sck142721		fi
1141b349f08Sck142721	else
1151b349f08Sck142721		# now try $ARCH version
1161b349f08Sck142721		LIBC_MOE_64=`/usr/bin/moe -64 \
1171b349f08Sck142721		    /platform/$ARCH/lib/sparcv9/libc_psr/'$HWCAP'`
1181b349f08Sck142721		if [ -n "$LIBC_MOE_64" ]; then
1191b349f08Sck142721			/usr/sbin/mount |
1201b349f08Sck142721			    egrep -s \
1211b349f08Sck142721			    "^/platform/$ARCH/lib/sparcv9/libc_psr.so.1 on "
1221b349f08Sck142721			if [ $? -ne 0 ]; then
1231b349f08Sck142721				/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
1241b349f08Sck142721				    /platform/$ARCH/lib/sparcv9/libc_psr.so.1
1251b349f08Sck142721			fi
1267c478bd9Sstevel@tonic-gate		fi
1277c478bd9Sstevel@tonic-gate	fi
1287c478bd9Sstevel@tonic-gate}
1297c478bd9Sstevel@tonic-gate
130bc13c17bSae112802#
131bc13c17bSae112802# Discover architecture and find and mount optimal libc_psr
132bc13c17bSae112802#
133bc13c17bSae112802libc_psr_mount() {
134bc13c17bSae112802	PLAT=`/usr/bin/uname -i`
135bc13c17bSae112802	ARCH=`/usr/bin/uname -m`
136bc13c17bSae112802	if [ "$ARCH" = "sun4v" ]; then
137bc13c17bSae112802		sun4v_libc_psr_mount
138bc13c17bSae112802	elif [ "$ARCH" = "sun4u" ]; then
139bc13c17bSae112802		if [ -h /platform/$PLAT/lib/libc_psr.so.1 ]; then
140bc13c17bSae112802			LINKSTO=`/usr/bin/ls -l \
141bc13c17bSae112802			    /platform/$PLAT/lib/libc_psr.so.1 |
142bc13c17bSae112802			    /usr/bin/awk '{print $NF}'`
143bc13c17bSae112802			if [ "$LINKSTO" = \
144bc13c17bSae112802			    "../../sun4u-us3/lib/libc_psr.so.1" ]; then
145bc13c17bSae112802				ARCH=sun4u-us3
146bc13c17bSae112802			fi
147bc13c17bSae112802		fi
148bc13c17bSae112802		sun4u_libc_psr_mount
149bc13c17bSae112802	fi
150bc13c17bSae112802}
151bc13c17bSae112802
1526927f468Sdp. /lib/svc/share/smf_include.sh
1536927f468Sdp. /lib/svc/share/fs_include.sh
1546927f468Sdp
1557c478bd9Sstevel@tonic-gate#
1567c478bd9Sstevel@tonic-gate# Most of the operations in this script are only necessary in the global
1577c478bd9Sstevel@tonic-gate# zone but due to the way initialization scripts like this are packaged,
1587c478bd9Sstevel@tonic-gate# it needs to currently exist for all zones.
1597c478bd9Sstevel@tonic-gate#
1606927f468Sdpif smf_is_nonglobalzone; then
1617c478bd9Sstevel@tonic-gate	libc_mount
162bc13c17bSae112802	libc_psr_mount
1636927f468Sdp	exit $SMF_EXIT_OK
1647c478bd9Sstevel@tonic-gatefi
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate#
1677c478bd9Sstevel@tonic-gate# Root is already mounted (by the kernel), but still needs to be
1687c478bd9Sstevel@tonic-gate# checked, possibly remounted and entered into mnttab.  First
169*a227b7f4Shs24103# mount /usr if it is a separate file system.  If the file system
170*a227b7f4Shs24103# type is something other than zfs, mount it read-only.  This must
1717c478bd9Sstevel@tonic-gate# be done first to allow utilities such as fsck and setmnt to
1727c478bd9Sstevel@tonic-gate# reside on /usr minimizing the space required by the root file
1737c478bd9Sstevel@tonic-gate# system.
1747c478bd9Sstevel@tonic-gate#
1757c478bd9Sstevel@tonic-gatereadvfstab "/usr" < $vfstab
1767c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
1777c478bd9Sstevel@tonic-gate	if [ "$fstype" = cachefs ]; then
1787c478bd9Sstevel@tonic-gate		#
1797c478bd9Sstevel@tonic-gate		# Mount without the cache initially.  We'll enable it
1807c478bd9Sstevel@tonic-gate		# later at remount time.  This lets us avoid
1817c478bd9Sstevel@tonic-gate		# teaching the statically linked mount program about
1827c478bd9Sstevel@tonic-gate		# cachefs.  Here we determine the backfstype.
1837c478bd9Sstevel@tonic-gate		# This is not pretty, but we have no tools for parsing
1847c478bd9Sstevel@tonic-gate		# the option string until we get /usr mounted...
1857c478bd9Sstevel@tonic-gate		#
1867c478bd9Sstevel@tonic-gate		case "$mntopts" in
1877c478bd9Sstevel@tonic-gate		*backfstype=nfs*)
1887c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
1897c478bd9Sstevel@tonic-gate			;;
1907c478bd9Sstevel@tonic-gate		*backfstype=hsfs*)
1917c478bd9Sstevel@tonic-gate			cfsbacktype=hsfs
1927c478bd9Sstevel@tonic-gate			;;
1937c478bd9Sstevel@tonic-gate		*)
1947c478bd9Sstevel@tonic-gate			msg='invalid vfstab entry for /usr'
1957c478bd9Sstevel@tonic-gate			echo $msg
1967c478bd9Sstevel@tonic-gate			echo "$SMF_FMRI:" $msg >/dev/msglog
1977c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
1987c478bd9Sstevel@tonic-gate			;;
1997c478bd9Sstevel@tonic-gate		esac
2007c478bd9Sstevel@tonic-gate		mountfs - /usr $cfsbacktype ro $special ||
2017c478bd9Sstevel@tonic-gate		    exit $SMF_EXIT_ERR_FATAL
202*a227b7f4Shs24103	elif [ "$fstype" = zfs ]; then
203*a227b7f4Shs24103		mountfs - /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2047c478bd9Sstevel@tonic-gate	else
2057c478bd9Sstevel@tonic-gate		#
2067c478bd9Sstevel@tonic-gate		# Must use -o largefiles here to ensure the
2077c478bd9Sstevel@tonic-gate		# read-only mount does not fail as a result of
2087c478bd9Sstevel@tonic-gate		# having a large file present on /usr. This gives
2097c478bd9Sstevel@tonic-gate		# fsck a chance to fix up the largefiles flag
2107c478bd9Sstevel@tonic-gate		# before we remount /usr read-write.
2117c478bd9Sstevel@tonic-gate		#
2127c478bd9Sstevel@tonic-gate		if [ "x$mntopts" = x- ]; then
2137c478bd9Sstevel@tonic-gate			mntopts='ro,largefiles'
2147c478bd9Sstevel@tonic-gate		else
2157c478bd9Sstevel@tonic-gate			checkopt largefiles $mntopts
2167c478bd9Sstevel@tonic-gate			if [ "x$option" != xlargefiles ]; then
2177c478bd9Sstevel@tonic-gate				mntopts="largefiles,$mntopts"
2187c478bd9Sstevel@tonic-gate			fi
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate			checkopt ro $mntopts
2217c478bd9Sstevel@tonic-gate			if [ "x$option" != xro ]; then
2227c478bd9Sstevel@tonic-gate				mntopts="ro,$mntopts"
2237c478bd9Sstevel@tonic-gate			fi
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate			#
2267c478bd9Sstevel@tonic-gate			# Requesting logging on a read-only mount
2277c478bd9Sstevel@tonic-gate			# causes errors to be displayed, so remove
2287c478bd9Sstevel@tonic-gate			# "logging" from the list of options for now.
2297c478bd9Sstevel@tonic-gate			# The read-write mount performed later will
2307c478bd9Sstevel@tonic-gate			# specify the logging option if appropriate.
2317c478bd9Sstevel@tonic-gate			#
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate			checkopt logging $mntopts
2347c478bd9Sstevel@tonic-gate			if [ "x$option" = xlogging ]; then
2357c478bd9Sstevel@tonic-gate				mntopts="$otherops"
2367c478bd9Sstevel@tonic-gate			fi
2377c478bd9Sstevel@tonic-gate		fi
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2407c478bd9Sstevel@tonic-gate	fi
2417c478bd9Sstevel@tonic-gatefi
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate#
244*a227b7f4Shs24103# if we are booted from zfs, the /usr mount probably won't be a
245*a227b7f4Shs24103# legacy mount.  Use the standard zfs mount command instead.
246*a227b7f4Shs24103
247*a227b7f4Shs24103readmnttab "/" < /etc/mnttab
248*a227b7f4Shs24103if [ "$fstype" = zfs ]; then
249*a227b7f4Shs24103	mountp=`/sbin/zfs get -H -o value mountpoint $special/usr 2>/dev/null`
250*a227b7f4Shs24103	#
251*a227b7f4Shs24103	# if mountp = /usr, there is a non-legacy mount of /usr
252*a227b7f4Shs24103	# in the boot environment being booted.
253*a227b7f4Shs24103	#
254*a227b7f4Shs24103	if [ "x$mountp" = "x/usr" ] ; then
255*a227b7f4Shs24103		/sbin/zfs mount $special/usr
256*a227b7f4Shs24103		if [ $? != 0 ] ; then
257*a227b7f4Shs24103				msg='zfs-mount failed'
258*a227b7f4Shs24103				echo $msg
259*a227b7f4Shs24103				echo "$SMF_FMRI:" $msg >/dev/msglog
260*a227b7f4Shs24103		 	exit $SMF_EXIT_ERR_FATAL
261*a227b7f4Shs24103		fi
262*a227b7f4Shs24103	fi
263*a227b7f4Shs24103fi
264*a227b7f4Shs24103
265*a227b7f4Shs24103#
2667c478bd9Sstevel@tonic-gate# Also mount /boot now so that things like keymap.sh can access
2677c478bd9Sstevel@tonic-gate# boot properties through eeprom.  Readonly isn't required because
2687c478bd9Sstevel@tonic-gate# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
2697c478bd9Sstevel@tonic-gate# Also, we don't account for caching /boot as it must be on a local
2707c478bd9Sstevel@tonic-gate# disk.  So what's in vfstab is fine as it stands; just look to see
2717c478bd9Sstevel@tonic-gate# if it's there and avoid the mount if not.
2727c478bd9Sstevel@tonic-gate#
2737c478bd9Sstevel@tonic-gatereadvfstab "/boot" < $vfstab
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
2767c478bd9Sstevel@tonic-gate	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2777c478bd9Sstevel@tonic-gatefi
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate#
2807c478bd9Sstevel@tonic-gate# Update kernel driver.conf cache with any additional driver.conf
2817c478bd9Sstevel@tonic-gate# files found on /usr, and device permissions from /etc/minor_perm.
2827c478bd9Sstevel@tonic-gate#
2837c478bd9Sstevel@tonic-gate/usr/sbin/devfsadm -I -P
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gatelibc_mount
286bc13c17bSae112802libc_psr_mount
2877c478bd9Sstevel@tonic-gate
2886927f468Sdpexit $SMF_EXIT_OK
289