xref: /illumos-gate/usr/src/cmd/growfs/growfs.sh (revision bbf21555)
17c478bd9Sstevel@tonic-gate#!/bin/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
67c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
77c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
87c478bd9Sstevel@tonic-gate# with the License.
97c478bd9Sstevel@tonic-gate#
107c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
117c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
127c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
137c478bd9Sstevel@tonic-gate# and limitations under the License.
147c478bd9Sstevel@tonic-gate#
157c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
167c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
177c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
187c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
197c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate# CDDL HEADER END
227c478bd9Sstevel@tonic-gate#
239717555dSYuri Pankov
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate# Use is subject to license terms.
277c478bd9Sstevel@tonic-gate#
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#exec newfs -G "$@"
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gatemyname=`basename $0`
327c478bd9Sstevel@tonic-gateUSAGE="usage: $myname [ -M mount-point ] [ newfs-options ] raw-special-device"
337c478bd9Sstevel@tonic-gateif [ ! "$UFS_MKFS" ]; then
347c478bd9Sstevel@tonic-gate	UFS_MKFS="/usr/lib/fs/ufs/mkfs"
357c478bd9Sstevel@tonic-gatefi
367c478bd9Sstevel@tonic-gateverbose=""
377c478bd9Sstevel@tonic-gatemkfs_opts="-G"
387c478bd9Sstevel@tonic-gatemkfs_subopts=""
397c478bd9Sstevel@tonic-gatesize=""
407c478bd9Sstevel@tonic-gatenewsize=0
417c478bd9Sstevel@tonic-gatemount_pt=
427c478bd9Sstevel@tonic-gateUFS_MKFS_NOTENOUGHSPACE=33
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gateadd_opt() {
457c478bd9Sstevel@tonic-gate	mkfs_opts="$mkfs_opts $1"
467c478bd9Sstevel@tonic-gate}
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gateadd_subopt() {
497c478bd9Sstevel@tonic-gate	if [ ! "$mkfs_subopts" ]; then
507c478bd9Sstevel@tonic-gate		mkfs_subopts="-o $1"
517c478bd9Sstevel@tonic-gate	else
527c478bd9Sstevel@tonic-gate		mkfs_subopts="$mkfs_subopts,$1"
537c478bd9Sstevel@tonic-gate	fi
547c478bd9Sstevel@tonic-gate}
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gatewhile getopts "GM:Nva:b:c:d:f:i:m:n:o:r:s:t:C:" c ; do
577c478bd9Sstevel@tonic-gate	save=$OPTIND
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate	case $c in
607c478bd9Sstevel@tonic-gate	G)	;;
617c478bd9Sstevel@tonic-gate	M)	add_opt "-M $OPTARG"; mount_pt="$OPTARG" ;;
627c478bd9Sstevel@tonic-gate	N)	add_subopt "N" ;;
637c478bd9Sstevel@tonic-gate	v)	verbose="1" ;;
647c478bd9Sstevel@tonic-gate	a)	add_subopt "apc=$OPTARG" ;;
657c478bd9Sstevel@tonic-gate	b)	add_subopt "bsize=$OPTARG" ;;
667c478bd9Sstevel@tonic-gate	c)	add_subopt "cgsize=$OPTARG" ;;
677c478bd9Sstevel@tonic-gate	d)	add_subopt "gap=$OPTARG" ;;
687c478bd9Sstevel@tonic-gate	f)	add_subopt "fragsize=$OPTARG" ;;
697c478bd9Sstevel@tonic-gate	i)	add_subopt "nbpi=$OPTARG" ;;
707c478bd9Sstevel@tonic-gate	m)	add_subopt "free=$OPTARG" ;;
717c478bd9Sstevel@tonic-gate	n)	add_subopt "nrpos=$OPTARG" ;;
727c478bd9Sstevel@tonic-gate	o)	add_subopt "opt=$OPTARG" ;;
737c478bd9Sstevel@tonic-gate	r)	add_subopt "rps=`expr $OPTARG / 60`" ;;
747c478bd9Sstevel@tonic-gate	s)	size=$OPTARG ;;
757c478bd9Sstevel@tonic-gate	t)	add_subopt "ntrack=$OPTARG" ;;
767c478bd9Sstevel@tonic-gate	C)	add_subopt "maxcontig=$OPTARG" ;;
777c478bd9Sstevel@tonic-gate	\?)	echo $USAGE; exit 1 ;;
787c478bd9Sstevel@tonic-gate	esac
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate	OPTIND=$save
817c478bd9Sstevel@tonic-gatedone
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
847c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
857c478bd9Sstevel@tonic-gate	echo $USAGE
867c478bd9Sstevel@tonic-gate	exit 1
877c478bd9Sstevel@tonic-gatefi
887c478bd9Sstevel@tonic-gateraw_special=$1
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gateif [ ! "$size" ]; then
917c478bd9Sstevel@tonic-gate	size=`devinfo -p $raw_special | awk '{ print $5 }'`
927c478bd9Sstevel@tonic-gate	if [ $? -ne 0 -o ! "$size" ]; then
937c478bd9Sstevel@tonic-gate		echo "$myname: cannot get partition size"
947c478bd9Sstevel@tonic-gate		exit 2
957c478bd9Sstevel@tonic-gate	fi
967c478bd9Sstevel@tonic-gatefi
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gatecmd="$UFS_MKFS $mkfs_opts $mkfs_subopts $raw_special $size"
997c478bd9Sstevel@tonic-gateif [ -n "$verbose" ]; then
1007c478bd9Sstevel@tonic-gate	echo $cmd
1017c478bd9Sstevel@tonic-gatefi
1027c478bd9Sstevel@tonic-gate$cmd; retv=$?
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gateif [ $retv -eq $UFS_MKFS_NOTENOUGHSPACE ]; then
1057c478bd9Sstevel@tonic-gate	echo "Growing filesystem in increments due to limited available space."
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate	while [ "$newsize" -lt "$size" ]; do
1087c478bd9Sstevel@tonic-gate		cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts -P $raw_special $size"
1097c478bd9Sstevel@tonic-gate		if [ -n "$verbose" ]; then
1107c478bd9Sstevel@tonic-gate			echo $cmd
1117c478bd9Sstevel@tonic-gate		fi
1127c478bd9Sstevel@tonic-gate		newsize=`$cmd`; retv=$?
1137c478bd9Sstevel@tonic-gate		if [ 0 -ne $retv -o -z "$newsize" ]; then
1147c478bd9Sstevel@tonic-gate			echo "$myname: cannot probe the possible file system size"
1157c478bd9Sstevel@tonic-gate			exit 2
1167c478bd9Sstevel@tonic-gate		fi
1177c478bd9Sstevel@tonic-gate		if [ 0 -eq "$newsize" ]; then
1187c478bd9Sstevel@tonic-gate			echo "$myname: the file system is full and cannot be grown, please delete some files"
1197c478bd9Sstevel@tonic-gate			exit 2
1207c478bd9Sstevel@tonic-gate		fi
1219717555dSYuri Pankov
1227c478bd9Sstevel@tonic-gate		cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts $raw_special $newsize"; retv=$?
1237c478bd9Sstevel@tonic-gate		if [ -n "$verbose" ]; then
1247c478bd9Sstevel@tonic-gate			echo $cmd
1257c478bd9Sstevel@tonic-gate		fi
1267c478bd9Sstevel@tonic-gate		$cmd; retv=$?
1277c478bd9Sstevel@tonic-gate		if [ 0 -ne $retv ]; then
1287c478bd9Sstevel@tonic-gate			echo "$myname: cannot grow file system to $newsize sectors"
1297c478bd9Sstevel@tonic-gate			exit  $retv
1307c478bd9Sstevel@tonic-gate		fi
1317c478bd9Sstevel@tonic-gate	done
1327c478bd9Sstevel@tonic-gate	echo \
1337c478bd9Sstevel@tonic-gate"\nThe incremental grow has successfully completed, but since the first growth \
134*bbf21555SRichard Loweattempt failed (see output from first mkfs(8) run), the filesystem is still \
135*bbf21555SRichard Lowelocked and needs to be checked with fsck(8).\n\
1367c478bd9Sstevel@tonic-gatePlease run \`fsck -F ufs $raw_special' and then unlock the filesystem \
1377c478bd9Sstevel@tonic-gatewith \`lockfs -u $mount_pt'." | fmt;
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gatefi
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gateexit $retv
142