From lev@ftp.translate.ru  Sun Oct 24 18:37:46 2010
Return-Path: <lev@ftp.translate.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B59721065679
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 24 Oct 2010 18:37:46 +0000 (UTC)
	(envelope-from lev@ftp.translate.ru)
Received: from ftp.translate.ru (ftp.translate.ru [80.249.188.42])
	by mx1.freebsd.org (Postfix) with ESMTP id 49C0C8FC12
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 24 Oct 2010 18:37:46 +0000 (UTC)
Received: by ftp.translate.ru (Postfix, from userid 1000)
	id 6619F13DF46; Sun, 24 Oct 2010 22:37:45 +0400 (MSD)
Message-Id: <20101024183745.6619F13DF46@ftp.translate.ru>
Date: Sun, 24 Oct 2010 22:37:45 +0400 (MSD)
From: Lev Serebryakov <lev@FreeBSD.org>
Reply-To: Lev Serebryakov <lev@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [nanobsd] [patch] Add two new options to nanobsd.sh to make rebuilds faster
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         151698
>Category:       misc
>Synopsis:       [nanobsd] [patch] Add two new options to nanobsd.sh to make rebuilds faster
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 24 18:40:10 UTC 2010
>Closed-Date:    Thu Mar 13 22:17:36 MDT 2014
>Last-Modified:  Thu Mar 13 22:17:36 MDT 2014
>Originator:     Lev Serebryakov
>Release:        FreeBSD 8.1-STABLE i386
>Organization:
>Environment:
System: FreeBSD vmware-8-32.home.serebryakov.spb.ru 8.1-STABLE FreeBSD 8.1-STABLE #1: Wed Oct 20 18:55:10 MSD 2010 root@vmware-8-32.home.serebryakov.spb.ru:/usr/obj/usr/src/sys/GENERIC i386

>Description:

  This patch adds two new options to nanobsd.sh:

  -f ([f]ast) options supress of extraction of CODE slice (s1) from final image. If you need full image to prepare new device, you don't need separate file with CODE slice, and this otions saves lots of time.
  -z ([z]ap) option works only if NANO_MD_BACKING=file and supresses creation of image file from "/dev/zero". It zeroes out two first cylinders of EXISTENT image file, left from previous runs. If image file is absent or has wrong size, process stops.

  These two options, when used together, make experiments with creating NanoBSD images MUCH faster even on modern hardware.

>How-To-Repeat:

>Fix:
--- nanobsd.sh.orig	2010-10-24 22:20:07.000000000 +0400
+++ nanobsd.sh.faster	2010-10-24 22:22:28.000000000 +0400
@@ -466,9 +466,20 @@
 		MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \
 			-y ${NANO_HEADS}`
 	else
-		echo "Creating md backing file..."
-		dd if=/dev/zero of=${IMG} bs=${NANO_SECTS}b \
-			count=`expr ${NANO_MEDIASIZE} / ${NANO_SECTS}`
+		if $do_create_md_file || ! [ -f ${IMG} ] ; then
+			echo "Creating md backing file..."
+			dd if=/dev/zero of=${IMG} bs=${NANO_SECTS}b \
+				count=`expr ${NANO_MEDIASIZE} / ${NANO_SECTS}`
+		else
+			echo "Check & zap md backing file..."
+			MD_SIZE=`stat -f '%z' ${IMG}`
+			MD_SIZE=$(( ${MDSIZE} / 512 ))
+			if [ "${MD_SIZE}" != "${NANO_MEDIASIZE}" ] ; then
+				echo "Invalid ${IMG} size (found ${MD_SIZE} sectors, need ${NANO_MEDIASIZE})"
+				exit 1
+			fi
+			dd if=/dev/zero of=${IMG} bs=1024 count=`expr ${NANO_SECTS} '*' ${NANO_HEADS}` conv=notrunc
+		fi
 		MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
 			-y ${NANO_HEADS}`
 	fi
@@ -521,8 +532,10 @@
 		dd if=/dev/${MD} of=${IMG} bs=64k
 	fi
 
-	echo "Writing out _.disk.image..."
-	dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
+	if do_copyout_partition ; then
+		echo "Writing out _.disk.image..."
+		dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
+	fi
 	mdconfig -d -u $MD
 
 	trap - 1 2 15 EXIT
