xref: /illumos-gate/usr/src/cmd/svc/milestone/fs-root (revision 6927f468b0af7710df000f6b16f6ee413e1e3007)
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
6*6927f468Sdp# Common Development and Distribution License (the "License").
7*6927f468Sdp# 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#
2322defd95Sae112802# Copyright 2006 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
130*6927f468Sdp. /lib/svc/share/smf_include.sh
131*6927f468Sdp. /lib/svc/share/fs_include.sh
132*6927f468Sdp
1337c478bd9Sstevel@tonic-gate#
1347c478bd9Sstevel@tonic-gate# Most of the operations in this script are only necessary in the global
1357c478bd9Sstevel@tonic-gate# zone but due to the way initialization scripts like this are packaged,
1367c478bd9Sstevel@tonic-gate# it needs to currently exist for all zones.
1377c478bd9Sstevel@tonic-gate#
138*6927f468Sdpif smf_is_nonglobalzone; then
1397c478bd9Sstevel@tonic-gate	libc_mount
140*6927f468Sdp	exit $SMF_EXIT_OK
1417c478bd9Sstevel@tonic-gatefi
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate#
1447c478bd9Sstevel@tonic-gate# Root is already mounted (by the kernel), but still needs to be
1457c478bd9Sstevel@tonic-gate# checked, possibly remounted and entered into mnttab. First
1467c478bd9Sstevel@tonic-gate# mount /usr read only if it is a separate file system. This must
1477c478bd9Sstevel@tonic-gate# be done first to allow utilities such as fsck and setmnt to
1487c478bd9Sstevel@tonic-gate# reside on /usr minimizing the space required by the root file
1497c478bd9Sstevel@tonic-gate# system.
1507c478bd9Sstevel@tonic-gate#
1517c478bd9Sstevel@tonic-gatereadvfstab "/usr" < $vfstab
1527c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
1537c478bd9Sstevel@tonic-gate	if [ "$fstype" = cachefs ]; then
1547c478bd9Sstevel@tonic-gate		#
1557c478bd9Sstevel@tonic-gate		# Mount without the cache initially.  We'll enable it
1567c478bd9Sstevel@tonic-gate		# later at remount time.  This lets us avoid
1577c478bd9Sstevel@tonic-gate		# teaching the statically linked mount program about
1587c478bd9Sstevel@tonic-gate		# cachefs.  Here we determine the backfstype.
1597c478bd9Sstevel@tonic-gate		# This is not pretty, but we have no tools for parsing
1607c478bd9Sstevel@tonic-gate		# the option string until we get /usr mounted...
1617c478bd9Sstevel@tonic-gate		#
1627c478bd9Sstevel@tonic-gate		case "$mntopts" in
1637c478bd9Sstevel@tonic-gate		*backfstype=nfs*)
1647c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
1657c478bd9Sstevel@tonic-gate			;;
1667c478bd9Sstevel@tonic-gate		*backfstype=hsfs*)
1677c478bd9Sstevel@tonic-gate			cfsbacktype=hsfs
1687c478bd9Sstevel@tonic-gate			;;
1697c478bd9Sstevel@tonic-gate		*)
1707c478bd9Sstevel@tonic-gate			msg='invalid vfstab entry for /usr'
1717c478bd9Sstevel@tonic-gate			echo $msg
1727c478bd9Sstevel@tonic-gate			echo "$SMF_FMRI:" $msg >/dev/msglog
1737c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
1747c478bd9Sstevel@tonic-gate			;;
1757c478bd9Sstevel@tonic-gate		esac
1767c478bd9Sstevel@tonic-gate		mountfs - /usr $cfsbacktype ro $special ||
1777c478bd9Sstevel@tonic-gate		    exit $SMF_EXIT_ERR_FATAL
1787c478bd9Sstevel@tonic-gate	else
1797c478bd9Sstevel@tonic-gate		#
1807c478bd9Sstevel@tonic-gate		# Must use -o largefiles here to ensure the
1817c478bd9Sstevel@tonic-gate		# read-only mount does not fail as a result of
1827c478bd9Sstevel@tonic-gate		# having a large file present on /usr. This gives
1837c478bd9Sstevel@tonic-gate		# fsck a chance to fix up the largefiles flag
1847c478bd9Sstevel@tonic-gate		# before we remount /usr read-write.
1857c478bd9Sstevel@tonic-gate		#
1867c478bd9Sstevel@tonic-gate		if [ "x$mntopts" = x- ]; then
1877c478bd9Sstevel@tonic-gate			mntopts='ro,largefiles'
1887c478bd9Sstevel@tonic-gate		else
1897c478bd9Sstevel@tonic-gate			checkopt largefiles $mntopts
1907c478bd9Sstevel@tonic-gate			if [ "x$option" != xlargefiles ]; then
1917c478bd9Sstevel@tonic-gate				mntopts="largefiles,$mntopts"
1927c478bd9Sstevel@tonic-gate			fi
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate			checkopt ro $mntopts
1957c478bd9Sstevel@tonic-gate			if [ "x$option" != xro ]; then
1967c478bd9Sstevel@tonic-gate				mntopts="ro,$mntopts"
1977c478bd9Sstevel@tonic-gate			fi
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate			#
2007c478bd9Sstevel@tonic-gate			# Requesting logging on a read-only mount
2017c478bd9Sstevel@tonic-gate			# causes errors to be displayed, so remove
2027c478bd9Sstevel@tonic-gate			# "logging" from the list of options for now.
2037c478bd9Sstevel@tonic-gate			# The read-write mount performed later will
2047c478bd9Sstevel@tonic-gate			# specify the logging option if appropriate.
2057c478bd9Sstevel@tonic-gate			#
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate			checkopt logging $mntopts
2087c478bd9Sstevel@tonic-gate			if [ "x$option" = xlogging ]; then
2097c478bd9Sstevel@tonic-gate				mntopts="$otherops"
2107c478bd9Sstevel@tonic-gate			fi
2117c478bd9Sstevel@tonic-gate		fi
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2147c478bd9Sstevel@tonic-gate	fi
2157c478bd9Sstevel@tonic-gatefi
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate#
2187c478bd9Sstevel@tonic-gate# Also mount /boot now so that things like keymap.sh can access
2197c478bd9Sstevel@tonic-gate# boot properties through eeprom.  Readonly isn't required because
2207c478bd9Sstevel@tonic-gate# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
2217c478bd9Sstevel@tonic-gate# Also, we don't account for caching /boot as it must be on a local
2227c478bd9Sstevel@tonic-gate# disk.  So what's in vfstab is fine as it stands; just look to see
2237c478bd9Sstevel@tonic-gate# if it's there and avoid the mount if not.
2247c478bd9Sstevel@tonic-gate#
2257c478bd9Sstevel@tonic-gatereadvfstab "/boot" < $vfstab
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
2287c478bd9Sstevel@tonic-gate	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
2297c478bd9Sstevel@tonic-gatefi
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate#
2327c478bd9Sstevel@tonic-gate# Update kernel driver.conf cache with any additional driver.conf
2337c478bd9Sstevel@tonic-gate# files found on /usr, and device permissions from /etc/minor_perm.
2347c478bd9Sstevel@tonic-gate#
2357c478bd9Sstevel@tonic-gate/usr/sbin/devfsadm -I -P
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate[ -f /etc/.dynamic_routing ] && /usr/bin/rm -f /etc/.dynamic_routing
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gatelibc_mount
2407c478bd9Sstevel@tonic-gate
2411b349f08Sck142721#
2421b349f08Sck142721# Discover architecture and find and mount optimal libc_psr
2431b349f08Sck142721#
2441b349f08Sck142721PLAT=`/usr/bin/uname -i`
2451b349f08Sck142721ARCH=`/usr/bin/uname -m`
2461b349f08Sck142721if [ "$ARCH" = "sun4v" ]; then
2471b349f08Sck142721	sun4v_libc_psr_mount
2481b349f08Sck142721elif [ "$ARCH" = "sun4u" ]; then
2491b349f08Sck142721	if [ -h /platform/$PLAT/lib/libc_psr.so.1 ]; then
2501b349f08Sck142721		LINKSTO=`/usr/bin/ls -l /platform/$PLAT/lib/libc_psr.so.1 |
2511b349f08Sck142721			/usr/bin/awk '{print $NF}'`
2521b349f08Sck142721		if [ "$LINKSTO" = "../../sun4u-us3/lib/libc_psr.so.1" ]; then
2531b349f08Sck142721			ARCH=sun4u-us3
2541b349f08Sck142721		fi
2551b349f08Sck142721	fi
2561b349f08Sck142721	sun4u_libc_psr_mount
2571b349f08Sck142721fi
2587c478bd9Sstevel@tonic-gate
259*6927f468Sdpexit $SMF_EXIT_OK
260