The scsi cd.c driver is now fully dynamic. You can change the lines
[unix-history] / etc / etc.i386 / inst1.install
index c4402f0..58e9ac9 100644 (file)
 #!/bin/sh
 # install1.fs disk 'install'
 #!/bin/sh
 # install1.fs disk 'install'
-# Simplified, interactive NetBSD installation script.
-# D.E. Silvia (dsilvia@net.com)
-#
-# (and again hacked on by rgrimes 1993/08/10,
-#  for FreeBSD, changed only the printing messages, not the comments
-#  about what OS this is for, now uses variable ${OPSYSTEM},
-#  converted to use cpio)
-#
-# (once again hacked on by rgrimes 1993/07/29,
-#  disabled old disktab.preinstall,
-#  added questions for what blocking factor to use in the file system,
-#  added (heads) to clarify what disk tracks means)
-#
-# (heavily hacked by cgd)
-# (and again by rwgrimes, for bad144 support and some error checking)
-#
-# Provides for variable swap and multiple partitions.
-#
-# Installs first minimal part of basic NetBSD system.
-#
-# Does not appear to work properly IF not using whole disk _AND_ there is
-# no DOS partition (kernel bug?  Tries to chroot to partition 'd' :-{ )
 #
 # Currently, no method for checking to see if the designated disk type is
 # already in /etc/disktab.  You can edit it out of the file after installation.
 #
 OPSYSTEM=FreeBSD
 #
 # Currently, no method for checking to see if the designated disk type is
 # already in /etc/disktab.  You can edit it out of the file after installation.
 #
 OPSYSTEM=FreeBSD
+OPSYSID=165
+ROOTMIN=7
+SWAPMIN=8
+DISKMIN=`expr $ROOTMIN + $SWAPMIN + 1`
+DEFBLOCKING=2
+DEFSECT=17
+DEFHEAD=12
+DEFCYLN=1024
+RUN_FDISK=""
 
 
-echo    "Welcome to ${OPSYSTEM}."
-echo    ""
-echo    "This program is designed to help you put ${OPSYSTEM} on your hard disk,"
-echo    "in a simple and rational way.  You'll be asked several questions,"
-echo    "and it would probably be useful to have your disk's hardware"
-echo   "manual, the installation notes, and a calculator handy."
-echo    ""
-echo   "In particular, you will need to know some reasonably detailed"
-echo   "information about your disk's geometry, because there is currently"
-echo   "no way this this program can figure that information out."
-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   "installation process."
-echo    ""
-echo -n "Proceed with installation? [n] "
-read resp
-case $resp in
+set_arbitrary_defaults() {
+cyls_per_disk=$DEFCYLN
+tracks_per_cyl=$DEFHEAD
+sects_per_track=$DEFSECT
+unused_last_part=3
+part_cnt=4
+}
+
+
+get_fdisk_data() {
+cyls_per_disk=
+part_id=
+got_sysid=
+part_cnt=0
+sysid_cnt=0
+have_opsys_part=
+unused_last_part=
+extent_max=0
+extent_max_part=
+
+fdisk /dev/r${drivename}d >fdisk.out 2>fdisk.err
+if [ $? -gt 0 ]; then
+       echo "Can't open /dev/r${drivename}d for reading!"
+       set_arbitrary_defaults
+       >fdisk.out 
+       >fdisk.err
+       return 2
+elif [ -s fdisk.err ]; then
+       echo "Disk doesn't appear to be initialized..."
+       no_part_table=1
+fi
+while read data; do
+       if [ ! "$cyls_per_disk" ]; then
+               cyls_per_disk=`expr "$data" : '[^=]*=\([0-9]*\)'`
+               tracks_per_cyl=`expr "$data" : '[^=]*=[^=]*=\([0-9]*\)'`
+               sects_per_track=`expr "$data" : '[^=]*=[^=]*=[^=]*=\([0-9]*\)'`
+               continue
+       fi
+       if [ "$got_sysid" ]; then
+               start_part=`expr "$data" : '[^0-9]*\([0-9]*\)'`
+               size_part=`expr "$data" : '[^0-9]*[0-9]*[^0-9]*\([0-9]*\)'`
+               extent_part=`expr $start_part + $size_part`
+               if [ $extent_part -gt $extent_max ]; then
+                       extent_max=$extent_part
+                       extent_max_part=$part_id
+               fi
+               eval start${part_id}=$start_part
+               eval size${part_id}=$size_part
+               sysid_cnt=`expr $sysid_cnt + 1`
+               got_sysid=
+               part_id=
+       elif [  "$part_id" ]; then
+               sysid=`expr "$data" : 'sysid \([0-9]*\)'`
+               if [ "$no_part_table" -o "$sysid" = "0" -o \
+                   "$(expr "$data" : '\(<UNUSED>\)')" = "<UNUSED>" ]; then
+                       unused_last_part=$part_id
+                       part_id=
+                       continue
+               fi
+               [ "$sysid" = "$OPSYSID" ] && have_opsys_part=$part_id
+               eval sysid${part_id}=$sysid
+               got_sysid=1
+       else 
+               part_id=`expr "$data" : 'The data[^0-9]*\([0-9]*\)'`
+               beg_cyl=`expr "$data" : '[      ]*beg[^0-9]*\([0-9]*\)'`
+               end_cyl=`expr "$data" : '[      ]*end[^0-9]*\([0-9]*\)'`
+               if [ "$part_id" ]; then         
+                       part_cnt=`expr $part_cnt + 1`
+               elif [ "$beg_cyl"  ]; then
+                               if [ $beg_cyl -gt $cyls_per_disk ]; then
+                                       no_part_table=1
+                                       sysid_cnt=0
+                                       have_opsys_part=0
+                                       unused_last_part=`expr $part_cnt - 1`
+                               fi
+               elif [ "$end_cyl" ]; then 
+                               if [ $end_cyl -gt $cyls_per_disk ]; then
+                                       no_part_table=1
+                                       sysid_cnt=0
+                                       have_opsys_part=0
+                                       unused_last_part=`expr $part_cnt - 1`
+                               fi
+               fi
+       fi
+done <fdisk.out
+if [ ! "$cyls_per_disk" ]; then
+       set_arbitrary_defaults
+       return 2
+fi
+>fdisk.out 
+>fdisk.err
+return 0
+}
+
+analyze_fdisk_data() {
+# Case I: >1024 cylinders
+force_offset=
+if [ $cyls_per_disk -gt 1024 ]; then
+       echo
+       echo "WARNING: >1024 cylinders."
+       echo -n "Overwriting existing partitions - okay? [y] "
+       read resp junk
+       [ ! "$resp" ] && resp=y
+       case "$resp" in
+       y*|Y*)
+               RUN_FDISK=""
+               force_offset=1
+               opsys_off=0
+               cyls_per_opsys=${cyls_per_disk}
+               opsys_part=${unused_last_part:-3}
+               return 0
+               ;;
+       *)
+               echo
+               echo "If the number of disk cylinders does not exceed 1024, then ${OPSYSTEM}"
+               echo "can be installed alongside other operating systems on a single disk."
+               echo "Otherwise, it is system-dependent whether this will work or not."
+               echo "In the worst case, ${OPSYSTEM} MUST be installed at the beginning of"
+               echo "the disk, and existing partitions will be lost."
+               echo
+               echo "For now, we will assume that >1024 cylinders creates no problems..."
+               # FALL THROUGH
+               ;;
+       esac
+fi
+# Case II: no partitions used
+if [ $sysid_cnt -eq 0 ]; then
+       echo
+       echo "WARNING: partition table is either missing or corrupt."
+       echo "Existing partitions will be lost."
+       part_cnt=${part_cnt:-4}
+       RUN_FDISK="overwrite"
+       opsys_off=1
+       cyls_per_opsys=`expr ${cyls_per_disk} - 1`
+       opsys_part=${unused_last_part:-3}
+       return 0
+# Case IIIa: overwrite an existing 386BSD/NetBSD/FreeBSD partition
+elif [ "$have_opsys_part" ]; then
+       echo
+       echo "386/Net/FreeBSD partition already exists!"
+       echo -n "Overwriting existing partition - okay? [y] "
+       read resp junk
+       [ ! "$resp" ] && resp=y
+       case "$resp" in
+       y*|Y*)
+               # Set existing partiton values as default (after adjusting to
+               # cylinder boundaries)
+               eval opsys_size=\$size${have_opsys_part}
+               eval opsys_start=\$start${have_opsys_part}
+               [ $opsys_size -eq 50000 ] && opsys_size=$disksize
+               opsys_off=`expr $opsys_start / $cylindersize`
+               opsys_adjusted=`expr $opsys_off \* $cylindersize`
+               if [ $opsys_adjusted -lt $opsys_start -o $opsys_off -eq 0 ]; then
+                       opsys_off=`expr $opsys_off + 1`
+                       opsys_adjusted=`expr $opsys_off \* $cylindersize`
+                       opsys_size=`expr $opsys_size - $opsys_adjusted + $opsys_start`
+               fi
+               cyls_per_opsys=`expr $opsys_size / $cylindersize`
+               opsys_part=${have_opsys_part}
+               RUN_FDISK="fdisk -u"
+               return 0
+               ;;
+       *)
+               have_opsys_part=
+               # FALL THROUGH
+               ;;
+       esac
+fi
+
+# Case IIIb: no partitions available
+if [ $sysid_cnt -eq $part_cnt -a ! "$have_opsys_part" ]; then
+       echo
+       echo "No unused partitions."
+       echo "$OPSYSTEM cannot selectively overwrite existing partitions."
+       echo -n "Install $OPSYSTEM and overwrite the entire disk? [n] "
+       read resp junk
+       case "$resp" in
        y*|Y*)
        y*|Y*)