@@ -712,14 +725,16 @@
 
 usage () {
 	(
-	echo "Usage: $0 [-biknqvw] [-c config_file]"
+	echo "Usage: $0 [-bfiknqvwz] [-c config_file]"
 	echo "	-b	suppress builds (both kernel and world)"
+	echo "	-f	suppress code slice extraction"
 	echo "	-i	suppress disk image build"
 	echo "	-k	suppress buildkernel"
 	echo "	-n	add -DNO_CLEAN to buildworld, buildkernel, etc"
 	echo "	-q	make output more quiet"
 	echo "	-v	make output more verbose"
 	echo "	-w	suppress buildworld"
+	echo "	-z	use existing disk image instead creating new one"
 	echo "	-c	specify config file"
 	) 1>&2
 	exit 2
@@ -732,9 +747,11 @@
 do_kernel=true
 do_world=true
 do_image=true
+do_create_md_file=true
+do_copyout_partition=true
 
 set +e
-args=`getopt bc:hiknqvw $*`
+args=`getopt bc:fhiknqvwz $*`
 if [ $? -ne 0 ] ; then
 	usage
 	exit 2
@@ -760,6 +777,10 @@
 		shift
 		shift
 		;;
+	-f)
+		do_copyout_partition=false
+		shift
+		;;
 	-h)
 		usage
 		;;
@@ -783,6 +804,10 @@
 		do_world=false
 		shift
 		;;
+	-z)
+		do_create_md_file=true
+		shift
+		;;
 	--)
 		shift
 		break
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-embedded 
Responsible-Changed-By: lev 
Responsible-Changed-When: Sun Oct 24 18:46:01 UTC 2010 
Responsible-Changed-Why:  

Over to maintainer(s). 


http://www.freebsd.org/cgi/query-pr.cgi?pr=151698 
Responsible-Changed-From-To: freebsd-embedded->imp 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Nov 20 11:55:16 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=151698 
State-Changed-From-To: open->patched 
State-Changed-By: imp 
State-Changed-When: Fri May 13 12:37:43 MDT 2011 
State-Changed-Why:  
-f committed, -z unneeded.  MFC to follow. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=151698 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/151698: commit references a PR
Date: Fri, 13 May 2011 18:36:43 +0000 (UTC)

 Author: imp
 Date: Fri May 13 18:36:24 2011
 New Revision: 221851
 URL: http://svn.freebsd.org/changeset/base/221851
 
 Log:
   Implement -f to inhibit copying s1 partition out for speed.
   (-z not taken from PR, it is no longer needed since we basically always
    do that now)
   
   PR:		misc/151698
   Submitted by:	lev@
 
 Modified:
   head/tools/tools/nanobsd/nanobsd.sh
 
 Modified: head/tools/tools/nanobsd/nanobsd.sh
 ==============================================================================
 --- head/tools/tools/nanobsd/nanobsd.sh	Fri May 13 18:28:25 2011	(r221850)
 +++ head/tools/tools/nanobsd/nanobsd.sh	Fri May 13 18:36:24 2011	(r221851)
 @@ -567,8 +567,10 @@ create_i386_diskimage ( ) (
  		dd if=/dev/${MD} of=${IMG} bs=64k
  	fi
  
 -	echo "Writing out _.disk.image..."
 -	dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
 +	if do_copyout_partition ; then
 +		echo "Writing out _.disk.image..."
 +		dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
 +	fi
  	mdconfig -d -u $MD
  
  	trap - 1 2 15 EXIT
 @@ -758,8 +760,9 @@ pprint() {
  
  usage () {
  	(
 -	echo "Usage: $0 [-biknqvw] [-c config_file]"
 +	echo "Usage: $0 [-bfiknqvw] [-c config_file]"
  	echo "	-b	suppress builds (both kernel and world)"
 +	echo "	-f	suppress code slice extraction"
  	echo "	-i	suppress disk image build"
  	echo "	-k	suppress buildkernel"
  	echo "	-n	add -DNO_CLEAN to buildworld, buildkernel, etc"
 @@ -778,9 +781,10 @@ do_clean=true
  do_kernel=true
  do_world=true
  do_image=true
 +do_copyout_partition=true
  
  set +e
 -args=`getopt bc:hiknqvw $*`
 +args=`getopt bc:fhiknqvw $*`
  if [ $? -ne 0 ] ; then
  	usage
  	exit 2
 @@ -806,6 +810,10 @@ do
  		shift
  		shift
  		;;
 +	-f)
 +		do_copyout_partition=false
 +		shift
 +		;;
  	-h)
  		usage
  		;;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: imp 
State-Changed-When: Thu Mar 13 22:17:25 MDT 2014 
State-Changed-Why:  
This is in 9 and 10, so	can be closed. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=151698 
>Unformatted:
