From aragon@phat.za.net  Fri Apr 23 00:24:43 2010
Return-Path: <aragon@phat.za.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id CD3271065676
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Apr 2010 00:24:43 +0000 (UTC)
	(envelope-from aragon@phat.za.net)
Received: from mail.geek.sh (decoder.geek.sh [196.36.198.81])
	by mx1.freebsd.org (Postfix) with ESMTP id 3F27D8FC1B
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Apr 2010 00:24:43 +0000 (UTC)
Received: from phat.za.net (196-209-37-82-ndn-esr-3.dynamic.isadsl.co.za [196.209.37.82])
	by mail.geek.sh (Postfix) with ESMTPA id 1DABE3D0C9
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Apr 2010 02:24:40 +0200 (SAST)
Received: by phat.za.net (sSMTP sendmail emulation); Fri, 23 Apr 2010 02:24:39 +0200
Message-Id: <20100423002440.1DABE3D0C9@mail.geek.sh>
Date: Fri, 23 Apr 2010 02:24:39 +0200
From: "Aragon Gouveia" <aragon@phat.za.net>
Reply-To: Aragon Gouveia <aragon@phat.za.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [nanobsd] improved flash update script
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         145961
>Category:       misc
>Synopsis:       [patch] [nanobsd] improved flash update script
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 23 00:30:03 UTC 2010
>Closed-Date:    Fri May 13 13:47:21 MDT 2011
>Last-Modified:  Fri May 13 13:47:21 MDT 2011
>Originator:     Aragon Gouveia
>Release:        FreeBSD 8.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD igor.geek.sh 8.0-STABLE FreeBSD 8.0-STABLE #0: Mon Mar 8 01:27:41 SAST 2010 toor@igor.geek.sh:/usr/obj/usr/src/sys/IGOR amd64


	
>Description:
	NanoBSD has some utility shell scripts called updatep1 and updatep2 which help upgrade system flash with a new image file and make it bootable.  These scripts still use fdisk and boot0cfg which seems to be error prone on FreeBSD 8.0, causing vfs errors after an update.

	I've attached a single update script which auto detects which partition is active and upgrades the inactive partition.  It also uses gpart for making the new partition bootable.
>How-To-Repeat:
	
>Fix:

	

--- update begins here ---
#!/bin/sh
# usage:
#	ssh somewhere cat image.s1 | sh update
#

set -e

. /etc/nanobsd.conf

ACTIVE=0
if mount |grep -q ^/dev/${NANO_DRIVE}s1; then
	ACTIVE=1
fi
if mount |grep -q ^/dev/${NANO_DRIVE}s2; then
	ACTIVE=$(( ${ACTIVE} + 2 ))
fi

case ${ACTIVE} in
1)
	UPDATE=2
	;;
2)
	UPDATE=1
	;;
*)
	echo "Unknown system state.  Aborting upgrade..." 1>&2
	exit 1
	;;
esac

echo "Partition ${ACTIVE} active, updating partition ${UPDATE}..."

# Blow away old system.
dd if=/dev/zero of=/dev/${NANO_DRIVE}s${UPDATE} bs=1m count=1 > /dev/null 2>&1

# Copy in new system
dd of=/dev/${NANO_DRIVE}s${UPDATE} obs=128k

# Check that it worked
fsck_ffs -n /dev/${NANO_DRIVE}s${UPDATE}a

echo
echo "Image data written successfully.  Activating..."

if [ ${UPDATE} -eq 2 ]; then
	# Update the /etc/fstab
	trap "umount /mnt" 1 2 3 15 EXIT
	mount /dev/${NANO_DRIVE}s2a /mnt
	sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/conf/base/etc/fstab
	sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/" /mnt/etc/fstab
	umount /mnt
	trap - 1 2 3 15 EXIT
fi

gpart set -a active -i ${UPDATE} ${NANO_DRIVE}
--- update ends here ---


>Release-Note:
>Audit-Trail:

From: Aragon Gouveia <aragon@phat.za.net>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/145961: [nanobsd] improved flash update script
Date: Fri, 23 Apr 2010 02:42:28 +0200

 If this script is accepted, please note PR misc/144553 can be closed too.
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Fri May 13 13:46:32 MDT 2011 
State-Changed-Why:  
Similar functionality has been adapoted.  Should be OK to close. 
Please let me know if I've overlooked something. 


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