xref: /titanic_50/usr/src/cmd/svc/milestone/fs-usr (revision 5667185bc023b9742cb2480659d7673fa9ac8050)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
27# All rights reserved.
28#
29#
30. /lib/svc/share/smf_include.sh
31. /lib/svc/share/fs_include.sh
32
33UPDATEFILE=/etc/svc/volatile/boot_archive_needs_update
34
35#
36# Once root is read/write we can enable the dedicated dumpdevice if it exists
37# locally. This is an optimization as svc-dumpadm will attempt do this later.
38#
39dump_setup()
40{
41	[ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf
42
43	readswapdev $DUMPADM_DEVICE < $vfstab
44
45	#
46	# Make sure that the dump save area has been configured before
47	# proceeding. If the variable has not been defined or does not exist
48	# then bail out early. This will prevent us from configuring a
49	# dump save area before a hostname has been configured (i.e after
50	# sys-unconfig has been invoked).
51	#
52	[ -z "$DUMPADM_SAVDIR" ] && return
53
54	#
55	# If we have a dedicated dump device, then go ahead and configure it.
56	#
57	if [ "x$special" != "x$DUMPADM_DEVICE" ]; then
58		if [ -x /usr/sbin/dumpadm -a -b $DUMPADM_DEVICE ]; then
59			/usr/sbin/dumpadm -u || exit $SMF_EXIT_ERR_CONFIG
60		fi
61	fi
62}
63
64rootiszfs=0
65# get the fstype of root
66readmnttab / </etc/mnttab
67if [ "$fstype" = zfs ] ; then
68	rootiszfs=1
69	dump_setup
70fi
71
72#
73# Add physical swap.
74#
75/sbin/swapadd -1
76
77#
78# Check and remount the / (root) file system.
79# For NFS mounts, force the llock option on.
80#
81if smf_is_globalzone && [ $rootiszfs = 0 ]; then
82	readvfstab / < $vfstab
83	checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL
84	checkopt "llock" $mntopts
85	mntopts='remount'
86
87	[ -n "$otherops" ] && mntopts="${mntopts},${otherops}"
88	[ "$fstype" = nfs ] && mntopts="${mntopts},llock"
89
90	# if root dev is a read-only metadevice then fail
91	case $special in
92	/dev/md/dsk/*)
93		dd if=/dev/null of=$special count=0 >/dev/null 2>&1 ||
94		    exit $SMF_EXIT_ERR_FATAL
95		;;
96	esac
97
98	mountfs -m $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
99fi
100
101#
102# Check and remount the /usr file system (formerly mounted read-only).
103# Unless root is zfs, in which case we've already mounted /usr read-write
104#
105if [ "$rootiszfs" = 0 ] ; then
106	readvfstab /usr < $vfstab
107	if [ "$mountp" ]; then
108		if [ "$fstype" = cachefs ]; then
109			mountfs -O $mountp cachefs $mntopts $special ||
110			    exit $SMF_EXIT_ERR_FATAL
111		else
112			checkopt ro $mntopts
113			if [ "x$option" != xro ]; then
114				checkfs $fsckdev $fstype $mountp ||
115				    exit $SMF_EXIT_ERR_FATAL
116				if [ "x$mntopts" != x- ]; then
117					mntopts="remount,$mntopts"
118				else
119					mntopts="remount"
120				fi
121
122				# if usr dev is a read-only metadevice then fail
123				case $special in
124				/dev/md/dsk/*)
125					dd if=/dev/null of=$special count=0 \
126					    >/dev/null 2>&1 || exit $SMF_EXIT_ERR_FATAL
127					;;
128				esac
129
130				mountfs - /usr $fstype $mntopts - ||
131				    exit $SMF_EXIT_ERR_FATAL
132			fi
133		fi
134	fi
135fi
136
137#
138# Check and mount the /usr/platform file system.  This should only be
139# present when a SunOS 5.5 (Solaris 2.5) or greater client is being
140# administered by a SunOS 5.4 or less host.
141#
142readvfstab /usr/platform < $vfstab
143if [ "$mountp" ]; then
144	checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL
145	mountfs - $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
146fi
147
148#
149# Mount the fd file systems if mount point exists.
150#
151readvfstab /dev/fd < $vfstab
152if [ "$mountp" -a -d /dev/fd ]; then
153	mountfs - /dev/fd - - - || exit $SMF_EXIT_ERR_FATAL
154fi
155
156if [ -f "${UPDATEFILE}" ]; then
157	/usr/sbin/bootadm update-archive
158	if [ $? != 0 ]; then
159		cecho ""
160		cecho "WARNING: Automatic update of the boot archive failed."
161		cecho "Try update the archives using 'bootadm update-archive'"
162		cecho "command and then reboot the system from the same device that"
163		cecho "was previously booted."
164		cecho ""
165		exit $SMF_EXIT_ERR_FATAL
166	fi
167	rm -f $UPDATEFILE
168	bootcmd=`/usr/sbin/eeprom bootcmd | /usr/bin/sed -e 's#bootcmd=##g'`
169	if [ `uname -p` = "i386" ]; then
170		/usr/sbin/reboot -f dryrun
171		if [ $? = 0 ]; then
172			/usr/sbin/reboot -f -- "$bootcmd"
173			exit $SMF_EXIT_OK
174		fi
175		boot_prop=`/usr/sbin/svccfg -s svc:/system/boot-config:default listprop config/trust-bios-boot-device | \
176			/usr/bin/nawk '{ print $3}'`
177		if [ "$boot_prop" != "true" ]; then
178			cecho ""
179			cecho "WARNING: Reboot required."
180			cecho "The system has updated the cache of files (boot archive) that is used"
181			cecho "during the early boot sequence. To avoid booting and running the system"
182			cecho "with the previously out-of-sync version of these files, reboot the"
183			cecho "system from the same device that was previously booted."
184			cecho ""
185			exit $SMF_EXIT_ERR_FATAL
186		else
187			/usr/sbin/reboot -p
188			exit $SMF_EXIT_OK
189		fi
190	fi
191	/usr/sbin/reboot -- "$bootcmd"
192fi
193
194exit $SMF_EXIT_OK
195