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)



hubert%feyrer.de@localhost wrote:

> Is there some easy way to automate this (e.g. size calculations for the 
> disklabel/partitions)?

Like this? (though I'm not a sh(1) expert)

---
#! /bin/sh
MACHINE=i386
MACHINE_ARCH=i386

TOOLDIR=/path/to/your/tooldir
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

FTPHOST=ftp.NetBSD.org
RELEASEDIR=pub/NetBSD/NetBSD-4.0.1
LABELSECTORS=63                 # historical
IMAGESECTORS=2097152            # 1024MB
SWAPSECTORS=262144              # 128MB

BSDPARTSECTORS=`expr ${IMAGESECTORS} - ${LABELSECTORS}`
FSSECTORS=`expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}`
FSOFFSET=${LABELSECTORS}
SWAPOFFSET=`expr ${LABELSECTORS} + ${FSSECTORS}`
FSSIZE=`expr ${FSSECTORS} \* 512`
ftp ftp://${FTPHOST}/${RELEASEDIR}/${MACHINE}/binary/sets/kern-GENERIC.tgz
ftp ftp://${FTPHOST}/${RELEASEDIR}/${MACHINE}/binary/sets/base.tgz
ftp ftp://${FTPHOST}/${RELEASEDIR}/${MACHINE}/binary/sets/etc.tgz
mkdir -p targetroot
# XXX ${MACHINE} specific
tar -C targetroot -zxf kern-GENERIC.tgz
tar -C targetroot -zxf base.tgz
tar -C targetroot -zxf etc.tgz
cp targetroot/usr/mdec/boot targetroot
# XXX /var/spool/ftp/hidden is unreadable
chmod u+r targetroot/var/spool/ftp/hidden
cat targetroot/etc/mtree/* > spec
sh targetroot/dev/MAKEDEV -s all | \
        sed -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> spec
makefs -M ${FSSIZE} -F spec target.fs targetroot
dd if=/dev/zero of=label.fs count=${LABELSECTORS}
cat > 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

${TOOLDIR}/bin/nbdisklabel-${MACHINE} -R -F label.fs label
cat label.fs target.fs > ${MACHINE}.img
# XXX ${MACHINE} specific
${TOOLDIR}/bin/nbinstallboot -vm ${MACHINE} ${MACHINE}.img \
        targetroot/usr/mdec/bootxx_ffsv1

qemu -hda ${MACHINE}.img -boot c
---
Izumi Tsutsui


Home | Main Index | Thread Index | Old Index