misc/136889: nanobsd error reporting and other refinements

Aragon Gouveia aragon at phat.za.net
Sat Jul 18 18:20:02 UTC 2009


>Number:         136889
>Category:       misc
>Synopsis:       nanobsd error reporting and other refinements
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 18 18:20:01 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Aragon Gouveia
>Release:        8.0-BETA1
>Organization:
>Environment:
FreeBSD fuzz.geek.sh 8.0-BETA1 FreeBSD 8.0-BETA1 #7: Thu Jul  9 03:27:47 UTC 2009     root at fuzz.geek.sh:/usr/obj/usr/src/sys/FUZZ  amd64
>Description:
I've attached a patch which improves or fixes a few things in the nanobsd build script.

1.  There is an error in create_i386_diskimage in that the routine sets traps to unmount and unallocate the filesystems and md devices it creates, but it doesn't clear the traps before the routine exits.  This causes the nanobsd script to halt (due to set -e) and one never sees the completion message at the end.

2.  set -e is called at the start of the script which causes any errors to terminate execution immediately.  There is no message to show that an error occurred so it is quite easy to run nanobsd and think it ran to completion because it just exits silently.  Meanwhile you end up taking a stale disk image to your device.  I've added a routine to check $? and a trap that calls this routine on EXIT.

3.  prune_usr has an annoying side effect in that while deleting all empty directories in /usr, it also deletes /usr/lib/aout.  With /usr/lib/aout missing, ldconfig generates an error during bootup.  I've modified prune_usr to skip any directories named "aout".

4.  Added NANO_BOOT2CFG variable for adjusting the flags set in /boot.config.  Default is still " -h".

4.  Added NANO_IMAGE_MBRONLY and set it true by default.  When true and when NANO_MD_BACKING is set to "swap", nanobsd will not write out an entire disk image to file.  Instead it will just write the MBR and the code partition image to files.  I added this to make new nanobsd builds quicker and easier as one rarely needs to write an entire disk image after the slices and filesystems are already setup, and with 2 GB or larger flash cards being the norm, writing an entire disk image is heavy.

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- /usr/src/tools/tools/nanobsd/nanobsd.sh	2009-07-12 19:06:20.000000000 +0200
+++ nanobsd.sh	2009-07-18 01:10:45.000000000 +0200
@@ -124,10 +124,17 @@
 NANO_BOOT0CFG="-o packet -s 1 -m 3"
 NANO_BOOTLOADER="boot/boot0sio"
 
+# boot2 flags/options
+# default force serial console
+NANO_BOOT2CFG=" -h"
+
 # Backing type of md(4) device
 # Can be "file" or "swap"
 NANO_MD_BACKING="file"
 
+# for swap type md(4) backing, write out the mbr only
+NANO_IMAGE_MBRONLY=true
+
 # Progress Print level
 PPLEVEL=3
 
@@ -143,6 +150,13 @@
 #
 #######################################################################
 
+nano_cleanup() {
+	if [ $? -ne 0 ]; then
+		echo "Error encountered.  Check for errors in last log file." 1>&2
+	fi
+	exit $?
+}
+
 clean_build ( ) (
 	pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
 
@@ -344,7 +358,7 @@
 prune_usr() (
 
 	# Remove all empty directories in /usr 
-	find ${NANO_WORLDDIR}/usr -type d -depth -print |
+	find ${NANO_WORLDDIR}/usr -type d -depth -not -name aout -print |
 		while read d
 		do
 			rmdir $d > /dev/null 2>&1 || true 
@@ -485,13 +499,20 @@
 	fi
 
 	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
-		echo "Writing out ${NANO_IMGNAME}..."
-		dd if=/dev/${MD} of=${IMG} bs=64k
+		if [ ${NANO_IMAGE_MBRONLY} ]; then
+			echo "Writing out _.disk.mbr..."
+			dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1
+		else
+			echo "Writing out ${NANO_IMGNAME}..."
+			dd if=/dev/${MD} of=${IMG} bs=64k
+		fi
 	fi
 
 	echo "Writing out _.disk.image..."
 	dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
 	mdconfig -d -u $MD
+	trap - 1 2 15
+	trap "nano_cleanup" EXIT
 	) > ${NANO_OBJ}/_.di 2>&1
 )
 
@@ -571,8 +592,7 @@
 	# Disable getty on syscons devices
 	sed -i "" -e '/^ttyv[0-8]/s/	on/	off/' ${NANO_WORLDDIR}/etc/ttys
 
-	# Tell loader to use serial console early.
-	echo " -h" > ${NANO_WORLDDIR}/boot.config
+	echo ${NANO_BOOT2CFG} > ${NANO_WORLDDIR}/boot.config
 )
 
 #######################################################################
@@ -677,7 +697,7 @@
 	echo "	-i	suppress disk image build"
 	echo "	-k	suppress buildkernel"
 	echo "	-n	add -DNO_CLEAN to buildworld, buildkernel, etc"
-	echo "	-q	make output more quite"
+	echo "	-q	make output quieter"
 	echo "	-v	make output more verbose"
 	echo "	-w	suppress buildworld"
 	echo "	-c	specify config file"
@@ -754,6 +774,8 @@
 	usage
 fi
 
+trap "nano_cleanup" EXIT
+
 #######################################################################
 # Setup and Export Internal variables
 #


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list