Date: Thu, 3 Sep 2009 12:19:57 -0400 From: Dimitri Yioulos <dyioulos@firstbhph.com> To: freebsd-questions@freebsd.org Subject: Re: Making bootable USB keys Message-ID: <200909031219.57856.dyioulos@firstbhph.com> In-Reply-To: <ce5f79aa0909030835k1a69c33ay3f7b4bb23e4c857c@mail.gmail.com> References: <ce5f79aa0909030835k1a69c33ay3f7b4bb23e4c857c@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday 03 September 2009 11:35:34 am Samuel=20 Mart=EDn Moro wrote: > 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 /{print $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 <<EOF > $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 "=20=20=20 > 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} ${tree} > > >/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/.img/"` 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 > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freeb >sd-questions To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" Might want to try UNetbootin. Dimitri --=20 This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909031219.57856.dyioulos>