mfsbsd icon indicating copy to clipboard operation
mfsbsd copied to clipboard

[PATCH] tools/do_gpt.sh calls makefs in an inefficient manner

Open ngie-eign opened this issue 11 years ago • 1 comments

According to one of our internal developers, calling makefs as-is in tools/do_gpt.sh is very slow. I've provided the patch below.

I would go one step further and say that the filesystem disk should be created in a sparse manner, not as a densely populated disk image.

Also, the block size is small (1kB). It could and should be larger (1MB at least).

A lot of this should be fixed/improved with the mkimg utility in 11+, but that's a different utility for a different day...

commit e10947989b275767e1e2e5a4e0bd89b8b342f788
Author: Russell Cattelan 
Date:   Wed May 21 14:51:19 2014 -0500

    Speed up the disk.img creation.

    Pointing makefs directly at the md mapped disk
    image is really slow. So use a temp file to create
    the file system image and then dd that directly
    to the mdp2 partition
--- a/tools/do_gpt.sh
+++ b/tools/do_gpt.sh
@@ -1,9 +1,6 @@
 #!/bin/sh
 #
-# $FreeBSD: src/release/scripts/doFS.sh,v 1.60 2004/08/25 01:39:52 kensmith Exp $
-#
-
-set -ex
+set -e

 FSIMG=$1
 FSPROTO=$2
@@ -41,7 +38,7 @@ fi
 echo "FSIMG ${FSIMG} FSPROTO ${FSPROTO} FSSIZE ${FSSIZE}"

 dd of=${FSIMG} if=/dev/zero count=${FSSIZE} bs=1k
-mdconfig -t vnode -f ${FSIMG}
+dd of=${FSIMG}.$$ if=/dev/zero count=${FSSIZE} bs=1k

 export unit=`mdconfig -a -t vnode -f ${FSIMG}`
 if [ $? -ne 0 ]; then
@@ -49,12 +46,16 @@ if [ $? -ne 0 ]; then
   exit 1
 fi

+set -x
 gpart create -s gpt ${unit}
 gpart add -t freebsd-boot -b 34 -l boot -s 512K ${unit}
 gpart bootcode -b ${FSPROTO}/boot/pmbr -p ${FSPROTO}/boot/gptboot -i 1 ${unit}
 gpart add -t freebsd-ufs -l rootfs ${unit}

-makefs -B little /dev/${unit}p2 ${FSPROTO}
+time makefs -B little ${FSIMG}.$$ ${FSPROTO}
+time dd if=${FSIMG}.$$ of=/dev/${unit}p2 bs=16384
+set +x
+rm ${FSIMG}.$$
 if [ $? -ne 0 ]; then
   echo "makefs failed"
   exit_with 1

ngie-eign avatar Oct 10 '14 20:10 ngie-eign

Please note that ${FSIMG}.$$ also needs to be removed in do_exit.

ngie-eign avatar Oct 10 '14 20:10 ngie-eign