NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: how to create a disk image? (shark; disklabel + / + swap)



Am 13.12.2008 um Sa, 13. 12 2008, 19:51 schrieb Hubert Feyrer:
Like this? (though I'm not a sh(1) expert)

Woah, that looks pretty good - thanks a lot! (I'll need a bit more time to play with it, but reading through it made a few things clear.


OK, with some fiddling and changing, I've adjusted the script to give me a bootable disk image for my shark. It should also still work on i386, but I cannot test this (qemu doesn't build on netbsd-5, and I didn't get Parallels to accept the disk as image). The script's appended below, it's based heavily on your script.

Things I've learned by the script, and also by using hexdump(1) on various disk images and disk labels:

 * a MS-DOS MBR is 512 bytes (boring)
* a BSD disklabel is some 300-400 bytes, apparently not really fixed in size. the interesting part: if you create a BSD disk label on a image, the first 512 bytes
   are left alone. good to put an MBR in!
* when you have a FFS file system image (e.g. created with mkfile), the actual file system data only starts at byte 8192 - that's plenty of space to put a BSD disk label in there. Oh, and a
   MBR, too, if needed! :-)

So in effect, at least for the shark, you can start your root (wd0a) partition on sector 0, as the file system's structure will still allow a BSD disk label to be present there. The MBR is not needed on a shark - just make sure the /netbsd is in a.out format. (XXX this should be moved into customize-shark.sh in the script below).


  - Hubert


#! /bin/sh
#
# Create bootable NetBSD/${MACHINE} disk image
#
# Usage: sh mkdisk-arm.sh shark
#        sh mkdisk-arm.sh i386
#

if [ "$1" = "" ]; then
        # Try to guess from $0:
        #
        m=`expr "$0" : ".*-\(.*\).sh"`
        if [ "$m" != "" ]; then
                MACHINE=$m
        else
                MACHINE=i386            # default
        fi
else
        MACHINE=${1}
fi


BASE=/usr/cvs/src-5/obj.${MACHINE}
TOOLDIR=${BASE}/tooldir
DESTDIR=${BASE}/destdir

# Remote build:
#FTPHOST=ftp.NetBSD.org
#RELEASEDIR=pub/NetBSD/NetBSD-4.0.1
#DLDIR=./dl
#
# Local build:
DLDIR=${BASE}/releasedir/${MACHINE}/binary/sets

# Partition sizes, in MB
IMAGEMB=1024
SWAPMB=128

# Start sector of the root file system:
LABELSECTORS_shark=0            # shark
LABELSECTORS_i386=63            # historical (i386)
eval "LABELSECTORS=\${LABELSECTORS_${MACHINE}}"

######################################################################## ###
# No changes from here!

# Working directory where everything is built - can be nuked safely
obj=./obj.${MACHINE}

# Script with local customization commands,
# can assume unpacked file system in .
customize=customize-${MACHINE}.sh

# Partition sizes, in sectors
IMAGESECTORS=`expr ${IMAGEMB} \* 1024 \* 1024 / 512`
SWAPSECTORS=`expr ${SWAPMB} \* 1024 \* 1024 / 512`
#
BSDPARTSECTORS=`expr ${IMAGESECTORS} - ${LABELSECTORS}`
FSSECTORS=`expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}`
FSOFFSET=${LABELSECTORS}
SWAPOFFSET=`expr ${LABELSECTORS} + ${FSSECTORS}`
FSMINSIZE=`expr ${FSSECTORS} \* 512`

echo Creating a bootable NetBSD/${MACHINE} disk image in ${MACHINE}.img:

if [ ! -d ${TOOLDIR} ]; then
        echo 'set TOOLDIR first'; exit 1
fi
if [ ! -x ${TOOLDIR}/bin/nbdisklabel-${MACHINE} ]; then
        echo 'build tools first'; exit 1
fi
if [ "${LABELSECTORS}" = "" ]; then
        echo 'set LABELSECTORS first'; exit 1
fi

echo Verifying downloads ...
for f in kern-GENERIC.tgz base.tgz etc.tgz
do
        if [ ! -f ${DLDIR}/${f} ]
        then
                mkdir -p ${DLDIR}
ftp -o ${DLDIR}/${f} ftp://${FTPHOST}/${RELEASEDIR}/${MACHINE}/ binary/sets/${f}
        fi
done

echo Extracting into targetroot ...
if [ ! -d $obj/targetroot ]
then
        mkdir -p $obj/targetroot
        
        # XXX ${MACHINE} specific
        tar -C $obj/targetroot -zxf ${DLDIR}/kern-GENERIC.tgz
        tar -C $obj/targetroot -zxf ${DLDIR}/base.tgz
        tar -C $obj/targetroot -zxf ${DLDIR}/etc.tgz
        
        # XXX ${MACHINE} == shark specific
        # XXX should be moved to customize-shark.sh (== $customize)
        if [ -f $obj/targetroot/netbsd.aout ]; then
                rm $obj/targetroot/netbsd
                ln $obj/targetroot/netbsd.aout targetroot/netbsd
        fi
        
        if [ -f $obj/targetroot/usr/mdec/boot ]
        then
                cp $obj/targetroot/usr/mdec/boot $obj/targetroot
        fi
        
        # XXX /var/spool/ftp/hidden is unreadable
        chmod u+r $obj/targetroot/var/spool/ftp/hidden
fi

echo Preparing mtree files ...
cat $obj/targetroot/etc/mtree/* > $obj/spec
sh $obj/targetroot/dev/MAKEDEV -s all | \
        sed -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> $obj/spec

echo -n Customizing via $customize ...
if [ -f $customize ]
then
        echo ""
        cat $customize \
        | ( cd $obj/targetroot ; sh 2>&1 ) \
        | sed 's,^,> ,'
        echo Customizing done.
else
    echo " not present (that's fine!)"
fi
        
echo Creating root file system in target.fs ...
${TOOLDIR}/bin/nbmakefs \
        -N ${DESTDIR}/etc \
        -M ${FSMINSIZE} \
        -F $obj/spec \
        $obj/target.fs $obj/targetroot

echo -n Preparing disk label
cat > $obj/label <<EOF
type: ESDI
disk: image
label:
flags:
bytes/sector: 512
sectors/track: 32
tracks/cylinder: 64
sectors/cylinder: 2048
cylinders: 1024
total sectors: ${IMAGESECTORS}
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

8 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
a:    ${FSSECTORS} ${FSOFFSET} 4.2BSD 1024 8192 16
b:    ${SWAPSECTORS} ${SWAPOFFSET} swap
c:    ${BSDPARTSECTORS} ${FSOFFSET} unused 0 0
d:    ${IMAGESECTORS} 0 unused 0 0
EOF
if [ ${LABELSECTORS} -gt 0 ]
then
        # Create extra label
        #
        # XXX for i386, it may be good to add a MBR as the first 512 bytes
        # of the disk label (take from usr/mdec/mbr) - HF
        #
        echo " (in extra file, label.fs) ..."
        dd if=/dev/zero of=$obj/label.fs count=${LABELSECTORS}
        ${TOOLDIR}/bin/nbdisklabel-${MACHINE} -R -F $obj/label.fs $obj/label
        cat $obj/label.fs $obj/target.fs > ${MACHINE}.img
else
        # Put label in front of file system
        echo " (adding at front of target.fs) ..."
        ${TOOLDIR}/bin/nbdisklabel-${MACHINE} -R -F $obj/target.fs $obj/label
        mv $obj/target.fs ${MACHINE}.img
fi

# XXX ${MACHINE} == i386 specific
if [ -f $obj/targetroot/usr/mdec/bootxx_ffsv1 ]
then
        echo Installing boot block ...
        ${TOOLDIR}/bin/nbinstallboot -vm ${MACHINE} ${MACHINE}.img \
                $obj/targetroot/usr/mdec/bootxx_ffsv1
fi

echo Cleaning up ...
#rm -rf $obj

echo Done:
ls -la ${MACHINE}.img

#echo Testing ...
#
# NetBSD:
# qemu -hda ${MACHINE}.img -boot c
#
# Mac OS X:
# dd bs=10m if=shark.img of=/dev/rdisk4

Attachment: PGP.sig
Description: Signierter Teil der Nachricht



Home | Main Index | Thread Index | Old Index