xref: /onnv-gate/usr/src/cmd/lvm/util/growfs.sh (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/bin/sh
2*0Sstevel@tonic-gate#
3*0Sstevel@tonic-gate# CDDL HEADER START
4*0Sstevel@tonic-gate#
5*0Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*0Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*0Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*0Sstevel@tonic-gate# with the License.
9*0Sstevel@tonic-gate#
10*0Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*0Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*0Sstevel@tonic-gate# See the License for the specific language governing permissions
13*0Sstevel@tonic-gate# and limitations under the License.
14*0Sstevel@tonic-gate#
15*0Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*0Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*0Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*0Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*0Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*0Sstevel@tonic-gate#
21*0Sstevel@tonic-gate# CDDL HEADER END
22*0Sstevel@tonic-gate#
23*0Sstevel@tonic-gate#
24*0Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
25*0Sstevel@tonic-gate#
26*0Sstevel@tonic-gate# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
27*0Sstevel@tonic-gate# Use is subject to license terms.
28*0Sstevel@tonic-gate#
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate#exec newfs -G "$@"
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gatemyname=`basename $0`
33*0Sstevel@tonic-gateUSAGE="usage: $myname [ -M mount-point ] [ newfs-options ] raw-special-device"
34*0Sstevel@tonic-gateif [ ! "$UFS_MKFS" ]; then
35*0Sstevel@tonic-gate	UFS_MKFS="/usr/lib/fs/ufs/mkfs"
36*0Sstevel@tonic-gatefi
37*0Sstevel@tonic-gateverbose=""
38*0Sstevel@tonic-gatemkfs_opts="-G"
39*0Sstevel@tonic-gatemkfs_subopts=""
40*0Sstevel@tonic-gatesize=""
41*0Sstevel@tonic-gatenewsize=0
42*0Sstevel@tonic-gatemount_pt=
43*0Sstevel@tonic-gateUFS_MKFS_NOTENOUGHSPACE=33
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gateadd_opt() {
46*0Sstevel@tonic-gate	mkfs_opts="$mkfs_opts $1"
47*0Sstevel@tonic-gate}
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gateadd_subopt() {
50*0Sstevel@tonic-gate	if [ ! "$mkfs_subopts" ]; then
51*0Sstevel@tonic-gate		mkfs_subopts="-o $1"
52*0Sstevel@tonic-gate	else
53*0Sstevel@tonic-gate		mkfs_subopts="$mkfs_subopts,$1"
54*0Sstevel@tonic-gate	fi
55*0Sstevel@tonic-gate}
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gatewhile getopts "GM:Nva:b:c:d:f:i:m:n:o:r:s:t:C:" c ; do
58*0Sstevel@tonic-gate	save=$OPTIND
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate	case $c in
61*0Sstevel@tonic-gate	G)	;;
62*0Sstevel@tonic-gate	M)	add_opt "-M $OPTARG"; mount_pt="$OPTARG" ;;
63*0Sstevel@tonic-gate	N)	add_subopt "N" ;;
64*0Sstevel@tonic-gate	v)	verbose="1" ;;
65*0Sstevel@tonic-gate	a)	add_subopt "apc=$OPTARG" ;;
66*0Sstevel@tonic-gate	b)	add_subopt "bsize=$OPTARG" ;;
67*0Sstevel@tonic-gate	c)	add_subopt "cgsize=$OPTARG" ;;
68*0Sstevel@tonic-gate	d)	add_subopt "gap=$OPTARG" ;;
69*0Sstevel@tonic-gate	f)	add_subopt "fragsize=$OPTARG" ;;
70*0Sstevel@tonic-gate	i)	add_subopt "nbpi=$OPTARG" ;;
71*0Sstevel@tonic-gate	m)	add_subopt "free=$OPTARG" ;;
72*0Sstevel@tonic-gate	n)	add_subopt "nrpos=$OPTARG" ;;
73*0Sstevel@tonic-gate	o)	add_subopt "opt=$OPTARG" ;;
74*0Sstevel@tonic-gate	r)	add_subopt "rps=`expr $OPTARG / 60`" ;;
75*0Sstevel@tonic-gate	s)	size=$OPTARG ;;
76*0Sstevel@tonic-gate	t)	add_subopt "ntrack=$OPTARG" ;;
77*0Sstevel@tonic-gate	C)	add_subopt "maxcontig=$OPTARG" ;;
78*0Sstevel@tonic-gate	\?)	echo $USAGE; exit 1 ;;
79*0Sstevel@tonic-gate	esac
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate	OPTIND=$save
82*0Sstevel@tonic-gatedone
83*0Sstevel@tonic-gate
84*0Sstevel@tonic-gateshift `expr $OPTIND - 1`
85*0Sstevel@tonic-gateif [ $# -ne 1 ]; then
86*0Sstevel@tonic-gate	echo $USAGE
87*0Sstevel@tonic-gate	exit 1
88*0Sstevel@tonic-gatefi
89*0Sstevel@tonic-gateraw_special=$1
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gateif [ ! "$size" ]; then
92*0Sstevel@tonic-gate	size=`devinfo -p $raw_special | awk '{ print $5 }'`
93*0Sstevel@tonic-gate	if [ $? -ne 0 -o ! "$size" ]; then
94*0Sstevel@tonic-gate		echo "$myname: cannot get partition size"
95*0Sstevel@tonic-gate		exit 2
96*0Sstevel@tonic-gate	fi
97*0Sstevel@tonic-gatefi
98*0Sstevel@tonic-gate
99*0Sstevel@tonic-gatecmd="$UFS_MKFS $mkfs_opts $mkfs_subopts $raw_special $size"
100*0Sstevel@tonic-gateif [ -n "$verbose" ]; then
101*0Sstevel@tonic-gate	echo $cmd
102*0Sstevel@tonic-gatefi
103*0Sstevel@tonic-gate$cmd; retv=$?
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gateif [ $retv -eq $UFS_MKFS_NOTENOUGHSPACE ]; then
106*0Sstevel@tonic-gate	echo "Growing filesystem in increments due to limited available space."
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate	while [ "$newsize" -lt "$size" ]; do
109*0Sstevel@tonic-gate		cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts -P $raw_special $size"
110*0Sstevel@tonic-gate		if [ -n "$verbose" ]; then
111*0Sstevel@tonic-gate			echo $cmd
112*0Sstevel@tonic-gate		fi
113*0Sstevel@tonic-gate		newsize=`$cmd`; retv=$?
114*0Sstevel@tonic-gate		if [ 0 -ne $retv -o -z "$newsize" ]; then
115*0Sstevel@tonic-gate			echo "$myname: cannot probe the possible file system size"
116*0Sstevel@tonic-gate			exit 2
117*0Sstevel@tonic-gate		fi
118*0Sstevel@tonic-gate		if [ 0 -eq "$newsize" ]; then
119*0Sstevel@tonic-gate			echo "$myname: the file system is full and cannot be grown, please delete some files"
120*0Sstevel@tonic-gate			exit 2
121*0Sstevel@tonic-gate		fi
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gate		cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts $raw_special $newsize"; retv=$?
124*0Sstevel@tonic-gate		if [ -n "$verbose" ]; then
125*0Sstevel@tonic-gate			echo $cmd
126*0Sstevel@tonic-gate		fi
127*0Sstevel@tonic-gate		$cmd; retv=$?
128*0Sstevel@tonic-gate		if [ 0 -ne $retv ]; then
129*0Sstevel@tonic-gate			echo "$myname: cannot grow file system to $newsize sectors"
130*0Sstevel@tonic-gate			exit  $retv
131*0Sstevel@tonic-gate		fi
132*0Sstevel@tonic-gate	done
133*0Sstevel@tonic-gate	echo \
134*0Sstevel@tonic-gate"\nThe incremental grow has successfully completed, but since the first growth \
135*0Sstevel@tonic-gateattempt failed (see output from first mkfs(1M) run), the filesystem is still \
136*0Sstevel@tonic-gatelocked and needs to be checked with fsck(1M).\n\
137*0Sstevel@tonic-gatePlease run \`fsck -F ufs $raw_special' and then unlock the filesystem \
138*0Sstevel@tonic-gatewith \`lockfs -u $mount_pt'." | fmt;
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gatefi
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gateexit $retv
143