-               echo    "Cool!  Let's get to it..."
+               # don't use first cylinder!
+               opsys_off=1
+               cyls_per_opsys=`expr $cyls_per_disk - 1`
+               opsys_part=${unused_last_part}
+               RUN_FDISK="overwrite"
+               return 0
                ;;
        *)
                ;;
        *)
-               echo    ""
-               echo    "OK, then.  enter 'halt' to halt the machine."
-               echo    "Once the machine has halted, remove the floppy,"
-               echo    "and press any key to reboot."
-               exit
+               return 2
                ;;
                ;;
+       esac
+fi
+
+
+# *** CAVEAT ***
+# $OPSYSTEM installs at the end of the disk.  If the
+# beginning of the disk is free but not the end, install fails!
+
+# Assume `fdisk -u' to add $OPSYSTEM in last unused partition for remaining cases
+opsys_part=${unused_last_part}
+RUN_FDISK="fdisk -u"
+mb_sect=`expr 1024 \* 1024 / $bytes_per_sect`
+disk_minimum=`expr $DISKMIN \* $mb_sect`
+
+# Case IV: No room (at end of disk) for mininal install
+disk_remaining=`expr $disksize - $extent_max`
+if [ $disk_remaining -lt $disk_minimum ]; then
+       echo
+       echo "Not enough space ($DISKMIN Mb) at end of disk to install $OPSYSTEM."
+       echo -n "Install FreeBSD and overwrite the entire disk? [n] "
+       read resp junk
+       case "$resp" in
+       y*|Y*)
+               # don't use first cylinder!
+               opsys_off=1
+               cyls_per_opsys=`expr $cyls_per_disk - 1`
+               opsys_part=${unused_last_part}
+               RUN_FDISK="overwrite"
+               ;;
+       *)
+               echo
+               echo "WARNING: To install ${OPSYSTEM}, you're on your own in figuring"
+               echo "out where on the disk it will fit without overwriting another"
+               echo "partition..."
+               # Set defaults assuming there is only one partition at end of disk
+               eval start=\$start${extent_max_part}
+               # don't use first cylinder!
+               opsys_off=1
+               cyls_per_opsys=`expr $start / $cylindersize - 1`
+               ;;
+       esac
+       return 0
+fi
+
+# Case V: Room for $OPSYSTEM and partition data okay
+opsys_off=`expr $extent_max / $cylindersize`
+opsys_extent=`expr $opsys_off \* $cylindersize`
+[ $opsys_extent -lt $extent_max ] && opsys_off=`expr $opsys_off + 1`
+cyls_per_opsys=`expr $cyls_per_disk - $opsys_off`
+return 0
+}
+
+put_fdisk_data() {
+start=$root_offset
+size=$partition 
+
+if [ "$RUN_FDISK" = "overwrite" ]; then
+       # How do you overwrite without explicitly editing each entry?
+       (
+               echo y
+               echo $cyls_per_disk
+               echo $tracks_per_cyl
+               echo $sects_per_track
+               echo y
+       ) >fdisk.script
+       i=0
+       n=`expr ${part_cnt:-4} - 1`
+       while [ $i -lt $n ]; do
+               echo y
+               echo 0
+               echo 0
+               echo 0
+               echo n
+               echo y
+               i=`expr $i + 1`
+       done >>fdisk.script
+       (       echo y
+               echo ${OPSYSID}
+               echo ${start}
+               echo ${size}
+               echo n
+               echo y
+               echo y
+               echo ${n}
+               echo y
+               echo y
+       ) >>fdisk.script
+       fdisk -u <fdisk.script >/dev/null 2>&1
+elif [ "$RUN_FDISK" ]; then
+       $RUN_FDISK -${opsys_part:-${unused_last_part:-3}} <<-EOF >/dev/null 2>&1
+       y
+       $cyls_per_disk
+       $tracks_per_cyl
+       $sects_per_track
+       y
+       y
+       ${OPSYSID}
+       ${start}
+       ${size}
+       n
+       y
+       y
+       ${opsys_part:-${unused_last_part:-3}}
+       y
+       y
+       EOF
+fi
+
+}
+
+echo    "Welcome to ${OPSYSTEM}."
+echo
+echo    "This program is designed to help put ${OPSYSTEM} on a hard disk with"
+echo   "at least $DISKMIN Megabytes of free space."
+echo
+echo   "If other operating systems are already on the disk, ${OPSYSTEM}"
+echo   "should be able to install alongside them.  Otherwise, if the disk"
+echo   "is being installed for the first time, it would probably be useful"
+echo   "to have the disk's hardware manual, the installation notes, and a"
+echo   "calculator handy."
+echo
+echo   "As with anything which modifies a hard drive's contents, this"
+echo   "program can cause SIGNIFICANT data loss, and we strongly recommend"
+echo   "making sure that the hard drive is backed up before going further with"
+echo   "the installation process."
+echo
+echo -n "Proceed with installation? [y] "
+read resp junk
+resp=${resp:-y}
+case "$resp" in
+y*|Y*)
+       echo
+       echo    "Cool!  Let's get to it..."
+       echo
+       echo    "If a mistake is made along the way, don't bail out."
+       echo    "At the end, you have the option to redo the configuration."
+       echo    "If you really must quit at some point, type <CTRL>+C and"
+       echo    "enter \`halt' at the command prompt, \`#'."
+       ;;
+*)
+       echo
+       echo    "OK, then.  Enter \`halt' to halt the machine."
+       echo    "Once the machine has halted, remove the floppy,"
+       echo    "and press any key to reboot."
+       exit
+       ;;
 esac
 
 esac
 
