misc/145961: [nanobsd] improved flash update script

Aragon Gouveia aragon at phat.za.net
Fri Apr 23 00:30:04 UTC 2010

>Number:         145961
>Category:       misc
>Synopsis:       [nanobsd] improved flash update script
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 23 00:30:03 UTC 2010
>Originator:     Aragon Gouveia
>Release:        FreeBSD 8.0-STABLE amd64
System: FreeBSD igor.geek.sh 8.0-STABLE FreeBSD 8.0-STABLE #0: Mon Mar 8 01:27:41 SAST 2010 toor at igor.geek.sh:/usr/obj/usr/src/sys/IGOR amd64

	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.


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

set -e

. /etc/nanobsd.conf

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

case ${ACTIVE} in
	echo "Unknown system state.  Aborting upgrade..." 1>&2
	exit 1

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 "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

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


More information about the freebsd-bugs mailing list