From owner-freebsd-bugs@FreeBSD.ORG Fri Apr 23 00:30:04 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 887F11065676 for ; Fri, 23 Apr 2010 00:30:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 6652C8FC24 for ; Fri, 23 Apr 2010 00:30:04 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o3N0U44T095808 for ; Fri, 23 Apr 2010 00:30:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o3N0U4uv095804; Fri, 23 Apr 2010 00:30:04 GMT (envelope-from gnats) Resent-Date: Fri, 23 Apr 2010 00:30:04 GMT Resent-Message-Id: <201004230030.o3N0U4uv095804@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Aragon Gouveia Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CD3271065676 for ; 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 ; 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 ; 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" To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: misc/145961: [nanobsd] improved flash update script X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Aragon Gouveia List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2010 00:30:04 -0000 >Number: 145961 >Category: misc >Synopsis: [nanobsd] improved flash update script >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Apr 23 00:30:03 UTC 2010 >Closed-Date: >Last-Modified: >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: >Unformatted: