xref: /titanic_41/usr/src/cmd/svc/milestone/fs-root (revision 430b4c467020edf2445feb0c21db01c88b86243a)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
24#
25
26# Make sure that the libraries essential to this stage of booting can be found.
27LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
28
29libc_mount() {
30	#
31	# If there is an optimized libc available in /usr that fits this
32	# processor, mount it on top of the base libc.
33	#
34	LIBC_MOE_32=`/usr/bin/moe -32 '/usr/lib/libc/$HWCAP'`
35	if [ -n "$LIBC_MOE_32" ]; then
36		/usr/sbin/mount | egrep -s "^/lib/libc.so.1 on "
37		if [ $? -ne 0 ]; then
38			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 /lib/libc.so.1
39		fi
40	fi
41
42	ARCH64=`isainfo | awk '{print $1}'`
43	LIBC_MOE_64=`/usr/bin/moe -64 /usr/lib/$ARCH64/libc/'$HWCAP'`
44	if [ -n "$LIBC_MOE_64" ]; then
45		/usr/sbin/mount | egrep -s "^/lib/$ARCH64/libc.so.1 on "
46		if [ $? -ne 0 ]; then
47			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
48				/lib/$ARCH64/libc.so.1
49		fi
50	fi
51}
52
53. /lib/svc/share/smf_include.sh
54. /lib/svc/share/fs_include.sh
55
56#
57# Most of the operations in this script are only necessary in the global
58# zone but due to the way initialization scripts like this are packaged,
59# it needs to currently exist for all zones.
60#
61if smf_is_nonglobalzone; then
62	libc_mount
63	exit $SMF_EXIT_OK
64fi
65
66#
67# Root is already mounted (by the kernel), but still needs to be
68# checked, possibly remounted and entered into mnttab.  First
69# mount /usr if it is a separate file system.  If the file system
70# type is something other than zfs, mount it read-only.  This must
71# be done first to allow utilities such as fsck and setmnt to
72# reside on /usr minimizing the space required by the root file
73# system.
74#
75readvfstab "/usr" < $vfstab
76if [ -n "$mountp" ]; then
77	if [ "$fstype" = cachefs ]; then
78		#
79		# Mount without the cache initially.  We'll enable it
80		# later at remount time.  This lets us avoid
81		# teaching the statically linked mount program about
82		# cachefs.  Here we determine the backfstype.
83		# This is not pretty, but we have no tools for parsing
84		# the option string until we get /usr mounted...
85		#
86		case "$mntopts" in
87		*backfstype=nfs*)
88			cfsbacktype=nfs
89			;;
90		*backfstype=hsfs*)
91			cfsbacktype=hsfs
92			;;
93		*)
94			msg='invalid vfstab entry for /usr'
95			echo $msg
96			echo "$SMF_FMRI:" $msg >/dev/msglog
97			cfsbacktype=nfs
98			;;
99		esac
100		mountfs - /usr $cfsbacktype ro $special ||
101		    exit $SMF_EXIT_ERR_FATAL
102	elif [ "$fstype" = zfs ]; then
103		mountfs - /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
104	else
105		#
106		# Must use -o largefiles here to ensure the
107		# read-only mount does not fail as a result of
108		# having a large file present on /usr. This gives
109		# fsck a chance to fix up the largefiles flag
110		# before we remount /usr read-write.
111		#
112		if [ "x$mntopts" = x- ]; then
113			mntopts='ro,largefiles'
114		else
115			checkopt largefiles $mntopts
116			if [ "x$option" != xlargefiles ]; then
117				mntopts="largefiles,$mntopts"
118			fi
119
120			checkopt ro $mntopts
121			if [ "x$option" != xro ]; then
122				mntopts="ro,$mntopts"
123			fi
124
125			#
126			# Requesting logging on a read-only mount
127			# causes errors to be displayed, so remove
128			# "logging" from the list of options for now.
129			# The read-write mount performed later will
130			# specify the logging option if appropriate.
131			#
132
133			checkopt logging $mntopts
134			if [ "x$option" = xlogging ]; then
135				mntopts="$otherops"
136			fi
137		fi
138
139		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
140	fi
141fi
142
143#
144# if we are booted from zfs, the /usr mount probably won't be a
145# legacy mount.  Use the standard zfs mount command instead.
146
147readmnttab "/" < /etc/mnttab
148if [ "$fstype" = zfs ]; then
149	mountp=`/sbin/zfs get -H -o value mountpoint $special/usr 2>/dev/null`
150	#
151	# if mountp = /usr, there is a non-legacy mount of /usr
152	# in the boot environment being booted.
153	#
154	if [ "x$mountp" = "x/usr" ] ; then
155		/sbin/zfs mount $special/usr
156		if [ $? != 0 ] ; then
157				msg='zfs-mount failed'
158				echo $msg
159				echo "$SMF_FMRI:" $msg >/dev/msglog
160		 	exit $SMF_EXIT_ERR_FATAL
161		fi
162	fi
163fi
164
165#
166# Also mount /boot now so that things like keymap.sh can access
167# boot properties through eeprom.  Readonly isn't required because
168# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
169# Also, we don't account for caching /boot as it must be on a local
170# disk.  So what's in vfstab is fine as it stands; just look to see
171# if it's there and avoid the mount if not.
172#
173readvfstab "/boot" < $vfstab
174
175if [ -n "$mountp" ]; then
176	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
177fi
178
179#
180# Update kernel driver.conf cache with any additional driver.conf
181# files found on /usr, and device permissions from /etc/minor_perm.
182#
183/usr/sbin/devfsadm -I -P
184
185libc_mount
186
187exit $SMF_EXIT_OK
188