+mount -u /dev/fd0a /
+sync
+verified_install=""
+while [ ! "$verified_install" ]; do    # Begin of Big Loop
+
 rotdelay=""
 drivename=wd0
 drivetype=wd
 sect_fwd=""
 rotdelay=""
 drivename=wd0
 drivetype=wd
 sect_fwd=""
-echo    ""
-echo    "Drive types can be ESDI, SCSI, ST506, or IDE."
-echo -n "Drive type? "
-read type
+echo
+echo    "First, we need to know the drive type.  This can be can be one of"
+echo   "ESDI, SCSI, ST506, or IDE."
+echo -n "Drive type? [${type:-IDE}] "
+read resp junk
+type=${resp:-${type:-IDE}}
 case "$type" in
 case "$type" in
-       esdi|ESDI|st506|ST506)
-               echo -n "Does it support _automatic_ sector remapping? [y] "
-               read remap
-               case "$remap" in
-                       n*|N*)
-                               sect_fwd="sf:"
-                               ;;
-               esac
-               ;;
-       ide|IDE)
-               type=ST506
+e*|E*|st*|ST*)
+       echo -n "Does it support AUTOMATIC sector remapping? [y] "
+       read remap junk
+       case "$remap" in
+       n*|N*)
+               sect_fwd="sf:"
                ;;
                ;;
-       scsi|SCSI)
-               drivename=sd0
-               drivetype=sd
-               type=SCSI
-               rotdelay="-d 0"
+       esac
+       case "$type" in
+       e*|E*)
+               DEFSECT=36
                ;;
                ;;
+       esac
+       ;;
+i*|I*)
+       type=ST506
+       rotdelay="-d 0"
+       ;;
+sc*|SC*)
+       drivename=sd0
+       drivetype=sd
+       type=SCSI
+       rotdelay="-d 0"
+       DEFSECT=32
+       DEFHEAD=64
+       ;;
+*)
+       echo "Unknown type.  Assuming ST506 with automatic sectoring..."
+       type=ST506
+       ;;
 esac
 esac
-echo    ""
-echo    "Disk is of type $drivetype"
-echo    "going to install on $drivename..."
-echo    ""
-echo -n "Label name (what kind of disk is it, one word please)? "
-read name
-echo   ""
-echo -n "Number of bytes per disk sector? [512] "
-read bytes_per_sect
-if [ "$bytes_per_sect" = "" ]; then
-       bytes_per_sect=512
+echo
+echo    "Disk is of device type $drivetype."
+echo
+echo -n "Number of bytes per disk sector? [${bytes_per_sect:-512}] "
+read resp junk
+bytes_per_sect=${resp:-${bytes_per_sect:-512}}
+if [ ! "$partition" ]; then
+       echo
+       echo    "Please wait.  Examining device /dev/r${drivename}d..."
+       get_fdisk_data
+       if [ $? -gt 1 ]; then
+               echo "Hm  - we can't seem to read that drive."
+               echo
+               echo -n "Are you sure that $type is the correct type? [n] "
+               read resp
+               case "$resp" in
+               y*|Y*)
+                       echo "Well, since we can't even open it, there isn't much"
+                       echo "hope for writing a label  on it.  But you're free"
+                       echo "to give it a try.  You need to specify the geometry."
+                       ;;
+               *)
+                       echo "Okay.  Let's start again from the top."
+                       continue
+                       ;;
+               esac
+       fi
 fi
 fi
