Date: Fri, 14 Nov 2008 14:12:17 +0100 From: Luigi Rizzo <rizzo@iet.unipi.it> To: hackers@freebsd.org Subject: convert bootable freebsd iso to bootable flash image Message-ID: <20081114131217.GA62275@onelab2.iet.unipi.it>
next in thread | raw e-mail | index | archive | help
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 --------------------------------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20081114131217.GA62275>