Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!news.hawaii.edu!ames!agate!howland.reston.ans.net!vixen.cso.uiuc.edu!newsfeed.internetmci.com!news.sprintlink.net!news.sysnet.net!usenet
From: warbird@laser.net (Matthew Patton)
Newsgroups: comp.unix.bsd.netbsd.misc
Subject: semi-intelligent disk format tool
Date: 10 Dec 1995 06:40:11 GMT
Organization: Defense Information Systems Agency
Lines: 463
Message-ID: <4advcb$ab6@unix2.sysnet.net>
Reply-To: patton@sysnet.net (Matthew Patton)
NNTP-Posting-Host: ppp4.sysnet.net
X-Newsreader: IBM NewsReader/2 v1.2
I am really disappointed in the continued lack of a simple tool to facilitate the
labeling of disks under NetBSD (at least on i386). Something like Sun's 'format'
command would be SO INCREDIBLY nice. For the /etc/disktab challenged like myself
I made some modifications to the default install script so that one can almost
painlessly label/partition additional disks. The file is included below for public use.
It is UNOFFICIAL software and should be used with care. Comments/suggestions
are welcome at patton@sysnet.net or pattonme@gnpr.pae.osd.mil.
#!/bin/sh
# NetBSD disk formatting script.
# Matthew Patton 12/8/95
DT=/etc/disktab # /etc/disktab
FSTABDIR=/etc # /mnt/etc
#DONTDOIT=echo
VERSION=1.1a
FSTAB=${FSTABDIR}/fstab
getresp() {
read resp
if [ "X$resp" = "X" ]; then
resp=$1
fi
}
echo "Welcome to the _UNOFFICIAL_ NetBSD ${VERSION} disk format program."
echo "It is a modified version of the release 'install' script for those "
echo "of us who have not mastered the particular details of hand-"
echo "constructing /etc/disktab files. I have tried to make it use safe "
echo "assumptions but be forewarned that serious damage could result."
echo "Unlike the 'install' script, this one supports root and swap "
echo "partitions of size 0. I highly recommend that you uncomment the "
echo "'DONTDOIT' line above, the first time around. Feedback is welcomed"
echo "at patton@sysnet.net or pattonme@gnpr.pae.osd.mil."
echo ""
echo "This program is designed to help you put NetBSD file systems on your"
echo "ADDITIONAL hard disks in a simple and rational way. I have NOT tried"
echo "it from the installation boot floppy."
echo ""
echo "As with anything which modifies your hard drive's contents, this"
echo "program can cause SIGNIFICANT data loss, and you are advised"
echo "to make sure your hard drive is backed up before beginning the"
echo "formatting process."
echo ""
echo "Default answers are displyed in brackets after the questions."
echo "You can hit Control-C at any time to quit, but if you do so at a"
echo "prompt, you may have to hit return. Also, quitting in the middle of"
echo "installation may leave your system in an inconsistent state."
echo ""
echo -n "Proceed with program? [n] "
getresp "n"
case "$resp" in
y*|Y*)
echo "Cool! Let's get to it..."
;;
*)
echo ""
echo "OK, then. Try again later."
exit
;;
esac
echo ""
echo "To do the formatting, you'll need to provide some information about"
echo "your disk."
echo ""
echo "NetBSD can format ST506, ESDI, IDE, or SCSI disks."
echo -n "What kind of disk will you be installing on? [SCSI] "
getresp "SCSI"
case "$resp" in
esdi|ESDI|st506|ST506)
drivetype=wd
echo -n "Does it support _automatic_ sector remapping? [y] "
getresp "y"
case "$resp" in
n*|N*)
sect_fwd="sf:"
;;
*)
sect_fwd=""
;;
esac
;;
ide|IDE)
drivetype=wd
sect_fwd=""
type=ST506
;;
scsi|SCSI)
drivetype=sd
sect_fwd=""
type=SCSI
;;
esac
# find out what units are possible for that disk, and query the user.
driveunits=`ls /dev/${drivetype}?a | sed -e 's,/dev/\(...\)a,\1,g'`
if [ "X${driveunits}" = "X" ]; then
echo "FATAL ERROR:"
echo "No devices for disks of type '${drivetype}'."
echo "Exiting format program."
exit
fi
prefdrive=${drivetype}0
echo ""
echo "The following ${drivetype}-type disks are supported by this"
echo "formatting procedure:"
echo " "${driveunits}
echo "Note that they may not exist in _your_ machine; the list of"
echo "disks in your machine was printed when the system was booting."
echo ""
while [ "X${drivename}" = "X" ]; do
echo -n "Which disk would like to format? [${prefdrive}] "
getresp ${prefdrive}
otherdrives=`echo "${driveunits}" | sed -e s,${resp},,`
if [ "X${driveunits}" = "X${otherdrives}" ]; then
echo ""
echo "\"${resp}\" is an invalid drive name. Valid choices"
echo "are: "${driveunits}
echo ""
else
drivename=${resp}
fi
done
echo ""
echo "Using disk ${drivename}."
echo ""
echo -n "What kind of disk is it? (one word please) [my${drivetype}] "
getresp "my${drivetype}"
labelname=$resp
echo ""
echo "You will now need to provide some information about your disk's"
echo "geometry. This should either be in the User's Manual for your disk,"
echo "or you should have written down what NetBSD printed when booting."
echo "(Note that he geometry that's printed at boot time is preferred.)"
echo ""
echo "You may choose to view the initial boot messages for your system"
echo "again right now if you like."
echo -n "View the boot messages again? [n] "
getresp "n"
case "$resp" in
y*|Y*)
more /kern/msgbuf
;;
*)
echo ""
;;
esac
echo ""
echo "You will now enter the disk geometry information"
echo ""
echo -n "Number of bytes per disk sector? [512] "
getresp 512
bytes_per_sect="$resp"
echo -n "Number of disk cylinders? "
getresp
cyls_per_disk="$resp"
echo -n "Number of disk tracks (heads) per disk cylinder? "
getresp
tracks_per_cyl="$resp"
echo -n "Number of disk sectors per disk track? "
getresp
sects_per_track="$resp"
cylindersize=`expr $sects_per_track \* $tracks_per_cyl`
cylbytes=`expr $cylindersize \* $bytes_per_sect`
disksize=`expr $cylindersize \* $cyls_per_disk`
echo ""
echo "Your disk has a total of $disksize $bytes_per_sect byte sectors,"
echo "arranged as $cyls_per_disk cylinders which contain $cylindersize "
echo "sectors ($cylbytes bytes) each."
echo ""
echo "You can specify partition sizes in cylinders ('c') or sectors ('s')."
while [ "X${sizemult}" = "X" ]; do
echo -n "What units would you like to use? [cylinders] "
getresp cylinders
case "$resp" in
c*|C*)
sizemult=$cylindersize
sizeunit="cylinders"
;;
s*|S*)
sizemult=1
sizeunit="sectors"
;;
*)
echo ""
echo "Enter cylinders ('c') or sectors ('s')."
;;
esac
done
if [ $sizeunit = "sectors" ]; then
echo ""
echo "For best disk performance, partitions should begin and end on"
echo "cylinder boundaries. Wherever possible, pick sizes that are"
echo "multiples of the cylinder size ($cylindersize sectors)."
fi
echo -n ""
echo -n "Size of NetBSD portion of disk (in $sizeunit)? "
getresp
partition=$resp
partition_sects=`expr $resp \* $sizemult`
part_offset=0
if [ $partition_sects -lt $disksize ]; then
echo -n "Offset of NetBSD portion of disk (in $sizeunit)? "
getresp
part_offset=$resp
fi
badspacesec=0
if [ "$sect_fwd" = "sf:" ]; then
badspacecyl=`expr $sects_per_track + 126`
badspacecyl=`expr $badspacecyl + $cylindersize - 1`
badspacecyl=`expr $badspacecyl / $cylindersize`
badspacesec=`expr $badspacecyl \* $cylindersize`
echo ""
echo -n "Using $badspacesec sectors ($badspacecyl cylinders) for the "
echo "bad144 bad block table"
fi
sects_left=`expr $partition_sects - $badspacesec`
units_left=`expr $sects_left / $sizemult`
echo ""
echo "There are $units_left $sizeunit left to allocate."
echo ""
root=0
finish=0
while [ $finish -eq 0 ]; do
echo -n "Root partition size (in $sizeunit)? "
getresp
case $resp in
[1-9]*)
total=$resp
if [ $total -gt $units_left ]; then
echo -n "Root size is greater than remaining "
echo "free space on disk."
else
root=$resp
finish=1
fi
;;
0) finish=1
;;
esac
done
root_offset=$part_offset
part_used=`expr $root + $badspacesec / $sizemult`
units_left=`expr $partition - $part_used`
echo ""
swap=0
finish=0
while [ $finish -eq 0 ]; do
echo "$units_left $sizeunit remaining in NetBSD portion of disk."
echo -n "Swap partition size (in $sizeunit)? "
getresp
case $resp in
[1-9]*)
if [ $swap -gt $units_left ]; then
echo -n "Swap size is greater than remaining "
echo "free space on disk."
else
swap=$resp
finish=1
fi
;;
0) finish=1
;;
esac
done
swap_offset=`expr $root_offset + $root`
part_used=`expr $part_used + $swap`
echo ""
fragsize=1024
blocksize=8192
echo "" >> $DT
echo "$labelname|NetBSD format tool generated:\\" >> $DT
echo " :dt=${type}:ty=winchester:\\" >> $DT
echo -n " :nc#${cyls_per_disk}:ns#${sects_per_track}" >> $DT
echo ":nt#${tracks_per_cyl}:\\" >> $DT
echo " :se#${bytes_per_sect}:${sect_fwd}\\" >> $DT
_size=`expr $root \* $sizemult`
_offset=`expr $root_offset \* $sizemult`
echo -n " :pa#${_size}:oa#${_offset}" >> $DT
echo ":ta=4.2BSD:ba#${blocksize}:fa#${fragsize}:\\" >> $DT
_size=`expr $swap \* $sizemult`
_offset=`expr $swap_offset \* $sizemult`
echo " :pb#${_size}:ob#${_offset}:tb=swap:\\" >> $DT
_size=`expr $partition \* $sizemult`
_offset=`expr $part_offset \* $sizemult`
echo " :pc#${_size}:oc#${_offset}:\\" >> $DT
echo "You will now have to enter information about any other partitions"
echo "to be created in the NetBSD portion of the disk. This process will"
echo "be complete when you've filled up all remaining space in the NetBSD"
echo "portion of the disk."
while [ $part_used -lt $partition ]; do
part_size=0
units_left=`expr $partition - $part_used`
while [ $part_size -eq 0 ]; do
echo ""
echo -n "$units_left $sizeunit remaining in NetBSD portion of "
echo "the disk"
echo -n "Next partition size (in $sizeunit)? "
getresp
case $resp in
[1-9]*)
total=`expr $part_used + $resp`
if [ $total -gt $partition ]; then
echo -n "That would make the parition"
echo "too large to fit!"
else
part_size=$resp
part_used=$total
part_name=""
while [ "$part_name" = "" ]; do
echo -n "Mount point? "
getresp
part_name=$resp
done
fi
;;
esac
done
if [ "$ename" = "" ]; then
ename=$part_name
offset=`expr $part_offset + $root + $swap`
_size=`expr $part_size \* $sizemult`
_offset=`expr $offset \* $sizemult`
echo -n " :pe#${_size}:oe#${_offset}" >> $DT
echo ":te=4.2BSD:be#${blocksize}:fe#${fragsize}:\\" >> $DT
offset=`expr $offset + $part_size`
elif [ "$fname" = "" ]; then
fname=$part_name
_size=`expr $part_size \* $sizemult`
_offset=`expr $offset \* $sizemult`
echo -n " :pf#${_size}:of#${_offset}" >> $DT
echo ":tf=4.2BSD:bf#${blocksize}:ff#${fragsize}:\\" >> $DT
offset=`expr $offset + $part_size`
elif [ "$gname" = "" ]; then
gname=$part_name
_size=`expr $part_size \* $sizemult`
_offset=`expr $offset \* $sizemult`
echo -n " :pg#${_size}:og#${_offset}" >> $DT
echo ":tg=4.2BSD:bg#${blocksize}:fg#${fragsize}:\\" >> $DT
offset=`expr $offset + $part_size`
elif [ "$hname" = "" ]; then
hname=$part_name
_size=`expr $part_size \* $sizemult`
_offset=`expr $offset \* $sizemult`
echo -n " :ph#${_size}:oh#${_offset}" >> $DT
echo ":th=4.2BSD:bh#${blocksize}:fh#${fragsize}:\\" >> $DT
part_used=$partition
fi
done
echo " :pd#${disksize}:od#0:" >> $DT
sync
echo ""
echo "THIS IS YOUR LAST CHANCE!!!"
echo ""
echo -n "Are you SURE you want to format your hard drive? (yes/no) "
answer=""
while [ "$answer" = "" ]; do
getresp
case $resp in
yes|YES)
echo ""
echo "Here we go..."
answer=yes
;;
no|NO)
echo ""
echo -n "OK, then. Type 'format' to retry this "
echo -n "process."
exit
;;
*)
echo -n "I want a yes or no answer... well? "
;;
esac
done
echo ""
echo -n "Labeling disk $drivename..."
$DONTDOIT disklabel -w -B $drivename $labelname
echo " done."
if [ "$sect_fwd" = "sf:" ]; then
echo -n "Initializing bad144 badblock table..."
$DONTDOIT bad144 $drivename 0
echo " done."
fi
echo "Initializing root filesystem, and mounting..."
$DONTDOIT newfs /dev/r${drivename}a $name
$DONTDOIT mount -v /dev/${drivename}a /mnt
if [ "$ename" != "" ]; then
echo ""
echo "Initializing $ename filesystem, and mounting..."
$DONTDOIT newfs /dev/r${drivename}e $name
$DONTDOIT mkdir -p /mnt/$ename
$DONTDOIT mount -v /dev/${drivename}e /mnt/$ename
fi
if [ "$fname" != "" ]; then
echo ""
echo "Initializing $fname filesystem, and mounting..."
$DONTDOIT newfs /dev/r${drivename}f $name
$DONTDOIT mkdir -p /mnt/$fname
$DONTDOIT mount -v /dev/${drivename}f /mnt/$fname
fi
if [ "$gname" != "" ]; then
echo ""
echo "Initializing $gname filesystem, and mounting..."
$DONTDOIT newfs /dev/r${drivename}g $name
$DONTDOIT mkdir -p /mnt/$gname
$DONTDOIT mount -v /dev/${drivename}g /mnt/$gname
fi
if [ "$hname" != "" ]; then
echo ""
echo "Initializing $hname filesystem, and mounting..."
$DONTDOIT newfs /dev/r${drivename}h $name
$DONTDOIT mkdir -p /mnt/$hname
$DONTDOIT mount -v /dev/${drivename}h /mnt/$hname
fi
echo ""
echo -n "Updating the fstab..."
echo /dev/${drivename}a /mnt ffs rw 1 1 | sed -e s,//,/, >> $FSTAB
if [ "$ename" != "" ]; then
echo /dev/${drivename}e /$ename ffs rw 1 2 | sed -e s,//,/, >> $FSTAB
fi
if [ "$fname" != "" ]; then
echo /dev/${drivename}f /$fname ffs rw 1 3 | sed -e s,//,/, >> $FSTAB
fi
if [ "$gname" != "" ]; then
echo /dev/${drivename}g /$gname ffs rw 1 4 | sed -e s,//,/, >> $FSTAB
fi
if [ "$hname" != "" ]; then
echo /dev/${drivename}h /$hname ffs rw 1 5 | sed -e s,//,/, >> $FSTAB
fi
sync
echo " done."
echo ""
echo ""
echo "OK! Be SURE to check out the accuracy of the /etc/fstab and fix it "
echo "as necessary."
echo ""