xref: /titanic_44/usr/src/cmd/svc/milestone/fs-root (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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*1e49577aSRod Evans# Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate# Make sure that the libraries essential to this stage of booting can be found.
277c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gatelibc_mount() {
307c478bd9Sstevel@tonic-gate	#
317c478bd9Sstevel@tonic-gate	# If there is an optimized libc available in /usr that fits this
327c478bd9Sstevel@tonic-gate	# processor, mount it on top of the base libc.
337c478bd9Sstevel@tonic-gate	#
34b1593d50SJason Beloro	LIBC_MOE_32=`/usr/bin/moe -32 '/usr/lib/libc/$HWCAP'`
35b1593d50SJason Beloro	if [ -n "$LIBC_MOE_32" ]; then
367c478bd9Sstevel@tonic-gate		/usr/sbin/mount | egrep -s "^/lib/libc.so.1 on "
377c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
38b1593d50SJason Beloro			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 /lib/libc.so.1
39b1593d50SJason Beloro		fi
40b1593d50SJason Beloro	fi
41b1593d50SJason Beloro
42b1593d50SJason Beloro	ARCH64=`isainfo | awk '{print $1}'`
43b1593d50SJason Beloro	LIBC_MOE_64=`/usr/bin/moe -64 /usr/lib/$ARCH64/libc/'$HWCAP'`
44b1593d50SJason Beloro	if [ -n "$LIBC_MOE_64" ]; then
45b1593d50SJason Beloro		/usr/sbin/mount | egrep -s "^/lib/$ARCH64/libc.so.1 on "
46b1593d50SJason Beloro		if [ $? -ne 0 ]; then
47b1593d50SJason Beloro			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
48b1593d50SJason Beloro				/lib/$ARCH64/libc.so.1
497c478bd9Sstevel@tonic-gate		fi
507c478bd9Sstevel@tonic-gate	fi
517c478bd9Sstevel@tonic-gate}
527c478bd9Sstevel@tonic-gate
536927f468Sdp. /lib/svc/share/smf_include.sh
546927f468Sdp. /lib/svc/share/fs_include.sh
556927f468Sdp
567c478bd9Sstevel@tonic-gate#
577c478bd9Sstevel@tonic-gate# Most of the operations in this script are only necessary in the global
587c478bd9Sstevel@tonic-gate# zone but due to the way initialization scripts like this are packaged,
597c478bd9Sstevel@tonic-gate# it needs to currently exist for all zones.
607c478bd9Sstevel@tonic-gate#
616927f468Sdpif smf_is_nonglobalzone; then
627c478bd9Sstevel@tonic-gate	libc_mount
636927f468Sdp	exit $SMF_EXIT_OK
647c478bd9Sstevel@tonic-gatefi
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate#
677c478bd9Sstevel@tonic-gate# Root is already mounted (by the kernel), but still needs to be
687c478bd9Sstevel@tonic-gate# checked, possibly remounted and entered into mnttab.  First
69a227b7f4Shs24103# mount /usr if it is a separate file system.  If the file system
70a227b7f4Shs24103# type is something other than zfs, mount it read-only.  This must
717c478bd9Sstevel@tonic-gate# be done first to allow utilities such as fsck and setmnt to
727c478bd9Sstevel@tonic-gate# reside on /usr minimizing the space required by the root file
737c478bd9Sstevel@tonic-gate# system.
747c478bd9Sstevel@tonic-gate#
757c478bd9Sstevel@tonic-gatereadvfstab "/usr" < $vfstab
767c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
777c478bd9Sstevel@tonic-gate	if [ "$fstype" = cachefs ]; then
787c478bd9Sstevel@tonic-gate		#
797c478bd9Sstevel@tonic-gate		# Mount without the cache initially.  We'll enable it
807c478bd9Sstevel@tonic-gate		# later at remount time.  This lets us avoid
817c478bd9Sstevel@tonic-gate		# teaching the statically linked mount program about
827c478bd9Sstevel@tonic-gate		# cachefs.  Here we determine the backfstype.
837c478bd9Sstevel@tonic-gate		# This is not pretty, but we have no tools for parsing
847c478bd9Sstevel@tonic-gate		# the option string until we get /usr mounted...
857c478bd9Sstevel@tonic-gate		#
867c478bd9Sstevel@tonic-gate		case "$mntopts" in
877c478bd9Sstevel@tonic-gate		*backfstype=nfs*)
887c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
897c478bd9Sstevel@tonic-gate			;;
907c478bd9Sstevel@tonic-gate		*backfstype=hsfs*)
917c478bd9Sstevel@tonic-gate			cfsbacktype=hsfs
927c478bd9Sstevel@tonic-gate			;;
937c478bd9Sstevel@tonic-gate		*)
947c478bd9Sstevel@tonic-gate			msg='invalid vfstab entry for /usr'
957c478bd9Sstevel@tonic-gate			echo $msg
967c478bd9Sstevel@tonic-gate			echo "$SMF_FMRI:" $msg >/dev/msglog
977c478bd9Sstevel@tonic-gate			cfsbacktype=nfs
987c478bd9Sstevel@tonic-gate			;;
997c478bd9Sstevel@tonic-gate		esac
1007c478bd9Sstevel@tonic-gate		mountfs - /usr $cfsbacktype ro $special ||
1017c478bd9Sstevel@tonic-gate		    exit $SMF_EXIT_ERR_FATAL
102a227b7f4Shs24103	elif [ "$fstype" = zfs ]; then
103a227b7f4Shs24103		mountfs - /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
1047c478bd9Sstevel@tonic-gate	else
1057c478bd9Sstevel@tonic-gate		#
1067c478bd9Sstevel@tonic-gate		# Must use -o largefiles here to ensure the
1077c478bd9Sstevel@tonic-gate		# read-only mount does not fail as a result of
1087c478bd9Sstevel@tonic-gate		# having a large file present on /usr. This gives
1097c478bd9Sstevel@tonic-gate		# fsck a chance to fix up the largefiles flag
1107c478bd9Sstevel@tonic-gate		# before we remount /usr read-write.
1117c478bd9Sstevel@tonic-gate		#
1127c478bd9Sstevel@tonic-gate		if [ "x$mntopts" = x- ]; then
1137c478bd9Sstevel@tonic-gate			mntopts='ro,largefiles'
1147c478bd9Sstevel@tonic-gate		else
1157c478bd9Sstevel@tonic-gate			checkopt largefiles $mntopts
1167c478bd9Sstevel@tonic-gate			if [ "x$option" != xlargefiles ]; then
1177c478bd9Sstevel@tonic-gate				mntopts="largefiles,$mntopts"
1187c478bd9Sstevel@tonic-gate			fi
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate			checkopt ro $mntopts
1217c478bd9Sstevel@tonic-gate			if [ "x$option" != xro ]; then
1227c478bd9Sstevel@tonic-gate				mntopts="ro,$mntopts"
1237c478bd9Sstevel@tonic-gate			fi
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate			#
1267c478bd9Sstevel@tonic-gate			# Requesting logging on a read-only mount
1277c478bd9Sstevel@tonic-gate			# causes errors to be displayed, so remove
1287c478bd9Sstevel@tonic-gate			# "logging" from the list of options for now.
1297c478bd9Sstevel@tonic-gate			# The read-write mount performed later will
1307c478bd9Sstevel@tonic-gate			# specify the logging option if appropriate.
1317c478bd9Sstevel@tonic-gate			#
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate			checkopt logging $mntopts
1347c478bd9Sstevel@tonic-gate			if [ "x$option" = xlogging ]; then
1357c478bd9Sstevel@tonic-gate				mntopts="$otherops"
1367c478bd9Sstevel@tonic-gate			fi
1377c478bd9Sstevel@tonic-gate		fi
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
1407c478bd9Sstevel@tonic-gate	fi
1417c478bd9Sstevel@tonic-gatefi
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate#
144a227b7f4Shs24103# if we are booted from zfs, the /usr mount probably won't be a
145a227b7f4Shs24103# legacy mount.  Use the standard zfs mount command instead.
146a227b7f4Shs24103
147a227b7f4Shs24103readmnttab "/" < /etc/mnttab
148a227b7f4Shs24103if [ "$fstype" = zfs ]; then
149a227b7f4Shs24103	mountp=`/sbin/zfs get -H -o value mountpoint $special/usr 2>/dev/null`
150a227b7f4Shs24103	#
151a227b7f4Shs24103	# if mountp = /usr, there is a non-legacy mount of /usr
152a227b7f4Shs24103	# in the boot environment being booted.
153a227b7f4Shs24103	#
154a227b7f4Shs24103	if [ "x$mountp" = "x/usr" ] ; then
155a227b7f4Shs24103		/sbin/zfs mount $special/usr
156a227b7f4Shs24103		if [ $? != 0 ] ; then
157a227b7f4Shs24103				msg='zfs-mount failed'
158a227b7f4Shs24103				echo $msg
159a227b7f4Shs24103				echo "$SMF_FMRI:" $msg >/dev/msglog
160a227b7f4Shs24103		 	exit $SMF_EXIT_ERR_FATAL
161a227b7f4Shs24103		fi
162a227b7f4Shs24103	fi
163a227b7f4Shs24103fi
164a227b7f4Shs24103
165a227b7f4Shs24103#
1667c478bd9Sstevel@tonic-gate# Also mount /boot now so that things like keymap.sh can access
1677c478bd9Sstevel@tonic-gate# boot properties through eeprom.  Readonly isn't required because
1687c478bd9Sstevel@tonic-gate# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
1697c478bd9Sstevel@tonic-gate# Also, we don't account for caching /boot as it must be on a local
1707c478bd9Sstevel@tonic-gate# disk.  So what's in vfstab is fine as it stands; just look to see
1717c478bd9Sstevel@tonic-gate# if it's there and avoid the mount if not.
1727c478bd9Sstevel@tonic-gate#
1737c478bd9Sstevel@tonic-gatereadvfstab "/boot" < $vfstab
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gateif [ -n "$mountp" ]; then
1767c478bd9Sstevel@tonic-gate	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
1777c478bd9Sstevel@tonic-gatefi
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate#
1807c478bd9Sstevel@tonic-gate# Update kernel driver.conf cache with any additional driver.conf
1817c478bd9Sstevel@tonic-gate# files found on /usr, and device permissions from /etc/minor_perm.
1827c478bd9Sstevel@tonic-gate#
1837c478bd9Sstevel@tonic-gate/usr/sbin/devfsadm -I -P
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gatelibc_mount
1867c478bd9Sstevel@tonic-gate
1876927f468Sdpexit $SMF_EXIT_OK
188