xref: /illumos-gate/usr/src/cmd/svc/milestone/fs-usr (revision 39b361b2ebefcef5612a54ae5cbd2179e19be296)
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 2008 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# ident	"%Z%%M%	%I%	%E% SMI"
31
32. /lib/svc/share/smf_include.sh
33. /lib/svc/share/fs_include.sh
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/zfs ]; then
59			dataset=`echo $DUMPADM_DEVICE | cut -d'/' -f5-`
60			[ -n "$dataset" ] && \
61			    /usr/sbin/zfs list -t volume $dataset > \
62			    /dev/null 2>&1
63			if [ $? -eq 0 ]; then
64				/usr/sbin/zfs volinit
65			fi
66		fi
67
68		if [ -x /usr/sbin/dumpadm -a -b $DUMPADM_DEVICE ]; then
69			/usr/sbin/dumpadm -u || exit $SMF_EXIT_ERR_CONFIG
70		fi
71	fi
72}
73
74rootiszfs=0
75# get the fstype of root
76readmnttab / </etc/mnttab
77if [ "$fstype" = zfs ] ; then
78	rootiszfs=1
79	dump_setup
80fi
81
82#
83# Add physical swap.
84#
85/sbin/swapadd -1
86
87#
88# Check and remount the / (root) file system.
89# For NFS mounts, force the llock option on.
90#
91if smf_is_globalzone && [ $rootiszfs = 0 ]; then
92	readvfstab / < $vfstab
93	checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL
94	checkopt "llock" $mntopts
95	mntopts='remount'
96
97	[ -n "$otherops" ] && mntopts="${mntopts},${otherops}"
98	[ "$fstype" = nfs ] && mntopts="${mntopts},llock"
99
100	# if root dev is a read-only metadevice then fail
101	case $special in
102	/dev/md/dsk/*)
103		dd if=/dev/null of=$special count=0 >/dev/null 2>&1 ||
104		    exit $SMF_EXIT_ERR_FATAL
105		;;
106	esac
107
108	mountfs -m $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
109fi
110
111#
112# Check and remount the /usr file system (formerly mounted read-only).
113# Unless root is zfs, in which case we've already mounted /usr read-write
114#
115if [ "$rootiszfs" = 0 ] ; then
116	readvfstab /usr < $vfstab
117	if [ "$mountp" ]; then
118		if [ "$fstype" = cachefs ]; then
119			mountfs -O $mountp cachefs $mntopts $special ||
120			    exit $SMF_EXIT_ERR_FATAL
121		else
122			checkopt ro $mntopts
123			if [ "x$option" != xro ]; then
124				checkfs $fsckdev $fstype $mountp ||
125				    exit $SMF_EXIT_ERR_FATAL
126				if [ "x$mntopts" != x- ]; then
127					mntopts="remount,$mntopts"
128				else
129					mntopts="remount"
130				fi
131
132				# if usr dev is a read-only metadevice then fail
133				case $special in
134				/dev/md/dsk/*)
135					dd if=/dev/null of=$special count=0 \
136					    >/dev/null 2>&1 || exit $SMF_EXIT_ERR_FATAL
137					;;
138				esac
139
140				mountfs - /usr $fstype $mntopts - ||
141				    exit $SMF_EXIT_ERR_FATAL
142			fi
143		fi
144	fi
145fi
146
147#
148# Check and mount the /usr/platform file system.  This should only be
149# present when a SunOS 5.5 (Solaris 2.5) or greater client is being
150# administered by a SunOS 5.4 or less host.
151#
152readvfstab /usr/platform < $vfstab
153if [ "$mountp" ]; then
154	checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL
155	mountfs - $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
156fi
157
158#
159# Mount the fd file systems if mount point exists.
160#
161readvfstab /dev/fd < $vfstab
162if [ "$mountp" -a -d /dev/fd ]; then
163	mountfs - /dev/fd - - - || exit $SMF_EXIT_ERR_FATAL
164fi
165
166exit $SMF_EXIT_OK
167