xref: /illumos-gate/usr/src/cmd/svc/milestone/fs-root (revision 71d45228ba245d505c3beae1d756e775616f6d5a)
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# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
25#
26
27# Make sure that the libraries essential to this stage of booting can be found.
28LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
29
30libc_mount() {
31	#
32	# If there is an optimized libc available in /usr that fits this
33	# processor, mount it on top of the base libc.
34	#
35	LIBC_MOE_32=`/usr/bin/moe -32 '/usr/lib/libc/$HWCAP'`
36	if [ -n "$LIBC_MOE_32" ]; then
37		/usr/sbin/mount | egrep -s "^/lib/libc.so.1 on "
38		if [ $? -ne 0 ]; then
39			/usr/sbin/mount -O -F lofs $LIBC_MOE_32 /lib/libc.so.1
40		fi
41	fi
42
43	ARCH64=`isainfo | awk '{print $1}'`
44	LIBC_MOE_64=`/usr/bin/moe -64 /usr/lib/$ARCH64/libc/'$HWCAP'`
45	if [ -n "$LIBC_MOE_64" ]; then
46		/usr/sbin/mount | egrep -s "^/lib/$ARCH64/libc.so.1 on "
47		if [ $? -ne 0 ]; then
48			/usr/sbin/mount -O -F lofs $LIBC_MOE_64 \
49				/lib/$ARCH64/libc.so.1
50		fi
51	fi
52}
53
54. /lib/svc/share/smf_include.sh
55. /lib/svc/share/fs_include.sh
56
57#
58# Most of the operations in this script are only necessary in the global
59# zone but due to the way initialization scripts like this are packaged,
60# it needs to currently exist for all zones.
61#
62if smf_is_nonglobalzone; then
63	libc_mount
64	exit $SMF_EXIT_OK
65fi
66
67#
68# Root is already mounted (by the kernel), but still needs to be
69# checked, possibly remounted and entered into mnttab.  First
70# mount /usr if it is a separate file system.  If the file system
71# type is something other than zfs, mount it read-only.  This must
72# be done first to allow utilities such as fsck and setmnt to
73# reside on /usr minimizing the space required by the root file
74# system.
75#
76readvfstab "/usr" < $vfstab
77if [ -n "$mountp" ]; then
78	if [ "$fstype" = zfs ]; then
79		mountfs - /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
80	else
81		#
82		# Must use -o largefiles here to ensure the
83		# read-only mount does not fail as a result of
84		# having a large file present on /usr. This gives
85		# fsck a chance to fix up the largefiles flag
86		# before we remount /usr read-write.
87		#
88		if [ "x$mntopts" = x- ]; then
89			mntopts='ro,largefiles'
90		else
91			checkopt largefiles $mntopts
92			if [ "x$option" != xlargefiles ]; then
93				mntopts="largefiles,$mntopts"
94			fi
95
96			checkopt ro $mntopts
97			if [ "x$option" != xro ]; then
98				mntopts="ro,$mntopts"
99			fi
100
101			#
102			# Requesting logging on a read-only mount
103			# causes errors to be displayed, so remove
104			# "logging" from the list of options for now.
105			# The read-write mount performed later will
106			# specify the logging option if appropriate.
107			#
108
109			checkopt logging $mntopts
110			if [ "x$option" = xlogging ]; then
111				mntopts="$otherops"
112			fi
113		fi
114
115		mountfs -O /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
116	fi
117fi
118
119#
120# if we are booted from zfs, the /usr mount probably won't be a
121# legacy mount.  Use the standard zfs mount command instead.
122
123readmnttab "/" < /etc/mnttab
124if [ "$fstype" = zfs ]; then
125	mountp=`/sbin/zfs get -H -o value mountpoint $special/usr 2>/dev/null`
126	#
127	# if mountp = /usr, there is a non-legacy mount of /usr
128	# in the boot environment being booted.
129	#
130	if [ "x$mountp" = "x/usr" ] ; then
131		/sbin/zfs mount $special/usr
132		if [ $? != 0 ] ; then
133				msg='zfs-mount failed'
134				echo $msg
135				echo "$SMF_FMRI:" $msg >/dev/msglog
136		 	exit $SMF_EXIT_ERR_FATAL
137		fi
138	fi
139fi
140
141#
142# Also mount /boot now so that things like keymap.sh can access
143# boot properties through eeprom.  Readonly isn't required because
144# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.
145# Also, we don't account for caching /boot as it must be on a local
146# disk.  So what's in vfstab is fine as it stands; just look to see
147# if it's there and avoid the mount if not.
148#
149readvfstab "/boot" < $vfstab
150
151if [ -n "$mountp" ]; then
152	mountfs - /boot $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
153fi
154
155#
156# Update kernel driver.conf cache with any additional driver.conf
157# files found on /usr, and device permissions from /etc/minor_perm.
158#
159/usr/sbin/devfsadm -I -P
160
161libc_mount
162
163exit $SMF_EXIT_OK
164