-echo   ""
-echo -n "Number of disk cylinders? "
-read cyls_per_disk
-echo   ""
-echo -n "Number of disk heads? "
-read tracks_per_cyl
-echo   ""
-echo -n "Number of disk sectors? "
-read sects_per_track
-echo   ""
+echo
+echo   "Now we want to build a data base entry in /etc/disktab describing"
+echo   "the geometry of the /dev/$drivename disk.  The name of the entry"
+echo   "should be descriptive of the disk's type and model.  For example,"
+echo   "a Maxtor IDE, model 7080 disk might be named \`maxtor7080'."
+echo -n "Disk label name (one word, please)? [${name:-mfr_model}] "
+read resp junk
+name=${resp:-${name:-mfr_model}}
+echo
+echo -n "Total number of disk cylinders? [${cyls_per_disk:-${DEFCYLN}}] "
+read resp junk
+cyls_per_disk=${resp:-${cyls_per_disk:-${DEFCYLN}}}
+echo
+echo -n "Number of disk heads (i.e., tracks/cylinder)? [${tracks_per_cyl:-${DEFHEAD}}] "
+read resp junk
+tracks_per_cyl=${resp:-${tracks_per_cyl:-${DEFHEAD}}}
+echo
+echo -n "Number of disk sectors (i.e., sectors/track)? [${sects_per_track:-${DEFSECT}}] "
+read resp junk
+sects_per_track=${resp:-${sects_per_track:-${DEFSECT}}}
 cylindersize=`expr $sects_per_track \* $tracks_per_cyl`
 disksize=`expr $cylindersize \* $cyls_per_disk`
 cylindersize=`expr $sects_per_track \* $tracks_per_cyl`
 disksize=`expr $cylindersize \* $cyls_per_disk`
-echo    "Disk has a total of $disksize $bytes_per_sect byte sectors"
-echo    "For greater efficiency, partitions should begin and end on cylinder"
-echo    "boundaries.  Cylinder size (in $bytes_per_sect byte sectors) on this"
-echo    "disk is $cylindersize.  Choose multiples of this value."
-echo   ""
-echo -n "Size of ${OPSYSTEM} portion of disk (in $bytes_per_sect byte sized sectors)? "
-read partition
-part_offset=0
-if [ $partition -lt $disksize ]; then
-       echo -n "Offset of ${OPSYSTEM} portion of disk (in $bytes_per_sect byte sized sectors) "
-       read part_offset
+mb_sect=`expr 1024 \* 1024 / $bytes_per_sect`
+mb_per_disk=`expr $disksize / $mb_sect`
+opsys_cyls_min=`expr $DISKMIN \* $mb_sect / $cylindersize`
+analyze_fdisk_data
+if [ $? -eq 0 ]; then
+       partition=`expr $cyls_per_opsys \* $cylindersize`
+       part_offset=`expr $opsys_off \* $cylindersize`
 fi
 fi
