From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 3 15:50:06 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C17A4106566C; Thu, 3 Sep 2009 15:50:06 +0000 (UTC) (envelope-from faust64@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.158]) by mx1.freebsd.org (Postfix) with ESMTP id F0F7C8FC0C; Thu, 3 Sep 2009 15:50:05 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id 16so738123fgg.13 for ; Thu, 03 Sep 2009 08:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type; bh=HK6eTgIdnbebMlIhf027ur9TaSEJ5wWMDhM4Hi/rtPo=; b=n/pawIFx3ZZwatK/1hTgUKkD1O+RC+RUFLhILXu5sqMJzsaflfYVWTqzS23a+cZJe8 zMPrKuUbwmph6A/kLBroPKTOq6YTrpEb2KW641BmNP4s7AKZGtFNNXrAdbi0gUL91MsS SaprWbMzai2gBpks7uU2YSkgDM+5TIo+dUJE4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=A6QnsYMj7uX9bKkteuz6q46AWyAQLjv89H030dnd/VZp4M0CtGKIHXHcptkNegSpQJ nzBB5syfuvogmbvzOS28boZjciJF4sTw8XSWyacy5scSE7tem7QzYPfODa+FKmnSZTqr 3iKtWKSovS5oS6d6RdzPRf8XD0ZwxbhAeVRyE= MIME-Version: 1.0 Received: by 10.86.13.37 with SMTP id 37mr4061525fgm.58.1251993005102; Thu, 03 Sep 2009 08:50:05 -0700 (PDT) In-Reply-To: References: From: =?ISO-8859-1?Q?Samuel_Mart=EDn_Moro?= Date: Thu, 3 Sep 2009 17:49:45 +0200 Message-ID: To: freebsd-questions@freebsd.org, freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Re: Making bootable USB keys 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: Thu, 03 Sep 2009 15:50:06 -0000 hello. again. btw: my .img file is 0-filled in its 512 first bytes... i downloaded the 8-0-BETA3-???.img, it starts with EB3C. and I think each .img file start like that, right ? thanks Samuel Mart=EDn Moro CamTrace {EPITECH.} tek4 On Thu, Sep 3, 2009 at 5:35 PM, Samuel Mart=EDn Moro wro= te: > > Hello > > I'm having some troubles, trying to create bootable USB keys. > I found (freebsd-hackers ML archives) a script, supposed to create the > bootable image from my iso file. > But, it still don't boot... (I may do it wrong) > > In details: > -We distribute a FreeBSD (4.7, 5.4, 6.2 and 7.2) "custom" server. > -We burn our install CD (and, in a few, our USB sticks) on a Ferdora 9 > (sorry...) > -USB sticks must contain a FAT32 partition (we'ld like to provide doc for > windows users) > > Well, my english isn't so great... so I'll post my code (more > understandable) > > --maker.sh-- > #!/bin/sh > ISO_DIR=3D/r00t > ISO_PFIX=3Dr00t > VERSION=3D5.9.3.0 > ISO_FILE=3D$ISO_DIR/$ISO_PFIX-$VERSION.img > DEVICE=3D > TMPDOC=3D/mnt/tmpdoc > DOCDIR=3D/root/samuel/docdir > ERR=3D > SFX=3D > MBR=3D/root/samuel/mbr > BT1=3D/root/samuel/boot1 > BT2=3D/root/samuel/boot2 > > if [ -e "$1" ]; then > DEVICE=3D$1 > elif [ "$1" -a -e "/dev/$1" ]; then > DEVICE=3D/dev/$1 > elif [ "$1" ]; then > echo "$0: incorrect device specified" >&2 > exit > else > echo "$0: must specify device" >&2 > exit > fi > for i in `mount | cut -d ' ' -f 1` > do > if [ "`echo $i | grep $DEVICE`" ]; then > echo "$0: $i already mounted" >&2 > echo " umount it manually or choose an other drive" >&2 > exit > fi > done > > if [ -e "$TMPDOC" -a -d "$TMPDOC" ]; then > echo "$0: removing $TMPDOC directory" >&2 > rm -rf $TMPDOC > elif [ -e "$TMPDOC" ]; then > mv $TMPDOC $TMPDOC.old > echo "$0: moved $TMPDOC to $TMPDOC.old" >&2 > fi > mkdir $TMPDOC > > if [ "$2" ]; then > echo $2 | grep "\.img$" >/dev/null || SFX=3D".img" > fi > > if [ -e "$2$SFX" ]; then > ISO_FILE=3D$2$SFX > elif [ "$2" -a -e "$ISO_DIR/$2$SFX" ]; then > ISO_FILE=3D$ISO_DIR/$2 > elif [ "$2" -a -e "$ISO_DIR/$ISO_PFIX-$2$SFX" ]; then > ISO_FILE=3D"$ISO_DIR/$ISO_PFX-$2$SFX" > else > echo "$0: will use default file \`$ISO_FILE'" >&2 > echo " as system image source" >&2 > fi > if [ -e "$ISO_FILE" ]; then > MSize=3D`ls -l $ISO_FILE | awk '{print $5}'` > else > echo "$0: $ISO_FILE doesn't exist!" >&2 > rm -rf $TMPDOC > exit > fi > if [ -z "$MSize" -o "$MSize" -lt 1 ]; then > echo "$0: bad image size (size=3D$MSize)" >&2 > rm -rf $TMPDOC > exit > fi > > while : > do > echo " [ Working on $DEVICE ]" > > echo -n " determining device geometry " > infos=3D`fdisk -l $DEVICE 2>/dev/null | grep "[0-9]* heads"` > ident=3D`fdisk -l $DEVICE 2>/dev/null | awk '/Disk identifier/{print > $3}'` > csz=3D`fdisk -l $DEVICE 2>/dev/null | awk '/Units =3D cylinders /{pri= nt > $7}'` > eval `echo $infos | awk '{print "hpc=3D" $1 " sec=3D" $3 " cyl=3D" $5= }'` > if [ -z "$hpc" -o -z "$sec" -o -z "$cyl" -o -z "$csz" ]; then > echo " [ FAIL ]" > echo "$0: can't get infos for device $DEVICE" >&2 > rm -rf $TMPDOC > exit > fi > echo " [ OK ]" > > echo -n " initializing partition table " > # dd if=3D/dev/zero of=3D$DEVICE bs=3D$csz count=3D1 >/dev/null 2>&1 > dd if=3D$BT1 of=3D$DEVICE >/dev/null 2>&1 > round=3D128 > tocyl=3D`expr $hpc '*' $sec '*' $csz` > ret=3D`expr $MSize % $tocyl` > MSize=3D`expr $MSize / $tocyl` > test "$ret" -eq "0" || MSize=3D`expr $MSize + 1` > s2len=3D$MSize > s2off=3D`expr $cyl - $s2len - 1` > s1len=3D`expr $s2off - 1` > s1off=3D1 > sfdisk -DLqf $DEVICE >/dev/null 2>&1 < $s1off $s1len b > $s2off $s2len a5 * > EOF > echo " [ OK ]" > > echo -n " formatting FAT32 partition " > dd if=3D/dev/zero of=3D${DEVICE}1 bs=3D$csz count=3D1 >/dev/null 2>&1 > mkdosfs -i 42424242 -n "Docs" -F 32 ${DEVICE}1 >/dev/null 2>&1 > mount -t vfat ${DEVICE}1 $TMPDOC || ERR=3D1 > if [ "$ERR" ]; then > echo " [ FAIL ]" > echo "$0: unable to mount ${DEVICE}1 on $TMPDOC" > rm -rf $TMPDOC > exit > fi > echo " [ OK ]" > > echo -n " copying documentation files " > cp -rp $DOCDIR/* $TMPDOC/ >/dev/null 2>&1 || ERR=3D2 > if [ "$ERR" ]; then > echo " [ FAIL ]" > echo "$0: unable to copy doc files" > ERR=3D > fi > umount ${DEVICE}1 > echo " [ OK ]" > > echo -n " copying system " > dd if=3D$ISO_FILE of=3D${DEVICE}2 status=3Dnoxfer >/dev/null 2>&1 > echo " [ OK ]" > > mbrsig $DEVICE 2>&1 | awk '{print " marking device with serial " $= 3 > }' > echo " [ Device ready! ]" > echo "" > echo -n " Create new USB key ? [Y/N] : " && read i > test "$i" =3D "Y" -o "$i" =3D "y" -o "$i" =3D "O" -o "$i" =3D "o" || = i=3D > test -z "$i" && echo " [ leaving ]" && break > echo " Please, remove current USB key, insert new one and press enter= " > read i > done > rmdir $TMPDOC > --EOF-- > > So, this is a "USB stick generator" I'm working on. > It seems to work. (I've not tested everything, but the basis is OK) > The stick is correctly parted. > The documentation is copied. > My only problem is that it still don't wan't to boot... > > At the beginning, I was trying to paste my ISO file directly in ${DEVICE}= 2 > Then, I found the following shell script, which is supposed to make my > bootable image from my ISO file > I changed 2/3 things, but some of you may recognize it anyway: > > --ISOtoIMG.sh-- > #!/bin/sh > MAKEFS=3Dmakefs > MKLABEL=3Dbsdlabel > BSDTAR=3Dtar > DD=3D"dd status=3Dnoxfer" > > make_freebsd_image() > { > local tree=3D$1 > local imagefile=3D$2 > local boot1=3D${tree}/boot/boot1 > local boot2=3D${tree}/boot/boot2 > > echo "convert tree $tree image $imagefile" > ${MAKEFS} -t ffs -o bsize=3D4096 -o fsize=3D512 -f 50 ${imagefile} ${tr= ee} > >/dev/null 2>&1 > ${MKLABEL} -w -f ${imagefile} auto >/dev/null 2>&1 > ${MKLABEL} -f ${imagefile} 2>/dev/null | sed -e '/ c:/{p;s/c:/a:/;}' | = \ > ${MKLABEL} -R -f ${imagefile} /dev/stdin >/dev/null 2>&1 > ${DD} if=3D${boot1} of=3D${imagefile} conv=3Dnotrunc >/dev/null 2>&1 > ${DD} if=3D${boot2} iseek=3D1 ibs=3D276 2>/dev/null | \ > ${DD} of=3D${imagefile} oseek=3D1 obs=3D788 conv=3Dnotrunc >/dev/null 2= >&1 > } > > extract_image() > { > [ -f $1 ] || return > local tmp=3D"${tree}.tree" > [ -e ${tmp} ] && rm -rf ${tmp} > mkdir -p $tmp > echo "extracting $tree in $tmp" > (cd $tmp && ${BSDTAR} xf $tree) > tree=3D$tmp > } > > if [ -z "$1" ]; then > echo "$0: usage" >&2 > echo " $0 {ISO_input} | {system_root IMG_output}" >&2 > exit > fi > tree=3D`realpath $1` > [ "$2" ] && image=3D`realpath $2` || image=3D`echo $tree | sed "s/.iso/.i= mg/"` > extract_image $tree > make_freebsd_image $tree $image > [ -d "$tmp" ] && (chmod -R +w $tmp && rm -rf $tmp) > --EOF-- > > This seems to work, too... > I'm just surprised: > root@granit:~/samuel# l -h /r00t/r00t-5.9.3.0* > -rw-r--r-- 1 root root 566M 2009-09-03 15:29 /r00t/r00t-5.9.3.0.img > -rw-r--r-- 1 root root 526M 2009-08-08 06:58 /r00t/r00t-5.9.3.0.iso > new file is 40M heavier than our iso image... > > Also, in the first script, I tried to do the first dd (initializing > ${DEVICE}) with: > - if=3D$MBR > - if=3D$BT1 > - if=3D$BT2 > - if=3D/dev/zero > none of that worked... > > So. > Does someone understand what am I doing wrong?! > > > Thanks for you help! > > Samuel Mart=EDn Moro > CamTrace > {EPITECH.} tek4 > >