File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / etc / default / fit2cf.sh
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Thu Mar 11 13:59:50 2021 UTC (3 years, 9 months ago) by misho
Branches: MAIN
CVS tags: elwix2_8, elwix2_7, HEAD, ELWIX2_7, ELWIX2_6
ver 2.6

#!/bin/sh
#
# (C)`10 by Michael Pounov <misho@elwix.org>
#  ELWIX grow disklabel sectors and fit-to-flash whole unused space
#
# $Id: fit2cf.sh,v 1.2 2021/03/11 13:59:50 misho Exp $
#

echo -n "++++ Check existence of fit2cf device ... "
if [ -c /dev/ufs/fit2cf ]; then
	echo "OK"
	exit 0
else
	echo "Not found!"
fi

if [ -z $1 ]; then
	echo "Not specified disk drive ..."
	exit 1
else
	DEV=$(echo $1 | awk '{ 
				if (!($1 ~ /^\//))
					printf("/dev/%s", $1);
				else
					printf("%s", $1);
			     }')
	if ! [ -c $DEV ]; then
		echo "Wrong device $DEV !!!"
		exit 1
	fi
fi

echo "Fit slice ${DEV}e to whole size of $DEV ..."
DEVSIZE=`diskinfo $DEV | awk '{ printf("%d", $4); }'`
OLDSIZE=`disklabel $DEV | awk '($1 == "c:") { printf("%d", $2); }'`
disklabel $DEV 2>&- | awk -vdevsize=$DEVSIZE -voldsize=$OLDSIZE '($1 == "c:") {
			for (i = 1; i <= NF; i++)
				printf("%s ", (i == 2) ? devsize : $i);
			printf("\n");
			next;
		      }
		      ($1 == "a:") {
			printf("e: %d %d unused 0 0 0\n", devsize - oldsize, oldsize);
		      }
		      { printf("%s\n", $0); }' >/tmp/disklabel.tmp

sysctl kern.geom.debugflags=16
disklabel -R $DEV /tmp/disklabel.tmp
newfs -b8192 -f1024 -m0 -Lfit2cf ${DEV}e
sysctl kern.geom.debugflags=0

rm -f /tmp/disklabel.tmp
echo
echo " Now will restart system to activate new schema !!!"
echo
kill -2 1

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>