+echo
+echo "Disk has a total of $mb_per_disk Mb."
+echo "The size of the ${OPSYSTEM} portion of the disk must be at least"
+echo "${opsys_cyls_min} cylinders, and should not exceed $(expr $cyls_per_disk - 1) cylinders."
+echo "The offset of ${OPSYSTEM} from the beginning of the disk should be at"
+echo "least 1 cylinder."
+echo 
+echo "For efficiency, partitions begin and end on cylinder boundaries."
+echo "If you know the size NN in Megabytes (Mb) of a partition you want, then"
+echo "use the following formula to determine the number NC of cylinders to use:"
+echo   "       NC = integer { ( NN * $mb_sect ) /  $cylindersize }"
+while :; do
+       echo -n "Total size of the ${OPSYSTEM} portion of the disk (in cylinders)? [${cyls_per_opsys:-`expr ${cyls_per_disk} - 1`}] "
+       read resp junk
+       cyls_per_opsys=${resp:-${cyls_per_opsys:-`expr ${cyls_per_disk} - 1`}}
+       partition=`expr $cyls_per_opsys \* $cylindersize`
+       if [ $cyls_per_opsys -lt $cyls_per_disk -a ! "$force_offset" ]; then
+               echo
+               echo -n "Offset of ${OPSYSTEM} from beginning of disk (in cylinders)? [${opsys_off:-1}] "
+               read resp junk
+               opsys_off=${resp:-${opsys_off:-1}}
+       else
+               echo
+               echo "WARNING: Installing at cylinder 0 overwrites DOS partition table."
+               echo "Existing partitions will be lost, and subsequent installs may fail."
+               RUN_FDISK=""
+               cyls_per_opsys=$cyls_per_disk
+               partition=$disksize
+               opsys_off=0
+       fi
+       part_offset=`expr $opsys_off \* $cylindersize`
+       opsys_extent=`expr $opsys_off + $cyls_per_opsys`
+       if [ ${opsys_extent} -gt ${cyls_per_disk} ]; then 
+               echo
+               echo "${OPSYSTEM} Size + Offset cannot exceed ${cyls_per_disk} cylinders."
+       elif [ ${cyls_per_opsys} -lt ${opsys_cyls_min} ]; then
+               echo
+               echo "${OPSYSTEM} requires at least ${opsys_cyls_min} cylinders to install."
+       else    break 
+       fi
+done
 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`
 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
        echo -n "Using $badspacesec sectors ($badspacecyl cylinders) for the "
        echo "bad144 bad block table"
 fi
 whats_left=`expr $partition - $badspacesec`
 cyl_left=`expr $whats_left / $cylindersize`
        echo -n "Using $badspacesec sectors ($badspacecyl cylinders) for the "
        echo "bad144 bad block table"
 fi
 whats_left=`expr $partition - $badspacesec`
 cyl_left=`expr $whats_left / $cylindersize`
-echo   ""
-echo   "There are $whats_left sectors ($cyl_left cylinders) left to allocate"
-echo   ""
-root=0
-while [ $root -eq 0 ]; do
-       echo -n "Root partition size (in $bytes_per_sect byte sized sectors)? "
-       read root
-       case $root in
-               [1-9]*)
-                       total=$root
-                       if [ $total -gt $whats_left ]; then
-                               echo Total is greater than remaining free space
-                               root=0
-                       else
-                               part_used=`expr $root + $badspacesec`
-                       fi
-                       ;;
-               *)
-                       root=0
-                       ;;
-       esac
+mb_left=`expr $whats_left / $mb_sect`
+swap_cyls_min=`expr $SWAPMIN \* $mb_sect / $cylindersize`
+root_cyls_max=`expr ${cyl_left} - ${swap_cyls_min}`
+root_cyls_min=`expr $ROOTMIN \* $mb_sect / $cylindersize`
+echo
+echo "There are $mb_left Mb ($cyl_left cylinders) to allocate."
+echo
+echo "The $OPSYSTEM portion of the disk must itself be divided into at least"
+echo "two partitions: one for the root filesystem and one for swap.  It is a"
+echo "good idea to have at least a third (large) $OPSYSTEM partition for the /usr"
+echo "filesystem."
+echo
+echo "The root partition cannot exceed ${root_cyls_max} cylinders.  It is usually"
+echo "no larger than about 15 Mb ($(expr 15 \* $mb_sect / $cylindersize) cylinders), and sometimes"
+echo "as small as $ROOTMIN Mb ($root_cyls_min cylinders)."
+if [ ! "$cyls_per_root" ]; then
+       # set default root partition to 15MB
+       cyls_per_root=`expr \( 15 \* $mb_sect \) /  $cylindersize`
+       [ $cyls_per_root -gt $root_cyls_max ] && cyls_per_root=$root_cyls_max
+fi
+while :; do
+       echo -n "Root partition size (in cylinders)? [${cyls_per_root}] "
+       read resp junk
+       cyls_per_root=${resp:-${cyls_per_root}}
+       root=`expr $cyls_per_root \* $cylindersize`
+       if [ ${cyls_per_root} -gt ${root_cyls_max} ]; then
+               echo
+               echo "The root partition size cannot exceed $root_cyls_max cylinders."
+       elif [ ${cyls_per_root} -lt ${root_cyls_min} ]; then
+               echo
+               echo "The root partition size must be at least $root_cyls_min cylinders."
+       else
+               part_used=`expr $root + $badspacesec`
+               break
+       fi
 done
 root_offset=$part_offset
 whats_left=`expr $partition - $part_used`
 done
 root_offset=$part_offset
 whats_left=`expr $partition - $part_used`
-echo   ""
-minswap=`expr 8192 \* 1024 / $bytes_per_sect`
-swap=0
-while [ $swap -eq 0 ]; do
-       echo    "$whats_left sectors remaining in ${OPSYSTEM} portion of disk"
-       echo    "Minimum swap space is $minswap."
-       echo    "Recomended is 2 x physical memory / $bytes_per_sect"
-       echo -n "Swap partition size (in $bytes_per_sect byte sized sectors)? "
-       read swap 
-       case $swap in
-               [1-9]*)
-                       if [ $swap -gt $whats_left ]; then
-                               echo "Swap size is greater than remaining free space"
-                               swap=0
-                       fi
-                       if [ $swap -lt $minswap ]; then
-                               echo "Swap space must be greater than $minswap"
-                               swap=0
-                       fi
-                       ;;
-               *)
-                       swap=0
-                       ;;
-       esac
-done
-echo ""
-echo "A blocking factor of 1 builds 4k/512 file systems,"
-echo "a blocking factor of 2 builds 8k/1k file systems."
-echo -n "What blocking factor should be used for the filesystem? [1] "
-read blocking_factor
-if [ "$blocking_factor" = "" ]; then
-       blocking_factor=1
+cyl_left=`expr $whats_left / $cylindersize`
+mb_left=`expr $whats_left / $mb_sect`
+echo
+# DO NOT USE DIFFERENT BLOCKING FACTORS FOR EACH PARITION.. IT TRASHES THE
+# VM SYSTEM!  When that gets fixed this can go back the way it was...
+#
+echo "We can build the filesystems with block/fragment sizes of either"
+echo " 1) 4k/512, to save disk space at the expense of speed, or"
+echo " 2) 8k/1k for speed at the expense of disk space."
+echo -n "Which blocking factor should we use for the filesystems? "
+echo -n "[${blocking_factor:-${DEFBLOCKING}}] "
+read resp junk
+blocking_factor=${resp:-${blocking_factor:-${DEFBLOCKING}}}
+fragsize=`expr $bytes_per_sect \* $blocking_factor`
+blocksize=`expr $bytes_per_sect \* $blocking_factor \* 8`
+echo
+echo    "$mb_left Mb ($cyl_left cylinders) remaining in ${OPSYSTEM} portion of disk."
+echo
+echo   "Minimum swap space is ${swap_cyls_min} cylinders."
+echo   "For running X, if your RAM size is NR Mb, then the recomended swap"
+echo   "size NS (in cylinders) is:"
+echo   "       NS = integer { ( NR x `expr 21 \* $mb_sect / 10` ) / ${cylindersize} }"
+if [ ! "$swap_cyl" ]; then
+       # guess memory size
+       mb_ram=16
+       swap_cyl=`expr \( 21 \* $mb_ram \* $mb_sect \) / 10`
+       swap_cyl=`expr $swap_cyl / ${cylindersize}`
+
+       # but not swap size more than 10% of disk size...
+       swap_quot=`expr $mb_left / $mb_ram`
+       if [ $swap_quot -lt 10 ]; then
+               swap_cyl=$swap_cyls_min
+       fi
 fi
 fi
+while :; do
+       echo -n "Swap partition size (in cylinders)? [${swap_cyl}] "
+       read resp junk
+       swap_cyl=${resp:-${swap_cyl}}
+       swap=`expr $swap_cyl \* $cylindersize`
+       if [ ${swap_cyl} -gt ${cyl_left} ]; then
+               echo
+               echo "Swap size cannot exceed $cyl_left cylinders."
+       elif [ ${swap_cyl} -lt ${swap_cyls_min} ]; then
+               echo
+               echo "Swap size must be at least ${swap_cyls_min} cylinders."
+       else
+               break
+       fi
+done
+echo
 swap_offset=`expr $root_offset + $root`
 part_used=`expr $part_used + $swap`
 swap_offset=`expr $root_offset + $root`
 part_used=`expr $part_used + $swap`
-fragsize=`expr $bytes_per_sect \* $blocking_factor`
-blocksize=`expr $bytes_per_sect \* $blocking_factor \* 8`
-mount -u /dev/fd0a /
 echo    "" >/etc/disktab
 echo    "$name|${OPSYSTEM} installation generated:\\" >>/etc/disktab
 echo    "      :dt=${type}:ty=winchester:\\" >>/etc/disktab
 echo    "" >/etc/disktab
 echo    "$name|${OPSYSTEM} installation generated:\\" >>/etc/disktab
 echo    "      :dt=${type}:ty=winchester:\\" >>/etc/disktab
@@ -208,58 +610,61 @@ echo    ":ta=4.2BSD:ba#${blocksize}:fa#${fragsize}:\\" >>/etc/disktab
 echo    "      :pb#${swap}:ob#${swap_offset}:tb=swap:\\" >>/etc/disktab
 echo    "      :pc#${partition}:oc#${part_offset}:\\" >>/etc/disktab
 ename="";fname="";gname="";hname=""
 echo    "      :pb#${swap}:ob#${swap_offset}:tb=swap:\\" >>/etc/disktab
 echo    "      :pc#${partition}:oc#${part_offset}:\\" >>/etc/disktab
 ename="";fname="";gname="";hname=""
-
-echo    ""
-echo   "You will now have to enter information about any other partitions"
-echo   "to be created in the ${OPSYSTEM} portion of the disk.  This process will"
-echo   "be complete when you've filled up all remaining space in the ${OPSYSTEM}"
-echo   "portion of the disk."
-
+if [ $part_used -lt $partition ]; then
+       echo
+       echo    "Now we enter information about any other partitions and filesystems"
+       echo    "to be created in the ${OPSYSTEM} portion of the disk.  This process"
+       echo    "is complete when we've filled up all remaining space in the ${OPSYSTEM}"
+       echo    "portion of the disk."
+fi
 while [ $part_used -lt $partition ]; do
        part_size=0
        whats_left=`expr $partition - $part_used`
 while [ $part_used -lt $partition ]; do
        part_size=0
        whats_left=`expr $partition - $part_used`
-       while [ $part_size -eq 0 ]; do
-               echo    ""
-               echo    "$whats_left sectors remaining in ${OPSYSTEM} portion of disk"
-               echo -n "Next partition size (in $bytes_per_sect byte sized sectors)? "
-               read part_size
-               case $part_size in
-                       [1-9]*)
-                               total=`expr $part_used + $part_size`
-                               if [ $total -gt $partition ]; then
-                                       echo Total is greater than partition size
-                                       part_size=0
-                               else
-                                       part_used=$total
-                                       part_name=""
-                                       while [ "$part_name" = "" ]; do
-                                               echo -n "Mount point (no leading / please)? "
-                                               read part_name
-                                       done
-                               fi
-                               ;;
-                       *)
-                               part_size=0
-                               ;;
-               esac
+       cyl_left=`expr $whats_left / $cylindersize`
+       mb_left=`expr $whats_left / $mb_sect`
+       echo
+       echo    "$mb_left Mb ($cyl_left cylinders) remaining in ${OPSYSTEM} portion of disk."
+       echo
+       while :; do
+               echo -n "Next partition size (in cylinders)? [${cyl_left}] "
+               read resp junk
+               part_size=${resp:-${cyl_left}}
+               part_size=`expr $part_size \* $cylindersize`
+               total=`expr $part_used + $part_size`
+               if [ $total -gt $partition ]; then
+                       echo
+                       echo "Partition size cannot exceed ${cyl_left} cylinders." 
+               else
+                       part_used=$total
+                       part_name=""
+                       while [ "$part_name" = "" ]; do
+                               echo
+                               echo -n "On which directory should this filesystem be mounted? [usr] "
+                               read resp junk
+                               part_name=${resp:-usr}
+                               part_name=`expr "$part_name" : '/*\(.*\)'`
+                       done
+                       break
+               fi
        done
        done
-       if [ "$ename" = "" ]; then      
+       echo
+       if [ ! "$ename" ]; then 
                ename=$part_name
                offset=`expr $part_offset + $root + $swap`
                echo -n "       :pe#${part_size}:oe#${offset}" >>/etc/disktab
                echo ":te=4.2BSD:be#${blocksize}:fe#${fragsize}:\\" >>/etc/disktab
                offset=`expr $offset + $part_size`
                ename=$part_name
                offset=`expr $part_offset + $root + $swap`
                echo -n "       :pe#${part_size}:oe#${offset}" >>/etc/disktab
                echo ":te=4.2BSD:be#${blocksize}:fe#${fragsize}:\\" >>/etc/disktab
                offset=`expr $offset + $part_size`
-       elif [ "$fname" = "" ]; then
+       elif [ ! "$fname" ]; then
                fname=$part_name
                echo -n "       :pf#${part_size}:of#${offset}" >>/etc/disktab
                echo ":tf=4.2BSD:bf#${blocksize}:ff#${fragsize}:\\" >>/etc/disktab
                offset=`expr $offset + $part_size`
                fname=$part_name
                echo -n "       :pf#${part_size}:of#${offset}" >>/etc/disktab
                echo ":tf=4.2BSD:bf#${blocksize}:ff#${fragsize}:\\" >>/etc/disktab
                offset=`expr $offset + $part_size`
-       elif [ "$gname" = "" ]; then
+       elif [ ! "$gname" ]; then
                gname=$part_name
                echo -n "       :pg#${part_size}:og#${offset}" >>/etc/disktab
                echo ":tg=4.2BSD:bg#${blocksize}:fg#${fragsize}:\\" >>/etc/disktab
                offset=`expr $offset + $part_size`
                gname=$part_name
                echo -n "       :pg#${part_size}:og#${offset}" >>/etc/disktab
                echo ":tg=4.2BSD:bg#${blocksize}:fg#${fragsize}:\\" >>/etc/disktab
                offset=`expr $offset + $part_size`
-       elif [ "$hname" = "" ]; then
+       elif [ ! "$hname" ]; then
                hname=$part_name
                echo -n "       :ph#${part_size}:oh#${offset}" >>/etc/disktab
                echo ":th=4.2BSD:bh#${blocksize}:fh#${fragsize}:\\" >>/etc/disktab
                hname=$part_name
                echo -n "       :ph#${part_size}:oh#${offset}" >>/etc/disktab
                echo ":th=4.2BSD:bh#${blocksize}:fh#${fragsize}:\\" >>/etc/disktab
@@ -268,98 +673,143 @@ while [ $part_used -lt $partition ]; do
 done
 
 echo    "      :pd#${disksize}:od#0:" >>/etc/disktab
 done
 
 echo    "      :pd#${disksize}:od#0:" >>/etc/disktab
-cat /etc/disktab
-#No longer provide a disktab.preinstall on the floppy!
-#cat /etc/disktab.preinstall >> /etc/disktab
 sync
 
 sync
 
-echo    ""
-echo    "OK!  THIS IS YOUR LAST CHANCE!!!"
-echo -n "Are you sure you want this stuff installed on your hard drive? (yes/no) "
-answer=""
-while [ "$answer" = "" ]; do
-       read answer
-       case $answer in
-               yes|YES)
-                       echo    ""
-                       echo    "OK!  Here we go..."
+# cat /etc/disktab
+OIFS=$IFS
+IFS='
+'
+while read data; do
+       echo $data
+done < /etc/disktab
+IFS=$OIFS
+
+echo
+echo -n "Verbose installation? [n] "
+read resp
+
+case $resp in
+y*)
+       cpioverbose=v
+       ;;
+*)
+       cpioverbose=
+       ;;
+esac
+
+
+echo
+echo    "OK!  THIS IS THE LAST CHANCE!!!  Data on the hard disk wil be lost."
+echo -n "Are you sure you want to install on the hard drive? (yes/no) "
+resp=""
+while [ ! "$resp" ]; do
+       read resp junk
+       case "$resp" in
+       Yes|yes|YES)
+               verified_install=1
+               echo
+               echo    "OK!  Here we go..."
+               ;;
+       No|no|NO)
+               echo
+               echo -n "Would you like to change the configuration? [y] "
+               read resp junk
+               resp=${resp:-y}
+               case "$resp" in
+               y*|Y*)
                        ;;
                        ;;
-               no|NO)
-                       echo    ""
-                       echo    "OK, then.  enter 'halt' to halt the machine."
+               *)
+                       echo
+                       echo    "OK, then.  Enter 'halt' to halt the machine."
                        echo    "Once the machine has halted, remove the floppy,"
                        echo    "and press any key to reboot."
                        exit
                        ;;
                        echo    "Once the machine has halted, remove the floppy,"
                        echo    "and press any key to reboot."
                        exit
                        ;;
-               *)
-                       echo -n "I want a yes or no answer...  well? "
-                       answer=
-                       ;;
+               esac
+               ;;
+       *)
+               echo "Please spell out either of \`yes' or \`no'..." 
+               echo -n "Install on the hard disk? (yes/no) " 
+               resp=
+               ;;
        esac
 done
        esac
 done
+done   # End of Big Loop
+
+put_fdisk_data
 
 
-echo    ""
+echo
 echo -n "Labelling disk..."
 echo -n "Labelling disk..."
-/sbin/disklabel -w -r $drivename $name /usr/mdec/${drivetype}boot /usr/mdec/boot${drivetype}
+echo y | 
+/sbin/disklabel -w -r ${drivename} $name /usr/mdec/${drivetype}boot /usr/mdec/boot${drivetype} >/dev/null 2>&1
 echo    " done."
 
 if [ "$sect_fwd" = "sf:" ]; then
        echo -n "Initializing bad144 badblock table..."
        bad144 $drivename 0
        echo " done."
 echo    " done."
 
 if [ "$sect_fwd" = "sf:" ]; then
        echo -n "Initializing bad144 badblock table..."
        bad144 $drivename 0
        echo " done."
+       echo "Updating badblock table..."
+       # `2>&1 >/dev/null' filters stdout and leaves only stderr...
+       bad144 -s $drivename 2>&1 >/dev/null |
+       while read data; do
+               bad_seek=`expr $data : '[^(]*(seek)[^0-9]*\([0-9]*\)'`
+               bad_read=`expr $data : '[^(]*(read)[^0-9]*\([0-9]*\)'`
+               [ "$bad_seek" -o "$bad_read" ] && echo -n "$bad_seek $bad_read "
+       done >bad144.out
+       if [ -s bad144.out ]; then
+               read badlist <bad144.out
+               bad144 -a -c $drivename "$badlist"
+               >bad144.out
+       fi
+       echo " done."
 fi
 
 echo    "Initializing root filesystem, and mounting..."
 newfs ${rotdelay} /dev/r${drivename}a $name
 mount -v /dev/${drivename}a /mnt
 if [ "$ename" != "" ]; then
 fi
 
 echo    "Initializing root filesystem, and mounting..."
 newfs ${rotdelay} /dev/r${drivename}a $name
 mount -v /dev/${drivename}a /mnt
 if [ "$ename" != "" ]; then
