home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / riscbsd / 1_1_beta / inst_11_fs / inst-11.fs / install < prev   
Encoding:
Text File  |  1995-12-08  |  14.0 KB  |  481 lines

  1. #!/bin/sh
  2. #
  3. # Copyright (c) 1994 Christopher G. Demetriou
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. #    notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions and the following disclaimer in the
  13. #    documentation and/or other materials provided with the distribution.
  14. # 3. All advertising materials mentioning features or use of this software
  15. #    must display the following acknowledgement:
  16. #    This product includes software developed by Christopher G. Demetriou.
  17. # 4. The name of the author may not be used to endorse or promote products
  18. #    derived from this software without specific prior written permission
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  21. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  22. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #
  31. #    $Id: install.sh,v 1.5 1995/10/30 02:14:04 tls Exp $
  32.  
  33. #    NetBSD installation script.
  34. #    In a perfect world, this would be a nice C program, with a reasonable
  35. #    user interface.
  36.  
  37. stty erase ^H
  38.  
  39. DT=/etc/disktab                # /etc/disktab
  40. FSTABDIR=/mnt/etc            # /mnt/etc
  41. #DONTDOIT=echo
  42.  
  43. VERSION=1.1
  44. FSTAB=${FSTABDIR}/fstab
  45.  
  46. getresp() {
  47.     read resp
  48.     if [ "X$resp" = "X" ]; then
  49.         resp=$1
  50.     fi
  51. }
  52.  
  53. echo    "Welcome to the NetBSD ${VERSION} installation program."
  54. echo    ""
  55. echo    "This program is designed to help you put NetBSD on your hard disk,"
  56. echo    "in a simple and rational way.  You'll be asked several questions,"
  57. echo    "and it would probably be useful to have your disk's hardware"
  58. echo    "manual, the installation notes, and a calculator handy."
  59. echo    ""
  60. echo    "In particular, you will need to know some reasonably detailed"
  61. echo    "information about your disk's geometry, because there is currently"
  62. echo    "no way this this program can figure that information out."
  63. echo    ""
  64. echo    "As with anything which modifies your hard drive's contents, this"
  65. echo    "program can cause SIGNIFICANT data loss, and you are advised"
  66. echo    "to make sure your hard drive is backed up before beginning the"
  67. echo    "installation process."
  68. echo    ""
  69. echo    "Default answers are displyed in brackets after the questions."
  70. echo    "You can hit Control-C at any time to quit, but if you do so at a"
  71. echo    "prompt, you may have to hit return.  Also, quitting in the middle of"
  72. echo    "installation may leave your system in an inconsistent state."
  73. echo    ""
  74. echo -n "Proceed with installation? [n] "
  75. getresp "n"
  76. case "$resp" in
  77.     y*|Y*)
  78.         echo    "Cool!  Let's get to it..."
  79.         ;;
  80.     *)
  81.         echo    ""
  82.         echo    "OK, then.  Enter 'halt' at the prompt to halt the"
  83.         echo    "machine."
  84.         exit
  85.         ;;
  86. esac
  87.  
  88. echo    ""
  89. echo    "To do the installation, you'll need to provide some information about"
  90. echo    "your disk."
  91. echo    ""
  92. echo    "NetBSD can be installed on ST506, ESDI, IDE, or SCSI disks."
  93. echo -n    "What kind of disk will you be installing on? [IDE] "
  94. getresp "IDE"
  95. case "$resp" in
  96.     esdi|ESDI|st506|ST506)
  97.         drivetype=wd
  98.         echo -n "Does it support _automatic_ sector remapping? [y] "
  99.         getresp "y"
  100.         case "$resp" in
  101.             n*|N*)
  102.                 sect_fwd="sf:"
  103.                 ;;
  104.             *)
  105.                 sect_fwd=""
  106.                 ;;
  107.         esac
  108.         ;;
  109.     ide|IDE)
  110.         drivetype=wd
  111.         sect_fwd=""
  112.         type=ST506
  113.         ;;
  114.     scsi|SCSI)
  115.         drivetype=sd
  116.         sect_fwd=""
  117.         type=SCSI
  118.         ;;
  119. esac
  120.  
  121. # find out what units are possible for that disk, and query the user.
  122. driveunits=`ls /dev/${drivetype}?a | sed -e 's,/dev/\(...\)a,\1,g'`
  123. if [ "X${driveunits}" = "X" ]; then
  124.     echo    "FATAL ERROR:"
  125.     echo    "No devices for disks of type '${drivetype}'."
  126.     echo    "This is probably a bug in the install disks."
  127.     echo    "Exiting install program."
  128.     exit
  129. fi
  130. prefdrive=${drivetype}0
  131.  
  132. echo    ""
  133. echo    "The following ${drivetype}-type disks are supported by this"
  134. echo    "installation procedure:"
  135. echo    "    "${driveunits}
  136. echo    "Note that they may not exist in _your_ machine; the list of"
  137. echo    "disks in your machine was printed when the system was booting."
  138. echo    ""
  139. while [ "X${drivename}" = "X" ]; do
  140.     echo -n    "Which disk would like to install on? [${prefdrive}] "
  141.     getresp ${prefdrive}
  142.     otherdrives=`echo "${driveunits}" | sed -e s,${resp},,`
  143.     if [ "X${driveunits}" = "X${otherdrives}" ]; then
  144.         echo    ""
  145.         echo    "\"${resp}\" is an invalid drive name.  Valid choices"
  146.         echo    "are: "${driveunits}
  147.         echo    ""
  148.     else
  149.         drivename=${resp}
  150.     fi
  151. done
  152.  
  153. echo    ""
  154. echo    "Using disk ${drivename}."
  155. echo    ""
  156. echo -n    "What kind of disk is it? (one word please) [my${drivetype}] "
  157. getresp "my${drivetype}"
  158. labelname=$resp
  159.  
  160. echo    ""
  161. echo    "You will now need to provide some information about your disk's"
  162. echo    "geometry.  This should either be in the User's Manual for your disk,"
  163. echo    "or you should have written down what NetBSD printed when booting."
  164. echo    "(Note that he geometry that's printed at boot time is preferred.)"
  165. echo    ""
  166. echo -n    "Number of bytes per disk sector? [512] "
  167. getresp 512
  168. bytes_per_sect="$resp"
  169.  
  170. echo -n "Number of disk cylinders? "
  171. getresp
  172. cyls_per_disk="$resp"
  173.  
  174. echo -n    "Number of disk tracks (heads) per disk cylinder? "
  175. getresp
  176. tracks_per_cyl="$resp"
  177.  
  178. echo -n    "Number of disk sectors per disk track? "
  179. getresp
  180. sects_per_track="$resp"
  181.  
  182. cylindersize=`expr $sects_per_track \* $tracks_per_cyl`
  183. cylbytes=`expr $cylindersize \* $bytes_per_sect`
  184. disksize=`expr $cylindersize \* $cyls_per_disk`
  185.  
  186. echo    ""
  187. echo    "Your disk has a total of $disksize $bytes_per_sect byte sectors,"
  188. echo    "arranged as $cyls_per_disk cylinders which contain $cylindersize "
  189. echo    "sectors ($cylbytes bytes) each."
  190. echo    ""
  191. echo    "You can specify partition sizes in cylinders ('c') or sectors ('s')."
  192. while [ "X${sizemult}" = "X" ]; do
  193.     echo -n    "What units would you like to use? [cylinders] "
  194.     getresp cylinders
  195.     case "$resp" in
  196.         c*|C*)
  197.             sizemult=$cylindersize
  198.             sizeunit="cylinders"
  199.             ;;
  200.         s*|S*)
  201.             sizemult=1
  202.             sizeunit="sectors"
  203.             ;;
  204.         *)
  205.             echo    ""
  206.             echo    "Enter cylinders ('c') or sectors ('s')."
  207.             ;;
  208.     esac
  209. done
  210.  
  211. if [ $sizeunit = "sectors" ]; then
  212.     echo    ""
  213.     echo    "For best disk performance, partitions should begin and end on"
  214.     echo    "cylinder boundaries.  Wherever possible, pick sizes that are"
  215.     echo    "multiples of the cylinder size ($cylindersize sectors)."
  216. fi
  217.  
  218. echo -n ""
  219. echo -n "Size of NetBSD portion of disk (in $sizeunit)? "
  220. getresp
  221. partition=$resp
  222. partition_sects=`expr $resp \* $sizemult`
  223. part_offset=0
  224. if [ $partition_sects -lt $disksize ]; then
  225.     echo -n "Offset of NetBSD portion of disk (in $sizeunit)? "
  226.     getresp
  227.     part_offset=$resp
  228. fi
  229. badspacesec=0
  230. if [ "$sect_fwd" = "sf:" ]; then
  231.     badspacecyl=`expr $sects_per_track + 126`
  232.     badspacecyl=`expr $badspacecyl + $cylindersize - 1`
  233.     badspacecyl=`expr $badspacecyl / $cylindersize`
  234.     badspacesec=`expr $badspacecyl \* $cylindersize`
  235.     echo    ""
  236.     echo -n "Using $badspacesec sectors ($badspacecyl cylinders) for the "
  237.     echo    "bad144 bad block table"
  238. fi
  239.  
  240. sects_left=`expr $partition_sects - $badspacesec`
  241. units_left=`expr $sects_left / $sizemult`
  242. echo    ""
  243. echo    "There are $units_left $sizeunit left to allocate."
  244. echo    ""
  245. root=0
  246. while [ $root -eq 0 ]; do
  247.     echo -n "Root partition size (in $sizeunit)? "
  248.     getresp
  249.     case $resp in
  250.         [1-9]*)
  251.             total=$resp
  252.             if [ $total -gt $units_left ]; then
  253.                 echo -n    "Root size is greater than remaining "
  254.                 echo    "free space on disk."
  255.             else
  256.                 root=$resp
  257.             fi
  258.             ;;
  259.     esac
  260. done
  261. root_offset=$part_offset
  262. part_used=`expr $root + $badspacesec / $sizemult`
  263. units_left=`expr $partition - $part_used`
  264. echo    ""
  265.  
  266. swap=0
  267. while [ $swap -eq 0 ]; do 
  268.     echo    "$units_left $sizeunit remaining in NetBSD portion of disk."
  269.     echo -n    "Swap partition size (in $sizeunit)? "
  270.     getresp
  271.     case $resp in
  272.         [1-9]*)
  273.             if [ $swap -gt $units_left ]; then
  274.                 echo -n    "Swap size is greater than remaining "
  275.                 echo    "free space on disk."
  276.             else
  277.                 swap=$resp
  278.             fi
  279.             ;;
  280.     esac
  281. done
  282. swap_offset=`expr $root_offset + $root`
  283. part_used=`expr $part_used + $swap`
  284. echo    ""
  285.  
  286. fragsize=1024
  287. blocksize=8192
  288. $DONTDOIT mount -u /dev/rd0a /
  289. cat /etc/disktab.preinstall > $DT
  290. echo    "" >> $DT
  291. echo    "$labelname|NetBSD installation generated:\\" >> $DT
  292. echo    "    :dt=${type}:ty=winchester:\\" >> $DT
  293. echo -n    "    :nc#${cyls_per_disk}:ns#${sects_per_track}" >> $DT
  294. echo    ":nt#${tracks_per_cyl}:\\" >> $DT
  295. echo    "    :se#${bytes_per_sect}:${sect_fwd}\\" >> $DT
  296. _size=`expr $root \* $sizemult`
  297. _offset=`expr $root_offset \* $sizemult`
  298. echo -n    "    :pa#${_size}:oa#${_offset}" >> $DT
  299. echo    ":ta=4.2BSD:ba#${blocksize}:fa#${fragsize}:\\" >> $DT
  300. _size=`expr $swap \* $sizemult`
  301. _offset=`expr $swap_offset \* $sizemult`
  302. echo    "    :pb#${_size}:ob#${_offset}:tb=swap:\\" >> $DT
  303. _size=`expr $partition \* $sizemult`
  304. echo    "    :pd#${_size}:od#0:\\" >> $DT
  305.  
  306. echo    "You will now have to enter information about any other partitions"
  307. echo    "to be created in the NetBSD portion of the disk.  This process will"
  308. echo    "be complete when you've filled up all remaining space in the NetBSD"
  309. echo    "portion of the disk."
  310.  
  311. while [ $part_used -lt $partition ]; do
  312.     part_size=0
  313.     units_left=`expr $partition - $part_used`
  314.     while [ $part_size -eq 0 ]; do
  315.         echo    ""
  316.         echo -n    "$units_left $sizeunit remaining in NetBSD portion of "
  317.         echo    "the disk"
  318.         echo -n "Next partition size (in $sizeunit)? "
  319.         getresp
  320.         case $resp in
  321.             [1-9]*)
  322.                 total=`expr $part_used + $resp`
  323.                 if [ $total -gt $partition ]; then
  324.                     echo -n    "That would make the parition"
  325.                     echo    "too large to fit!"
  326.                 else
  327.                     part_size=$resp
  328.                     part_used=$total
  329.                     part_name=""
  330.                     while [ "$part_name" = "" ]; do
  331.                         echo -n "Mount point? "
  332.                         getresp
  333.                         part_name=$resp
  334.                     done
  335.                 fi
  336.                 ;;
  337.         esac
  338.     done
  339.     if [ "$ename" = "" ]; then
  340.         ename=$part_name
  341.         offset=`expr $part_offset + $root + $swap`
  342.         _size=`expr $part_size \* $sizemult`
  343.         _offset=`expr $offset \* $sizemult`
  344.         echo -n "    :pe#${_size}:oe#${_offset}" >> $DT
  345.         echo ":te=4.2BSD:be#${blocksize}:fe#${fragsize}:\\" >> $DT
  346.         offset=`expr $offset + $part_size`
  347.     elif [ "$fname" = "" ]; then
  348.         fname=$part_name
  349.         _size=`expr $part_size \* $sizemult`
  350.         _offset=`expr $offset \* $sizemult`
  351.         echo -n "    :pf#${_size}:of#${_offset}" >> $DT
  352.         echo ":tf=4.2BSD:bf#${blocksize}:ff#${fragsize}:\\" >> $DT
  353.         offset=`expr $offset + $part_size`
  354.     elif [ "$gname" = "" ]; then
  355.         gname=$part_name
  356.         _size=`expr $part_size \* $sizemult`
  357.         _offset=`expr $offset \* $sizemult`
  358.         echo -n "    :pg#${_size}:og#${_offset}" >> $DT
  359.         echo ":tg=4.2BSD:bg#${blocksize}:fg#${fragsize}:\\" >> $DT
  360.         offset=`expr $offset + $part_size`
  361.     elif [ "$hname" = "" ]; then
  362.         hname=$part_name
  363.         _size=`expr $part_size \* $sizemult`
  364.         _offset=`expr $offset \* $sizemult`
  365.         echo -n "    :ph#${_size}:oh#${_offset}" >> $DT
  366.         echo ":th=4.2BSD:bh#${blocksize}:fh#${fragsize}:\\" >> $DT
  367.         part_used=$partition
  368.     fi
  369. done
  370. echo    "    :pc#${disksize}:oc#0:" >> $DT
  371. sync
  372.  
  373. echo    ""
  374. echo    "THIS IS YOUR LAST CHANCE!!!"
  375. echo    ""
  376. echo -n    "Are you SURE you want NetBSD installed on your hard drive? (yes/no) "
  377. answer=""
  378. while [ "$answer" = "" ]; do
  379.     getresp
  380.     case $resp in
  381.         yes|YES)
  382.             echo    ""
  383.             echo    "Here we go..."
  384.             answer=yes
  385.             ;;
  386.         no|NO)
  387.             echo    ""
  388.             echo -n    "OK, then.  enter 'halt' to halt the machine.  "
  389.             exit
  390.             ;;
  391.         *)
  392.             echo -n "I want a yes or no answer...  well? "
  393.             ;;
  394.     esac
  395. done
  396.  
  397. echo    ""
  398. echo -n    "Labeling disk $drivename..."
  399. $DONTDOIT disklabel -w -r $drivename $labelname
  400. echo    " done."
  401.  
  402. if [ "$sect_fwd" = "sf:" ]; then
  403.     echo -n "Initializing bad144 badblock table..."
  404.     $DONTDOIT bad144 $drivename 0
  405.     echo " done."
  406. fi
  407.  
  408. echo    "Initializing root filesystem, and mounting..."
  409. $DONTDOIT newfs /dev/r${drivename}a $name
  410. $DONTDOIT mount -v /dev/${drivename}a /mnt
  411. if [ "$ename" != "" ]; then
  412.     echo    ""
  413.     echo    "Initializing $ename filesystem, and mounting..."
  414.     $DONTDOIT newfs /dev/r${drivename}e $name
  415.     $DONTDOIT mkdir -p /mnt/$ename
  416.     $DONTDOIT mount -v /dev/${drivename}e /mnt/$ename
  417. fi
  418. if [ "$fname" != "" ]; then
  419.     echo    ""
  420.     echo    "Initializing $fname filesystem, and mounting..."
  421.     $DONTDOIT newfs /dev/r${drivename}f $name
  422.     $DONTDOIT mkdir -p /mnt/$fname
  423.     $DONTDOIT mount -v /dev/${drivename}f /mnt/$fname
  424. fi
  425. if [ "$gname" != "" ]; then
  426.     echo    ""
  427.     echo    "Initializing $gname filesystem, and mounting..."
  428.     $DONTDOIT newfs /dev/r${drivename}g $name
  429.     $DONTDOIT mkdir -p /mnt/$gname
  430.     $DONTDOIT mount -v /dev/${drivename}g /mnt/$gname
  431. fi
  432. if [ "$hname" != "" ]; then
  433.     echo    ""
  434.     echo    "Initializing $hname filesystem, and mounting..."
  435.     $DONTDOIT newfs /dev/r${drivename}h $name
  436.     $DONTDOIT mkdir -p /mnt/$hname
  437.     $DONTDOIT mount -v /dev/${drivename}h /mnt/$hname
  438. fi
  439.  
  440. echo    ""
  441. echo    "Populating filesystems with bootstrapping binaries and config files"
  442. $DONTDOIT tar --one-file-system -cf - . | (cd /mnt ; tar --unlink -xpf - )
  443. $DONTDOIT cp /tmp/.hdprofile /mnt/.profile
  444.  
  445. echo    ""
  446. echo -n    "Creating an fstab..."
  447. echo /dev/${drivename}a / ffs rw 1 1 | sed -e s,//,/, > $FSTAB
  448. if [ "$ename" != "" ]; then
  449.     echo /dev/${drivename}e /$ename ffs rw 1 2 | sed -e s,//,/, >> $FSTAB
  450. fi
  451. if [ "$fname" != "" ]; then
  452.     echo /dev/${drivename}f /$fname ffs rw 1 3 | sed -e s,//,/, >> $FSTAB
  453. fi
  454. if [ "$gname" != "" ]; then
  455.     echo /dev/${drivename}g /$gname ffs rw 1 4 | sed -e s,//,/, >> $FSTAB
  456. fi
  457. if [ "$hname" != "" ]; then
  458.     echo /dev/${drivename}h /$hname ffs rw 1 5 | sed -e s,//,/, >> $FSTAB
  459. fi
  460. sync
  461. echo    " done."
  462.  
  463. echo    ""
  464. echo    ""
  465. echo    "OK!  The preliminary work of setting up your disk is now complete."
  466. echo     ""
  467. echo    "The remaining tasks are:"
  468. echo    ""
  469. echo    "To copy a NetBSD kernel to the hard drive's root filesystem."
  470. echo    "Once accomplished, you can boot off the hard drive."
  471. echo    ""
  472. echo    "To load and install the NetBSD distribution sets."
  473. echo    "Currently the hard drive's root filesystem is mounted on /mnt"
  474. echo    ""
  475. echo    "Consult the installation notes which will describe how to"
  476. echo    "install the distribution sets and kernel.  Post-installation"
  477. echo    "configuration is also discussed therein."
  478. echo    ""
  479. echo    "GOOD LUCK!"
  480. echo    ""
  481.