xref: /titanic_53/usr/src/cmd/svc/milestone/fs-root (revision 1b349f08205ae4c89d0cbd3d8906d947a17ce56d)
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#
247c478bd9Sstevel@tonic-gate# Copyright 2005 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
50*1b349f08Sck142721# This mount function is sun4v only. It may be melded with the sun4u-us3
51*1b349f08Sck142721# version later.
52*1b349f08Sck142721sun4v_libc_psr_mount() {
537c478bd9Sstevel@tonic-gate	LIBC_MOE_32=`/usr/bin/moe -32 '/platform/sun4v/lib/libc_psr/$HWCAP'`
547c478bd9Sstevel@tonic-gate	if [ -n "$LIBC_MOE_32" ]; then
55*1b349f08Sck142721		/usr/sbin/mount |
56*1b349f08Sck142721		    egrep -s "^/platform/sun4v/lib/libc_psr.so.1 on "
577c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
58*1b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
59*1b349f08Sck142721			    /platform/sun4v/lib/libc_psr.so.1
607c478bd9Sstevel@tonic-gate		fi
617c478bd9Sstevel@tonic-gate	fi
627c478bd9Sstevel@tonic-gate
63*1b349f08Sck142721	LIBC_MOE_64=`/usr/bin/moe -64 \
64*1b349f08Sck142721	    '/platform/sun4v/lib/sparcv9/libc_psr/$HWCAP'`
657c478bd9Sstevel@tonic-gate	if [ -n "$LIBC_MOE_64" ]; then
66*1b349f08Sck142721		/usr/sbin/mount |
67*1b349f08Sck142721		    egrep -s "^/platform/sun4v/lib/sparcv9/libc_psr.so.1 on "
687c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
69*1b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
70*1b349f08Sck142721			    /platform/sun4v/lib/sparcv9/libc_psr.so.1
71*1b349f08Sck142721		fi
72*1b349f08Sck142721	fi
73*1b349f08Sck142721}
74*1b349f08Sck142721
75*1b349f08Sck142721# This is specific to sun4u[-us3].
76*1b349f08Sck142721# try to intelligently handle the various ways that a hwcap library can
77*1b349f08Sck142721# be present for libc_psr for sun4u.
78*1b349f08Sck142721sun4u_libc_psr_mount() {
79*1b349f08Sck142721	# first look for $PLAT specific
80*1b349f08Sck142721	# the string $HWCAP is not an env var but part of the argument to moe
81*1b349f08Sck142721	LIBC_MOE_32=`/usr/bin/moe -32 /platform/$PLAT/lib/libc_psr/'$HWCAP'`
82*1b349f08Sck142721	if [ -n "$LIBC_MOE_32" ]; then
83*1b349f08Sck142721		/usr/sbin/mount |
84*1b349f08Sck142721		    egrep -s "^/platform/$PLAT/lib/libc_psr.so.1 on "
85*1b349f08Sck142721		if [ $? -ne 0 ]; then
86*1b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
87*1b349f08Sck142721			    /platform/$PLAT/lib/libc_psr.so.1
88*1b349f08Sck142721		fi
89*1b349f08Sck142721	else
90*1b349f08Sck142721		# try the 'generic' one under $ARCH
91*1b349f08Sck142721		LIBC_MOE_32=`/usr/bin/moe -32 \
92*1b349f08Sck142721		    /platform/$ARCH/lib/libc_psr/'$HWCAP'`
93*1b349f08Sck142721		if [ -n "$LIBC_MOE_32" ]; then
94*1b349f08Sck142721			/usr/sbin/mount |
95*1b349f08Sck142721			    egrep -s "^/platform/$ARCH/lib/libc_psr.so.1 on "
96*1b349f08Sck142721			if [ $? -ne 0 ]; then
97*1b349f08Sck142721				/usr/sbin/mount -O -F lofs $LIBC_MOE_32 \
98*1b349f08Sck142721				    /platform/$ARCH/lib/libc_psr.so.1
99*1b349f08Sck142721			fi
100*1b349f08Sck142721		fi
101*1b349f08Sck142721
102*1b349f08Sck142721	fi
103*1b349f08Sck142721
104*1b349f08Sck142721	# now repeat for 64 bit.
105*1b349f08Sck142721
106*1b349f08Sck142721	LIBC_MOE_64=`/usr/bin/moe -64 \
107*1b349f08Sck142721	    /platform/$PLAT/lib/sparcv9/libc_psr/'$HWCAP'`
108*1b349f08Sck142721	if [ -n "$LIBC_MOE_64" ]; then
109*1b349f08Sck142721		/usr/sbin/mount |
110*1b349f08Sck142721		    egrep -s "^/platform/$PLAT/lib/sparcv9/libc_psr.so.1 on "
111*1b349f08Sck142721		if [ $? -ne 0 ]; then
112*1b349f08Sck142721			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
113*1b349f08Sck142721			    /platform/$PLAT/lib/sparcv9/libc_psr.so.1
114*1b349f08Sck142721		fi
115*1b349f08Sck142721	else
116*1b349f08Sck142721		# now try $ARCH version
117*1b349f08Sck142721		LIBC_MOE_64=`/usr/bin/moe -64 \
118*1b349f08Sck142721		    /platform/$ARCH/lib/sparcv9/libc_psr/'$HWCAP'`
119*1b349f08Sck142721		if [ -n "$LIBC_MOE_64" ]; then
120*1b349f08Sck142721			/usr/sbin/mount |
121*1b349f08Sck142721			    egrep -s \
122*1b349f08Sck142721			    "^/platform/$ARCH/lib/sparcv9/libc_psr.so.1 on "
123*1b349f08Sck142721			if [ $? -ne 0 ]; then
124*1b349f08Sck142721				/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
125*1b349f08Sck142721				    /platform/$ARCH/lib/sparcv9/libc_psr.so.1
126*1b349f08Sck142721			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
242*1b349f08Sck142721#
243*1b349f08Sck142721# Discover architecture and find and mount optimal libc_psr
244*1b349f08Sck142721#
245*1b349f08Sck142721PLAT=`/usr/bin/uname -i`
246*1b349f08Sck142721ARCH=`/usr/bin/uname -m`
247*1b349f08Sck142721if [ "$ARCH" = "sun4v" ]; then
248*1b349f08Sck142721	sun4v_libc_psr_mount
249*1b349f08Sck142721elif [ "$ARCH" = "sun4u" ]; then
250*1b349f08Sck142721	if [ -h /platform/$PLAT/lib/libc_psr.so.1 ]; then
251*1b349f08Sck142721		LINKSTO=`/usr/bin/ls -l /platform/$PLAT/lib/libc_psr.so.1 |
252*1b349f08Sck142721			/usr/bin/awk '{print $NF}'`
253*1b349f08Sck142721		if [ "$LINKSTO" = "../../sun4u-us3/lib/libc_psr.so.1" ]; then
254*1b349f08Sck142721			ARCH=sun4u-us3
255*1b349f08Sck142721		fi
256*1b349f08Sck142721	fi
257*1b349f08Sck142721	sun4u_libc_psr_mount
258*1b349f08Sck142721fi
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gateexit 0
261