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