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