From nobody@FreeBSD.org  Thu Nov  8 20:29:29 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 0F15C18B
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  8 Nov 2012 20:29:29 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id D1FCB8FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  8 Nov 2012 20:29:28 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qA8KTSF6063500
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 8 Nov 2012 20:29:28 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qA8KTSmg063499;
	Thu, 8 Nov 2012 20:29:28 GMT
	(envelope-from nobody)
Message-Id: <201211082029.qA8KTSmg063499@red.freebsd.org>
Date: Thu, 8 Nov 2012 20:29:28 GMT
From: Nick Hibma <nick@anywi.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [Patch] NanoBSD images should be created sparsely.
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         173482
>Category:       misc
>Synopsis:       [nanobsd] [patch] NanoBSD images should be created sparsely.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 08 20:30:00 UTC 2012
>Closed-Date:    Sun Apr 28 22:13:37 UTC 2013
>Last-Modified:  Sun Apr 28 22:13:37 UTC 2013
>Originator:     Nick Hibma
>Release:        FreeBSD 8.3-RELEASE i386
>Organization:
AnyWi Technologies
>Environment:
System: FreeBSD bitske2.localdomain 8.3-RELEASE FreeBSD 8.3-RELEASE #0 r242660: Tue Nov 6 16:23:23 CET 2012 root@bitske2.localdomain:/usr/obj/usr/src/sys/GENERIC i386
>Description:
When an image is copied out into _.disk.image this could be done sparsely. I
use a Virtual machine to build the images, and writing them sparsely saves time
and space. This makes a huge difference when not initialising the second
partition (NANO_INIT_IMG2=0)

Note: The backing files are already created sparsely (using 'seek=<size>
count=0' arguments to dd).


The diff below contains also a comment on how to speed up installing packages
(using a null mount instead of copying the packages across). We install several
MBs of packages and this speeds things up dramatically.

A similar piece of code works beautifully in our package install (which
cherry-picks the packages that need to be installed instead of installing the
packages wholesale).

>How-To-Repeat:

>Fix:
--- AnyWi/freebsd/nanobsd/nanobsd.sh	2012-11-08 19:48:40.000000000 +0100
+++ /usr/src/tools/tools/nanobsd/nanobsd.sh	2012-11-06 15:24:52.000000000 +0100
@@ -540,7 +540,7 @@
 	if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
 		# Duplicate to second image (if present)
 		echo "Duplicating to second image..."
-		dd conv=sparse if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
+		dd if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
 		mount /dev/${MD}s2a ${MNT}
 		for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab
 		do
@@ -569,7 +569,7 @@
 
 	if ${do_copyout_partition} ; then
 		echo "Writing out _.disk.image..."
-		dd conv=sparse if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
+		dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
 	fi
 	mdconfig -d -u $MD
 
@@ -683,16 +683,6 @@
 # Install packages from ${NANO_PACKAGE_DIR}
 
 cust_pkg () (
-	# XXX This should be replaced by a nullfs mount, like so
-	#	mkdir -p ${NANO_WORLDDIR}/Pkg
-	#	trap "umount ${NANO_PACKAGE_DIR}Pkg" 1 2 3 15 EXIT
-	#	mount -t nullfs ${NANO_PACKAGE_DIR}Pkg ${NANO_WORLDDIR}/Pkg
-	# and replace the rm -rf below with the following:
-	#	umount $NANO_WORLDDIR$PKG_PATH
-	#	rmdir $NANO_WORLDDIR$PKG_PATH
-	#	trap - 1 2 3 15 EXIT
-	# Missing is the handling of selecting the packages to install. The
-	# loop below needs to be rewritten.
 
 	# If the package directory doesn't exist, we're done.
 	if [ ! -d ${NANO_PACKAGE_DIR} ]; then

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Nov 8 23:40:00 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173482 
State-Changed-From-To: open->closed 
State-Changed-By: n_hibma 
State-Changed-When: Sun Apr 28 22:13:21 UTC 2013 
State-Changed-Why:  
Committed in 250036. 

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