xref: /titanic_53/usr/src/cmd/svc/milestone/fs-root (revision 22defd952063f38887d1d2f9ddb11d93c91f00f5)
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
67c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
77c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
87c478bd9Sstevel@tonic-gate# with the License.
97c478bd9Sstevel@tonic-gate#
107c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
117c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
127c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
137c478bd9Sstevel@tonic-gate# and limitations under the License.
147c478bd9Sstevel@tonic-gate#
157c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
167c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
177c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
187c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
197c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate# CDDL HEADER END
227c478bd9Sstevel@tonic-gate#
237c478bd9Sstevel@tonic-gate#
24*22defd95Sae112802# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
307c478bd9Sstevel@tonic-gate# All rights reserved.
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate# Make sure that the libraries essential to this stage of booting can be found.
347c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gatelibc_mount() {
377c478bd9Sstevel@tonic-gate	#
387c478bd9Sstevel@tonic-gate	# If there is an optimized libc available in /usr that fits this
397c478bd9Sstevel@tonic-gate	# processor, mount it on top of the base libc.
407c478bd9Sstevel@tonic-gate	#
417c478bd9Sstevel@tonic-gate	MOE=`/usr/bin/moe -32 '/usr/lib/libc/$HWCAP'`
427c478bd9Sstevel@tonic-gate	if [ -n "$MOE" ]; then
437c478bd9Sstevel@tonic-gate		/usr/sbin/mount | egrep -s "^/lib/libc.so.1 on "
447c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
457c478bd9Sstevel@tonic-gate			/usr/sbin/mount -O -F lofs $MOE /lib/libc.so.1
467c478bd9Sstevel@tonic-gate		fi
477c478bd9Sstevel@tonic-gate	fi
487c478bd9Sstevel@tonic-gate}
497c478bd9Sstevel@tonic-gate
501b349f08Sck142721# This mount function is sun4v only. It may be melded with the sun4u-us3
511b349f08Sck142721# version later.
521b349f08Sck142721sun4v_libc_psr_mount() {
53*22defd95Sae112802	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
547c478bd9Sstevel@tonic-gate	if [ -n "$LIBC_MOE_32" ]; then
551b349f08Sck142721		/usr/sbin/mount |
56*22defd95Sae112802		    egrep -s "^/platform/[^/]*/lib/libc_psr.so.1 on "
577c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
581b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
59*22defd95Sae112802			    /platform/$PLAT/lib/libc_psr.so.1
607c478bd9Sstevel@tonic-gate		fi
617c478bd9Sstevel@tonic-gate	fi
627c478bd9Sstevel@tonic-gate
631b349f08Sck142721	LIBC_MOE_64=`/usr/bin/moe -64 \
64*22defd95Sae112802	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
657c478bd9Sstevel@tonic-gate	if [ -n "$LIBC_MOE_64" ]; then
661b349f08Sck142721		/usr/sbin/mount |
67*22defd95Sae112802		    egrep -s "^/platform/[^/]*/lib/sparcv9/libc_psr.so.1 on "
687c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
691b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
70*22defd95Sae112802			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
711b349f08Sck142721		fi
721b349f08Sck142721	fi
731b349f08Sck142721}
741b349f08Sck142721
751b349f08Sck142721# This is specific to sun4u[-us3].
761b349f08Sck142721# try to intelligently handle the various ways that a hwcap library can
771b349f08Sck142721# be present for libc_psr for sun4u.
781b349f08Sck142721sun4u_libc_psr_mount() {
791b349f08Sck142721	# first look for $PLAT specific
801b349f08Sck142721	# the string $HWCAP is not an env var but part of the argument to moe
811b349f08Sck142721	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
821b349f08Sck142721	if [ -n "$LIBC_MOE_32" ]; then
831b349f08Sck142721		/usr/sbin/mount |
841b349f08Sck142721		    egrep -s "^/platform/$PLAT/lib/libc_psr.so.1 on "
851b349f08Sck142721		if [ $? -ne 0 ]; then
861b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
871b349f08Sck142721			    /platform/$PLAT/lib/libc_psr.so.1
881b349f08Sck142721		fi
891b349f08Sck142721	else
901b349f08Sck142721		# try the 'generic' one under $ARCH
911b349f08Sck142721		LIBC_MOE_32=`/usr/bin/moe -32 \
921b349f08Sck142721		    /platform/$ARCH/lib/libc_psr/'$HWCAP'`
931b349f08Sck142721		if [ -n "$LIBC_MOE_32" ]; then
941b349f08Sck142721			/usr/sbin/mount |
951b349f08Sck142721			    egrep -s "^/platform/$ARCH/lib/libc_psr.so.1 on "
961b349f08Sck142721			if [ $? -ne 0 ]; then
971b349f08Sck142721				/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
981b349f08Sck142721				    /platform/$ARCH/lib/libc_psr.so.1
991b349f08Sck142721			fi
1001b349f08Sck142721		fi
1011b349f08Sck142721
1021b349f08Sck142721	fi
1031b349f08Sck142721
1041b349f08Sck142721	# now repeat for 64 bit.
1051b349f08Sck142721
1061b349f08Sck142721	LIBC_MOE_64=`/usr/bin/moe -64 \
1071b349f08Sck142721	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
1081b349f08Sck142721	if [ -n "$LIBC_MOE_64" ]; then
1091b349f08Sck142721		/usr/sbin/mount |
1101b349f08Sck142721		    egrep -s "^/platform/$PLAT/lib/sparcv9/libc_psr.so.1 on "
1111b349f08Sck142721		if [ $? -ne 0 ]; then
1121b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
1131b349f08Sck142721			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
1141b349f08Sck142721		fi
1151b349f08Sck142721	else
1161b349f08Sck142721		# now try $ARCH version
1171b349f08Sck142721		LIBC_MOE_64=`/usr/bin/moe -64 \
1181b349f08Sck142721		    /platform/$ARCH/lib/sparcv9/libc_psr/'$HWCAP'`
1191b349f08Sck142721		if [ -n "$LIBC_MOE_64" ]; then
1201b349f08Sck142721			/usr/sbin/mount |
1211b349f08Sck142721			    egrep -s \
1221b349f08Sck142721			    "^/platform/$ARCH/lib/sparcv9/libc_psr.so.1 on "
1231b349f08Sck142721			if [ $? -ne 0 ]; then
1241b349f08Sck142721				/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
1251b349f08Sck142721				    /platform/$ARCH/lib/sparcv9/libc_psr.so.1
1261b349f08Sck142721			fi
1277c478bd9Sstevel@tonic-gate		fi
1287c478bd9Sstevel@tonic-gate	fi
1297c478bd9Sstevel@tonic-gate}
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate#
1327c478bd9Sstevel@tonic-gate# Most of the operations in this script are only necessary in the global
1337c478bd9Sstevel@tonic-gate# zone but due to the way initialization scripts like this are packaged,
1347c478bd9Sstevel@tonic-gate# it needs to currently exist for all zones.
1357c478bd9Sstevel@tonic-gate#
1367c478bd9Sstevel@tonic-gateif [ "${_INIT_ZONENAME:=`/sbin/zonename`}" != "global" ]; then
1377c478bd9Sstevel@tonic-gate	libc_mount
1387c478bd9Sstevel@tonic-gate	exit 0
1397c478bd9Sstevel@tonic-gatefi
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh
1427c478bd9Sstevel@tonic-gate. /lib/svc/share/fs_include.sh
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate#
1457c478bd9Sstevel@tonic-gate# Root is already mounted (by the kernel), but still needs to be
1467c478bd9Sstevel@tonic-gate# checked, possibly remounted and entered into mnttab. First
1477c478bd9Sstevel@tonic-gate# mount /usr read only if it is a separate file system. This must
1487c478bd9Sstevel@tonic-gate# be done first to allow utilities such as fsck and setmnt to
1497c478bd9Sstevel@tonic-gate# reside on /usr minimizing the space required by the root file
1507c478bd9Sstevel@tonic-gate# system.
1517c478bd9Sstevel@tonic-gate#
1527c478bd9Sstevel@tonic-gatereadvfstab "/usr" < $vfstab
1537c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
1547c478bd9Sstevel@tonic-gate	if [ "$fstype" = cachefs ]; then
1557c478bd9Sstevel@tonic-gate		#
1567c478bd9Sstevel@tonic-gate		# Mount without the cache initially.  We'll enable it
1577c478bd9Sstevel@tonic-gate		# later at remount time.  This lets us avoid
1587c478bd9Sstevel@tonic-gate		# teaching the statically linked mount program about
1597c478bd9Sstevel@tonic-gate		# cachefs.  Here we determine the backfstype.
1607c478bd9Sstevel@tonic-gate		# This is not pretty, but we have no tools for parsing
1617c478bd9Sstevel@tonic-gate		# the option string until we get /usr mounted...
1627c478bd9Sstevel@tonic-gate		#
1637c478bd9Sstevel@tonic-gate		case "$mntopts" in
1647c478bd9Sstevel@tonic-gate		*backfstype=nfs*)
1657c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
1667c478bd9Sstevel@tonic-gate			;;
1677c478bd9Sstevel@tonic-gate		*backfstype=hsfs*)
1687c478bd9Sstevel@tonic-gate			cfsbacktype=hsfs
1697c478bd9Sstevel@tonic-gate			;;
1707c478bd9Sstevel@tonic-gate		*)
1717c478bd9Sstevel@tonic-gate			msg='invalid vfstab entry for /usr'
1727c478bd9Sstevel@tonic-gate			echo $msg
1737c478bd9Sstevel@tonic-gate			echo "$SMF_FMRI:" $msg >/dev/msglog
1747c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
1757c478bd9Sstevel@tonic-gate			;;
1767c478bd9Sstevel@tonic-gate		esac
1777c478bd9Sstevel@tonic-gate		mountfs - /usr $cfsbacktype ro $special ||
1787c478bd9Sstevel@tonic-gate		    exit $SMF_EXIT_ERR_FATAL
1797c478bd9Sstevel@tonic-gate	else
1807c478bd9Sstevel@tonic-gate		#
1817c478bd9Sstevel@tonic-gate		# Must use -o largefiles here to ensure the
1827c478bd9Sstevel@tonic-gate		# read-only mount does not fail as a result of
1837c478bd9Sstevel@tonic-gate		# having a large file present on /usr. This gives
1847c478bd9Sstevel@tonic-gate		# fsck a chance to fix up the largefiles flag
1857c478bd9Sstevel@tonic-gate		# before we remount /usr read-write.
1867c478bd9Sstevel@tonic-gate		#
1877c478bd9Sstevel@tonic-gate		if [ "x$mntopts" = x- ]; then
1887c478bd9Sstevel@tonic-gate			mntopts='ro,largefiles'
1897c478bd9Sstevel@tonic-gate		else
1907c478bd9Sstevel@tonic-gate			checkopt largefiles $mntopts
1917c478bd9Sstevel@tonic-gate			if [ "x$option" != xlargefiles ]; then
1927c478bd9Sstevel@tonic-gate				mntopts="largefiles,$mntopts"
1937c478bd9Sstevel@tonic-gate			fi
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate			checkopt ro $mntopts
1967c478bd9Sstevel@tonic-gate			if [ "x$option" != xro ]; then
1977c478bd9Sstevel@tonic-gate				mntopts="ro,$mntopts"
1987c478bd9Sstevel@tonic-gate			fi
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate			#
2017c478bd9Sstevel@tonic-gate			# Requesting logging on a read-only mount
2027c478bd9Sstevel@tonic-gate			# causes errors to be displayed, so remove
2037c478bd9Sstevel@tonic-gate			# "logging" from the list of options for now.
2047c478bd9Sstevel@tonic-gate			# The read-write mount performed later will
2057c478bd9Sstevel@tonic-gate			# specify the logging option if appropriate.
2067c478bd9Sstevel@tonic-gate			#
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate			checkopt logging $mntopts
2097c478bd9Sstevel@tonic-gate			if [ "x$option" = xlogging ]; then
2107c478bd9Sstevel@tonic-gate				mntopts="$otherops"
2117c478bd9Sstevel@tonic-gate			fi
2127c478bd9Sstevel@tonic-gate		fi
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2157c478bd9Sstevel@tonic-gate	fi
2167c478bd9Sstevel@tonic-gatefi
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate#
2197c478bd9Sstevel@tonic-gate# Also mount /boot now so that things like keymap.sh can access
2207c478bd9Sstevel@tonic-gate# boot properties through eeprom.  Readonly isn't required because
2217c478bd9Sstevel@tonic-gate# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
2227c478bd9Sstevel@tonic-gate# Also, we don't account for caching /boot as it must be on a local
2237c478bd9Sstevel@tonic-gate# disk.  So what's in vfstab is fine as it stands; just look to see
2247c478bd9Sstevel@tonic-gate# if it's there and avoid the mount if not.
2257c478bd9Sstevel@tonic-gate#
2267c478bd9Sstevel@tonic-gatereadvfstab "/boot" < $vfstab
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
2297c478bd9Sstevel@tonic-gate	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2307c478bd9Sstevel@tonic-gatefi
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate#
2337c478bd9Sstevel@tonic-gate# Update kernel driver.conf cache with any additional driver.conf
2347c478bd9Sstevel@tonic-gate# files found on /usr, and device permissions from /etc/minor_perm.
2357c478bd9Sstevel@tonic-gate#
2367c478bd9Sstevel@tonic-gate/usr/sbin/devfsadm -I -P
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate[ -f /etc/.dynamic_routing ] && /usr/bin/rm -f /etc/.dynamic_routing
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gatelibc_mount
2417c478bd9Sstevel@tonic-gate
2421b349f08Sck142721#
2431b349f08Sck142721# Discover architecture and find and mount optimal libc_psr
2441b349f08Sck142721#
2451b349f08Sck142721PLAT=`/usr/bin/uname -i`
2461b349f08Sck142721ARCH=`/usr/bin/uname -m`
2471b349f08Sck142721if [ "$ARCH" = "sun4v" ]; then
2481b349f08Sck142721	sun4v_libc_psr_mount
2491b349f08Sck142721elif [ "$ARCH" = "sun4u" ]; then
2501b349f08Sck142721	if [ -h /platform/$PLAT/lib/libc_psr.so.1 ]; then
2511b349f08Sck142721		LINKSTO=`/usr/bin/ls -l /platform/$PLAT/lib/libc_psr.so.1 |
2521b349f08Sck142721			/usr/bin/awk '{print $NF}'`
2531b349f08Sck142721		if [ "$LINKSTO" = "../../sun4u-us3/lib/libc_psr.so.1" ]; then
2541b349f08Sck142721			ARCH=sun4u-us3
2551b349f08Sck142721		fi
2561b349f08Sck142721	fi
2571b349f08Sck142721	sun4u_libc_psr_mount
2581b349f08Sck142721fi
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gateexit 0
261