xref: /onnv-gate/usr/src/cmd/svc/milestone/fs-root (revision 12719:bd9fb35d09c2)
10Sstevel@tonic-gate#!/sbin/sh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
61573Sdp# Common Development and Distribution License (the "License").
71573Sdp# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate#
23*12719SRod.Evans@Sun.COM# Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate#
250Sstevel@tonic-gate
260Sstevel@tonic-gate# Make sure that the libraries essential to this stage of booting can be found.
270Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
280Sstevel@tonic-gate
290Sstevel@tonic-gatelibc_mount() {
300Sstevel@tonic-gate	#
310Sstevel@tonic-gate	# If there is an optimized libc available in /usr that fits this
320Sstevel@tonic-gate	# processor, mount it on top of the base libc.
330Sstevel@tonic-gate	#
349202SJason.Beloro@Sun.COM	LIBC_MOE_32=`/usr/bin/moe -32 '/usr/lib/libc/$HWCAP'`
359202SJason.Beloro@Sun.COM	if [ -n "$LIBC_MOE_32" ]; then
360Sstevel@tonic-gate		/usr/sbin/mount | egrep -s "^/lib/libc.so.1 on "
370Sstevel@tonic-gate		if [ $? -ne 0 ]; then
389202SJason.Beloro@Sun.COM			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 /lib/libc.so.1
399202SJason.Beloro@Sun.COM		fi
409202SJason.Beloro@Sun.COM	fi
419202SJason.Beloro@Sun.COM
429202SJason.Beloro@Sun.COM	ARCH64=`isainfo | awk '{print $1}'`
439202SJason.Beloro@Sun.COM	LIBC_MOE_64=`/usr/bin/moe -64 /usr/lib/$ARCH64/libc/'$HWCAP'`
449202SJason.Beloro@Sun.COM	if [ -n "$LIBC_MOE_64" ]; then
459202SJason.Beloro@Sun.COM		/usr/sbin/mount | egrep -s "^/lib/$ARCH64/libc.so.1 on "
469202SJason.Beloro@Sun.COM		if [ $? -ne 0 ]; then
479202SJason.Beloro@Sun.COM			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
489202SJason.Beloro@Sun.COM				/lib/$ARCH64/libc.so.1
490Sstevel@tonic-gate		fi
500Sstevel@tonic-gate	fi
510Sstevel@tonic-gate}
520Sstevel@tonic-gate
531573Sdp. /lib/svc/share/smf_include.sh
541573Sdp. /lib/svc/share/fs_include.sh
551573Sdp
560Sstevel@tonic-gate#
570Sstevel@tonic-gate# Most of the operations in this script are only necessary in the global
580Sstevel@tonic-gate# zone but due to the way initialization scripts like this are packaged,
590Sstevel@tonic-gate# it needs to currently exist for all zones.
600Sstevel@tonic-gate#
611573Sdpif smf_is_nonglobalzone; then
620Sstevel@tonic-gate	libc_mount
631573Sdp	exit $SMF_EXIT_OK
640Sstevel@tonic-gatefi
650Sstevel@tonic-gate
660Sstevel@tonic-gate#
670Sstevel@tonic-gate# Root is already mounted (by the kernel), but still needs to be
686168Shs24103# checked, possibly remounted and entered into mnttab.  First
696168Shs24103# mount /usr if it is a separate file system.  If the file system
706168Shs24103# type is something other than zfs, mount it read-only.  This must
710Sstevel@tonic-gate# be done first to allow utilities such as fsck and setmnt to
720Sstevel@tonic-gate# reside on /usr minimizing the space required by the root file
730Sstevel@tonic-gate# system.
740Sstevel@tonic-gate#
750Sstevel@tonic-gatereadvfstab "/usr" < $vfstab
760Sstevel@tonic-gateif [ -n "$mountp" ]; then
770Sstevel@tonic-gate	if [ "$fstype" = cachefs ]; then
780Sstevel@tonic-gate		#
790Sstevel@tonic-gate		# Mount without the cache initially.  We'll enable it
800Sstevel@tonic-gate		# later at remount time.  This lets us avoid
810Sstevel@tonic-gate		# teaching the statically linked mount program about
820Sstevel@tonic-gate		# cachefs.  Here we determine the backfstype.
830Sstevel@tonic-gate		# This is not pretty, but we have no tools for parsing
840Sstevel@tonic-gate		# the option string until we get /usr mounted...
850Sstevel@tonic-gate		#
860Sstevel@tonic-gate		case "$mntopts" in
870Sstevel@tonic-gate		*backfstype=nfs*)
880Sstevel@tonic-gate			cfsbacktype=nfs
890Sstevel@tonic-gate			;;
900Sstevel@tonic-gate		*backfstype=hsfs*)
910Sstevel@tonic-gate			cfsbacktype=hsfs
920Sstevel@tonic-gate			;;
930Sstevel@tonic-gate		*)
940Sstevel@tonic-gate			msg='invalid vfstab entry for /usr'
950Sstevel@tonic-gate			echo $msg
960Sstevel@tonic-gate			echo "$SMF_FMRI:" $msg >/dev/msglog
970Sstevel@tonic-gate			cfsbacktype=nfs
980Sstevel@tonic-gate			;;
990Sstevel@tonic-gate		esac
1000Sstevel@tonic-gate		mountfs - /usr $cfsbacktype ro $special ||
1010Sstevel@tonic-gate		    exit $SMF_EXIT_ERR_FATAL
1026168Shs24103	elif [ "$fstype" = zfs ]; then
1036168Shs24103		mountfs - /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
1040Sstevel@tonic-gate	else
1050Sstevel@tonic-gate		#
1060Sstevel@tonic-gate		# Must use -o largefiles here to ensure the
1070Sstevel@tonic-gate		# read-only mount does not fail as a result of
1080Sstevel@tonic-gate		# having a large file present on /usr. This gives
1090Sstevel@tonic-gate		# fsck a chance to fix up the largefiles flag
1100Sstevel@tonic-gate		# before we remount /usr read-write.
1110Sstevel@tonic-gate		#
1120Sstevel@tonic-gate		if [ "x$mntopts" = x- ]; then
1130Sstevel@tonic-gate			mntopts='ro,largefiles'
1140Sstevel@tonic-gate		else
1150Sstevel@tonic-gate			checkopt largefiles $mntopts
1160Sstevel@tonic-gate			if [ "x$option" != xlargefiles ]; then
1170Sstevel@tonic-gate				mntopts="largefiles,$mntopts"
1180Sstevel@tonic-gate			fi
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate			checkopt ro $mntopts
1210Sstevel@tonic-gate			if [ "x$option" != xro ]; then
1220Sstevel@tonic-gate				mntopts="ro,$mntopts"
1230Sstevel@tonic-gate			fi
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate			#
1260Sstevel@tonic-gate			# Requesting logging on a read-only mount
1270Sstevel@tonic-gate			# causes errors to be displayed, so remove
1280Sstevel@tonic-gate			# "logging" from the list of options for now.
1290Sstevel@tonic-gate			# The read-write mount performed later will
1300Sstevel@tonic-gate			# specify the logging option if appropriate.
1310Sstevel@tonic-gate			#
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate			checkopt logging $mntopts
1340Sstevel@tonic-gate			if [ "x$option" = xlogging ]; then
1350Sstevel@tonic-gate				mntopts="$otherops"
1360Sstevel@tonic-gate			fi
1370Sstevel@tonic-gate		fi
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
1400Sstevel@tonic-gate	fi
1410Sstevel@tonic-gatefi
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate#
1446168Shs24103# if we are booted from zfs, the /usr mount probably won't be a
1456168Shs24103# legacy mount.  Use the standard zfs mount command instead.
1466168Shs24103
1476168Shs24103readmnttab "/" < /etc/mnttab
1486168Shs24103if [ "$fstype" = zfs ]; then
1496168Shs24103	mountp=`/sbin/zfs get -H -o value mountpoint $special/usr 2>/dev/null`
1506168Shs24103	#
1516168Shs24103	# if mountp = /usr, there is a non-legacy mount of /usr
1526168Shs24103	# in the boot environment being booted.
1536168Shs24103	#
1546168Shs24103	if [ "x$mountp" = "x/usr" ] ; then
1556168Shs24103		/sbin/zfs mount $special/usr
1566168Shs24103		if [ $? != 0 ] ; then
1576168Shs24103				msg='zfs-mount failed'
1586168Shs24103				echo $msg
1596168Shs24103				echo "$SMF_FMRI:" $msg >/dev/msglog
1606168Shs24103		 	exit $SMF_EXIT_ERR_FATAL
1616168Shs24103		fi
1626168Shs24103	fi
1636168Shs24103fi
1646168Shs24103
1656168Shs24103#
1660Sstevel@tonic-gate# Also mount /boot now so that things like keymap.sh can access
1670Sstevel@tonic-gate# boot properties through eeprom.  Readonly isn't required because
1680Sstevel@tonic-gate# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
1690Sstevel@tonic-gate# Also, we don't account for caching /boot as it must be on a local
1700Sstevel@tonic-gate# disk.  So what's in vfstab is fine as it stands; just look to see
1710Sstevel@tonic-gate# if it's there and avoid the mount if not.
1720Sstevel@tonic-gate#
1730Sstevel@tonic-gatereadvfstab "/boot" < $vfstab
1740Sstevel@tonic-gate
1750Sstevel@tonic-gateif [ -n "$mountp" ]; then
1760Sstevel@tonic-gate	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
1770Sstevel@tonic-gatefi
1780Sstevel@tonic-gate
1790Sstevel@tonic-gate#
1800Sstevel@tonic-gate# Update kernel driver.conf cache with any additional driver.conf
1810Sstevel@tonic-gate# files found on /usr, and device permissions from /etc/minor_perm.
1820Sstevel@tonic-gate#
1830Sstevel@tonic-gate/usr/sbin/devfsadm -I -P
1840Sstevel@tonic-gate
1850Sstevel@tonic-gatelibc_mount
1860Sstevel@tonic-gate
1871573Sdpexit $SMF_EXIT_OK
188