xref: /illumos-gate/usr/src/cmd/svc/milestone/fs-usr (revision e7cbe64f7a72dae5cb44f100db60ca88f3313c65)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
66927f468Sdp# Common Development and Distribution License (the "License").
76927f468Sdp# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23c63537d6Sth199096# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
277c478bd9Sstevel@tonic-gate# All rights reserved.
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate#
307c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh
337c478bd9Sstevel@tonic-gate. /lib/svc/share/fs_include.sh
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate#
36*e7cbe64fSgw25295# Once root is read/write we can enable the dedicated dumpdevice if it exists
37*e7cbe64fSgw25295# locally. This is an optimization as svc-dumpadm will attempt do this later.
387c478bd9Sstevel@tonic-gate#
39*e7cbe64fSgw25295dump_setup()
40*e7cbe64fSgw25295{
41*e7cbe64fSgw25295	[ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf
42*e7cbe64fSgw25295
43*e7cbe64fSgw25295	readswapdev $DUMPADM_DEVICE < $vfstab
44*e7cbe64fSgw25295
45*e7cbe64fSgw25295	#
46*e7cbe64fSgw25295	# If we have a dedicated dump device, then go ahead and configure it.
47*e7cbe64fSgw25295	#
48*e7cbe64fSgw25295	if [ "x$special" != "x$DUMPADM_DEVICE" ]; then
49*e7cbe64fSgw25295		if [ -x /usr/sbin/zfs ]; then
50*e7cbe64fSgw25295			dataset=`echo $DUMPADM_DEVICE | cut -d'/' -f5-`
51*e7cbe64fSgw25295			[ -n "$dataset" ] && \
52*e7cbe64fSgw25295			    /usr/sbin/zfs list -t volume $dataset > \
53*e7cbe64fSgw25295			    /dev/null 2>&1
54*e7cbe64fSgw25295			if [ $? -eq 0 ]; then
55*e7cbe64fSgw25295				/usr/sbin/zfs volinit
56*e7cbe64fSgw25295			fi
57*e7cbe64fSgw25295		fi
58*e7cbe64fSgw25295
59*e7cbe64fSgw25295		if [ -x /usr/sbin/dumpadm -a -b $DUMPADM_DEVICE ]; then
60*e7cbe64fSgw25295			/usr/sbin/dumpadm -u || exit $SMF_EXIT_ERR_CONFIG
61*e7cbe64fSgw25295		fi
62*e7cbe64fSgw25295	fi
63*e7cbe64fSgw25295}
647c478bd9Sstevel@tonic-gate
65a227b7f4Shs24103rootiszfs=0
66a227b7f4Shs24103# get the fstype of root
67a227b7f4Shs24103readmnttab / </etc/mnttab
68a227b7f4Shs24103if [ "$fstype" = zfs ] ; then
69a227b7f4Shs24103	rootiszfs=1
70*e7cbe64fSgw25295	dump_setup
71a227b7f4Shs24103fi
72a227b7f4Shs24103
737c478bd9Sstevel@tonic-gate#
74*e7cbe64fSgw25295# Add physical swap.
75*e7cbe64fSgw25295#
76*e7cbe64fSgw25295/sbin/swapadd -1
77*e7cbe64fSgw25295
78*e7cbe64fSgw25295#
797c478bd9Sstevel@tonic-gate# Check and remount the / (root) file system.
807c478bd9Sstevel@tonic-gate# For NFS mounts, force the llock option on.
817c478bd9Sstevel@tonic-gate#
82a227b7f4Shs24103if smf_is_globalzone && [ $rootiszfs = 0 ]; then
837c478bd9Sstevel@tonic-gate	readvfstab / < $vfstab
847c478bd9Sstevel@tonic-gate	checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL
857c478bd9Sstevel@tonic-gate	checkopt "llock" $mntopts
867c478bd9Sstevel@tonic-gate	mntopts='remount'
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate	[ -n "$otherops" ] && mntopts="${mntopts},${otherops}"
897c478bd9Sstevel@tonic-gate	[ "$fstype" = nfs ] && mntopts="${mntopts},llock"
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate	# if root dev is a read-only metadevice then fail
927c478bd9Sstevel@tonic-gate	case $special in
937c478bd9Sstevel@tonic-gate	/dev/md/dsk/*)
947c478bd9Sstevel@tonic-gate		dd if=/dev/null of=$special count=0 >/dev/null 2>&1 ||
957c478bd9Sstevel@tonic-gate		    exit $SMF_EXIT_ERR_FATAL
967c478bd9Sstevel@tonic-gate		;;
977c478bd9Sstevel@tonic-gate	esac
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate	mountfs -m $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
1007c478bd9Sstevel@tonic-gatefi
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate#
1037c478bd9Sstevel@tonic-gate# Check and remount the /usr file system (formerly mounted read-only).
104a227b7f4Shs24103# Unless root is zfs, in which case we've already mounted /usr read-write
1057c478bd9Sstevel@tonic-gate#
106a227b7f4Shs24103if [ "$rootiszfs" = 0 ] ; then
1077c478bd9Sstevel@tonic-gate	readvfstab /usr < $vfstab
1087c478bd9Sstevel@tonic-gate	if [ "$mountp" ]; then
1097c478bd9Sstevel@tonic-gate		if [ "$fstype" = cachefs ]; then
1107c478bd9Sstevel@tonic-gate			mountfs -O $mountp cachefs $mntopts $special ||
1117c478bd9Sstevel@tonic-gate			    exit $SMF_EXIT_ERR_FATAL
1127c478bd9Sstevel@tonic-gate		else
1137c478bd9Sstevel@tonic-gate			checkopt ro $mntopts
1147c478bd9Sstevel@tonic-gate			if [ "x$option" != xro ]; then
1157c478bd9Sstevel@tonic-gate				checkfs $fsckdev $fstype $mountp ||
1167c478bd9Sstevel@tonic-gate				    exit $SMF_EXIT_ERR_FATAL
1177c478bd9Sstevel@tonic-gate				if [ "x$mntopts" != x- ]; then
1187c478bd9Sstevel@tonic-gate					mntopts="remount,$mntopts"
1197c478bd9Sstevel@tonic-gate				else
1207c478bd9Sstevel@tonic-gate					mntopts="remount"
1217c478bd9Sstevel@tonic-gate				fi
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate				# if usr dev is a read-only metadevice then fail
1247c478bd9Sstevel@tonic-gate				case $special in
1257c478bd9Sstevel@tonic-gate				/dev/md/dsk/*)
1267c478bd9Sstevel@tonic-gate					dd if=/dev/null of=$special count=0 \
1277c478bd9Sstevel@tonic-gate					    >/dev/null 2>&1 || exit $SMF_EXIT_ERR_FATAL
1287c478bd9Sstevel@tonic-gate					;;
1297c478bd9Sstevel@tonic-gate				esac
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate				mountfs - /usr $fstype $mntopts - ||
1327c478bd9Sstevel@tonic-gate				    exit $SMF_EXIT_ERR_FATAL
1337c478bd9Sstevel@tonic-gate			fi
1347c478bd9Sstevel@tonic-gate		fi
1357c478bd9Sstevel@tonic-gate	fi
136a227b7f4Shs24103fi
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate#
1397c478bd9Sstevel@tonic-gate# Check and mount the /usr/platform file system.  This should only be
1407c478bd9Sstevel@tonic-gate# present when a SunOS 5.5 (Solaris 2.5) or greater client is being
1417c478bd9Sstevel@tonic-gate# administered by a SunOS 5.4 or less host.
1427c478bd9Sstevel@tonic-gate#
1437c478bd9Sstevel@tonic-gatereadvfstab /usr/platform < $vfstab
1447c478bd9Sstevel@tonic-gateif [ "$mountp" ]; then
1457c478bd9Sstevel@tonic-gate	checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL
1467c478bd9Sstevel@tonic-gate	mountfs - $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL
1477c478bd9Sstevel@tonic-gatefi
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate#
1507c478bd9Sstevel@tonic-gate# Mount the fd file systems if mount point exists.
1517c478bd9Sstevel@tonic-gate#
1527c478bd9Sstevel@tonic-gatereadvfstab /dev/fd < $vfstab
1537c478bd9Sstevel@tonic-gateif [ "$mountp" -a -d /dev/fd ]; then
1547c478bd9Sstevel@tonic-gate	mountfs - /dev/fd - - - || exit $SMF_EXIT_ERR_FATAL
1557c478bd9Sstevel@tonic-gatefi
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gateexit $SMF_EXIT_OK
158