19349fc28SPeter Holm#!/bin/sh 29349fc28SPeter Holm 39349fc28SPeter Holm# 4*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 59349fc28SPeter Holm# 69349fc28SPeter Holm# Copyright (c) 2022 Peter Holm <pho@FreeBSD.org> 79349fc28SPeter Holm# 89349fc28SPeter Holm# Redistribution and use in source and binary forms, with or without 99349fc28SPeter Holm# modification, are permitted provided that the following conditions 109349fc28SPeter Holm# are met: 119349fc28SPeter Holm# 1. Redistributions of source code must retain the above copyright 129349fc28SPeter Holm# notice, this list of conditions and the following disclaimer. 139349fc28SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 149349fc28SPeter Holm# notice, this list of conditions and the following disclaimer in the 159349fc28SPeter Holm# documentation and/or other materials provided with the distribution. 169349fc28SPeter Holm# 179349fc28SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 189349fc28SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 199349fc28SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 209349fc28SPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 219349fc28SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 229349fc28SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 239349fc28SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 249349fc28SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 259349fc28SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 269349fc28SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 279349fc28SPeter Holm# SUCH DAMAGE. 289349fc28SPeter Holm# 299349fc28SPeter Holm 309349fc28SPeter Holm# A fast version of newfs.sh 319349fc28SPeter Holm 329349fc28SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 339349fc28SPeter Holm 349349fc28SPeter Holm. ../default.cfg 359349fc28SPeter Holm 369349fc28SPeter Holmmount | grep "on $mntpoint " | grep -q md$mdstart && 379349fc28SPeter Holm umount $mntpoint 389349fc28SPeter Holmmdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 399349fc28SPeter Holmmdconfig -a -t swap -s 1g -u $mdstart || exit 1 409349fc28SPeter Holm 41187f4fceSPeter Holmlog=/tmp/newfs6.sh.log 429349fc28SPeter Holms=0 439349fc28SPeter Holmfor opt in -O1 -O2 -U -j; do 449349fc28SPeter Holm bs=4096 459349fc28SPeter Holm while [ $bs -le 65536 ]; do 469349fc28SPeter Holm for i in 8 4 2 1; do 479349fc28SPeter Holm fragsize=$((bs / i)) 489349fc28SPeter Holm echo "newfs $opt -b $bs -f $fragsize md$mdstart " 499349fc28SPeter Holm newfs $opt -b $bs -f $fragsize \ 509349fc28SPeter Holm md$mdstart > /dev/null || { s=1; continue; } 519349fc28SPeter Holm mount /dev/md$mdstart $mntpoint || s=2 && 529349fc28SPeter Holm umount $mntpoint 53187f4fceSPeter Holm fsck -fy /dev/md$mdstart > $log 2>&1 54187f4fceSPeter Holm grep -q "WAS MODIFIED" $log && { 55187f4fceSPeter Holm s=3 56187f4fceSPeter Holm cat $log 57187f4fceSPeter Holm } 589349fc28SPeter Holm done 599349fc28SPeter Holm bs=$((bs * 2)) 609349fc28SPeter Holm done 619349fc28SPeter Holmdone 629349fc28SPeter Holmmdconfig -d -u $mdstart 63187f4fceSPeter Holmrm -f $log 649349fc28SPeter Holmexit $s 65