-       echo    ""
+       echo
        echo    "Initializing $ename filesystem, and mounting..."
        newfs ${rotdelay} /dev/r${drivename}e $name
        mkdir -p /mnt/$ename
        mount -v /dev/${drivename}e /mnt/$ename
 fi
 if [ "$fname" != "" ]; then
        echo    "Initializing $ename filesystem, and mounting..."
        newfs ${rotdelay} /dev/r${drivename}e $name
        mkdir -p /mnt/$ename
        mount -v /dev/${drivename}e /mnt/$ename
 fi
 if [ "$fname" != "" ]; then
-       echo    ""
+       echo
        echo    "Initializing $fname filesystem, and mounting..."
        newfs ${rotdelay} /dev/r${drivename}f $name
        mkdir -p /mnt/$fname
        mount -v /dev/${drivename}f /mnt/$fname
 fi
 if [ "$gname" != "" ]; then
        echo    "Initializing $fname filesystem, and mounting..."
        newfs ${rotdelay} /dev/r${drivename}f $name
        mkdir -p /mnt/$fname
        mount -v /dev/${drivename}f /mnt/$fname
 fi
 if [ "$gname" != "" ]; then
-       echo    ""
+       echo
        echo    "Initializing $gname filesystem, and mounting..."
        newfs ${rotdelay} /dev/r${drivename}g $name
        mkdir -p /mnt/$gname
        mount -v /dev/${drivename}g /mnt/$gname
 fi
 if [ "$hname" != "" ]; then
        echo    "Initializing $gname filesystem, and mounting..."
        newfs ${rotdelay} /dev/r${drivename}g $name
        mkdir -p /mnt/$gname
        mount -v /dev/${drivename}g /mnt/$gname
 fi
 if [ "$hname" != "" ]; then
