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