From owner-freebsd-hackers@FreeBSD.ORG Fri Nov 14 13:25:25 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 59CC8106567A for ; Fri, 14 Nov 2008 13:25:25 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.9.129]) by mx1.freebsd.org (Postfix) with ESMTP id 1FF828FC14 for ; Fri, 14 Nov 2008 13:25:25 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id D5CC9730A1; Fri, 14 Nov 2008 14:12:17 +0100 (CET) Date: Fri, 14 Nov 2008 14:12:17 +0100 From: Luigi Rizzo To: hackers@freebsd.org Message-ID: <20081114131217.GA62275@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Cc: Subject: convert bootable freebsd iso to bootable flash image X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Nov 2008 13:25:25 -0000 Just in case people have a similar need, or can point me to better code to do the same job: i needed to convert a bootable FreeBSD iso image into a bootable flash image, and have come up with the following code (derived from PicoBSD). The nice part is that this is all done without requiring root permissions -- the iso extraction is done with bsdtar, the file system is created using makefs, and the other patching is done with bsdlabel and dd. Now i need to find something similar to convert a bootable linux image and a bootable DOS image :) cheers luigi ----------- cut here -------------------------------- #!/bin/sh # convert a FreeBSD iso to flash image # # based on picobsd tricks. # requires makefs, bsdlabel, bsdtar, sed and dd MAKEFS=makefs MKLABEL=bsdlabel BSDTAR=tar make_freebsd_image() { # tree imagefile local tree=$1 local imagefile=$2 local boot1=${tree}/boot/boot1 local boot2=${tree}/boot/boot2 echo "convert tree $tree image $img" ${MAKEFS} -t ffs -o bsize=4096 -o fsize=512 \ -f 50 ${imagefile} ${tree} ${MKLABEL} -w -f ${imagefile} auto # write a label # copy partition c: into a: with some sed magic ${MKLABEL} -f ${imagefile} | sed -e '/ c:/{p;s/c:/a:/;}' | \ ${MKLABEL} -R -f ${imagefile} /dev/stdin # dump the primary and secondary boot (primary is 512 bytes) dd if=${boot1} of=${imagefile} conv=notrunc 2>/dev/null # XXX secondary starts after the 0x114 = dec 276 bytes of the label # so we skip 276 from the source, and 276+512=788 from dst # the old style blocks used 512 and 1024 respectively dd if=${boot2} iseek=1 ibs=276 2> /dev/null | \ dd of=${imagefile} oseek=1 obs=788 conv=notrunc 2>/dev/null } tree=$1 image=$2 if [ -f $1 ] ; then echo "Extract files from ${image}" tmp="${image}.tree" mkdir -p $tmp (cd $tmp && ${BSDTAR} xf $tree) tree=$tmp fi make_freebsd_image $tree $image [ -d "$tmp" ] && (chmod -R +w $tmp && rm -rf $tmp) #------ end of fil --------------------------------