-       echo    ""
+       echo
        echo    "Initializing $hname filesystem, and mounting..."
        newfs ${rotdelay} /dev/r${drivename}h $name
        mkdir -p /mnt/$hname
        mount -v /dev/${drivename}h /mnt/$hname
 fi
 
        echo    "Initializing $hname filesystem, and mounting..."
        newfs ${rotdelay} /dev/r${drivename}h $name
        mkdir -p /mnt/$hname
        mount -v /dev/${drivename}h /mnt/$hname
 fi
 
-echo    ""
-echo -n "Verbose installation? [n] "
-read resp
-
-echo Copying to disk...
+echo
+echo "Please wait.  Copying to disk..."
 cd /
 cd /
-case $resp in
-       y*)
-               cpioverbose=v
-               ;;
-       *)
-               cpioverbose=
-               ;;
-esac
-
-cat filelist | cpio -pdalmu${cpioverbose} /mnt
+# cat filelist | cpio -pdamu${cpioverbose} /mnt
+OIFS=$IFS
+IFS='
+'
+while read data; do 
+       echo $data
+done <filelist | cpio -pdamu${cpioverbose} /mnt
+IFS=$OIFS
+sync
 
 cd /mnt
 
 cd /mnt
-
 echo "/dev/${drivename}a       /       ufs     rw 1 1" >etc/fstab
 if [ "$ename" != "" ]; then
        echo "/dev/${drivename}e        /$ename ufs     rw 1 2" >>etc/fstab
 echo "/dev/${drivename}a       /       ufs     rw 1 1" >etc/fstab
 if [ "$ename" != "" ]; then
        echo "/dev/${drivename}e        /$ename ufs     rw 1 2" >>etc/fstab
@@ -374,30 +824,69 @@ if [ "$hname" != "" ]; then
        echo "/dev/${drivename}h        /$hname ufs     rw 1 5" >>etc/fstab
 fi
 
        echo "/dev/${drivename}h        /$hname ufs     rw 1 5" >>etc/fstab
 fi
 
-cat << EOF >.profile
-PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/contrib/bin:.:
-export PATH
-HOME=/root
-export HOME
-TERM=pc3
-export TERM
-echo    ""
-echo    "Insert second installation floppy in drive and"
-echo -n "enter that drive's number (e.g. 0 or 1): [0]"
-driveno=0
-read driveno
-mount -o ro /dev/fd\${driveno}a /mnt
-cd /mnt
-install
-EOF
+# cat /etc/disktab >etc/disktab.install
+OIFS=$IFS
+IFS='
+'
+while read data; do
+       echo $data
+done </etc/disktab >etc/disktab.install
+IFS=$OIFS
+
+# cat << EOF >.profile
+(
+echo "PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/contrib/bin:/usr/distbin:.:"
+echo "export PATH"
+echo "HOME=/root"
+echo "export HOME"
+echo "TERM=pc3"
+echo "export TERM"
+echo "mount -at ufs"
+echo "echo" 
+echo "echo    \"Insert second installation floppy in drive and\""
+echo "echo -n \"enter that drive's number (e.g. 0 or 1): [0] \""
+echo "read resp junk"
+echo "driveno=\${resp:-0}"
+echo "mount -o ro /dev/fd\${driveno}a /mnt"
+echo "cd /mnt"
+echo "install"
+echo "cd /"
+echo "umount /mnt >/dev/null 2>&1"
+echo "echo"
+echo "echo    \"Now insert third installation floppy in drive and\""
+echo "echo -n \"enter that drive's number (e.g. 0 or 1): [0] \""
+echo "read resp junk"
+echo "driveno=\${resp:-0}"
+echo "mount -t pcfs -o ro /dev/fd\${driveno}a /mnt"
+echo "mkdir -p /usr/distbin"
+echo "cp /mnt/* /usr/distbin/"
+echo "sync"
+echo "umount /mnt >/dev/null 2>&1"
+echo "echo"
+echo "echo    \"OK.  All of the base files are installed.\""
+echo "echo"
+echo "echo    \"The next step: reboot from the hard disk, and follow\""
+echo "echo    \"more instrutctions.\""
+echo "echo"
+echo "echo    \"To do this, enter 'halt' at the prompt to halt the machine.\""
+echo "echo     \"Once the machine has halted, remove the floppy from the disk\""
+echo "echo     \"drive, and hit any key to reboot from the hard disk.\""
+) >.profile
 
 sync
 
 
 sync
 
-echo    "The next step:  reboot from the kernel copy disk, copy a"
-echo    "kernel to your hard disk (to partition ${drivename}a), then reboot"
-echo    "from the hard disk."
-echo    ""
-echo    "Enter 'halt' to halt the machine."
-echo    "Once the machine has halted, replace the floppy in the disk drive"
-echo    "with the kernel-copy disk that you originally booted from."
-echo    "Once you have done that, press any key to reboot."
+echo
+echo    "The next step:  reboot from the kernel-copy disk, copy a kernel"
+echo    "to the hard disk, and finally reboot from the hard disk."
+echo
+echo    "To do this, enter 'halt' now to halt the machine.  After it"
+echo   "announces that it has halted, remove the floppy from the drive"
+echo   "and insert the kernel-copy disk that was booted before."
+echo   "Press any key to reboot.  When prompted to insert the filesystem"
+echo   "floppy this time, just hit RETURN without changing floppies."
+echo
+echo   "If all goes well, you can enter the command \`copy' at the prompt to"
+echo   "copy the kernel to the hard disk.  When asked for which partition to"
+echo   "copy to, enter  to \`${drivename}a' (without the quotes)."
+echo
+echo   "Okay, that's all for now.  I'm waiting for you to enter \`halt'..."