home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / riscbsd / datafile / misc / inst_12_fs / install < prev   
Encoding:
Text File  |  1996-07-07  |  14.3 KB  |  498 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.1 1996/05/16 19:59:00 mark 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.2
  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    "You may choose to view the initial boot messages for your system"
  167. echo    "again right now if you like."
  168. echo -n "View the boot messages again? [n] "
  169. getresp "n"
  170. case "$resp" in
  171.     y*|Y*)
  172.         more /kern/msgbuf
  173.         ;;
  174.     *)
  175.         echo    ""
  176.         ;;
  177. esac
  178.  
  179. echo    ""
  180. echo    "You will now enter the disk geometry information"
  181. echo    ""
  182.  
  183. echo -n    "Number of bytes per disk sector? [512] "
  184. getresp 512
  185. bytes_per_sect="$resp"
  186.  
  187. echo -n "Number of disk cylinders? "
  188. getresp
  189. cyls_per_disk="$resp"
  190.  
  191. echo -n    "Number of disk tracks (heads) per disk cylinder? "
  192. getresp
  193. tracks_per_cyl="$resp"
  194.  
  195. echo -n    "Number of disk sectors per disk track? "
  196. getresp
  197. sects_per_track="$resp"
  198.  
  199. cylindersize=`expr $sects_per_track \* $tracks_per_cyl`
  200. cylbytes=`expr $cylindersize \* $bytes_per_sect`
  201. disksize=`expr $cylindersize \* $cyls_per_disk`
  202.  
  203. echo    ""
  204. echo    "Your disk has a total of $disksize $bytes_per_sect byte sectors,"
  205. echo    "arranged as $cyls_per_disk cylinders which contain $cylindersize "
  206. echo    "sectors ($cylbytes bytes) each."
  207. echo    ""
  208. echo    "You can specify partition sizes in cylinders ('c') or sectors ('s')."
  209. while [ "X${sizemult}" = "X" ]; do
  210.     echo -n    "What units would you like to use? [cylinders] "
  211.     getresp cylinders
  212.     case "$resp" in
  213.         c*|C*)
  214.             sizemult=$cylindersize
  215.             sizeunit="cylinders"
  216.             ;;
  217.         s*|S*)
  218.             sizemult=1
  219.             sizeunit="sectors"
  220.             ;;
  221.         *)
  222.             echo    ""
  223.             echo    "Enter cylinders ('c') or sectors ('s')."
  224.             ;;
  225.     esac
  226. done
  227.  
  228. if [ $sizeunit = "sectors" ]; then
  229.     echo    ""
  230.     echo    "For best disk performance, partitions should begin and end on"
  231.     echo    "cylinder boundaries.  Wherever possible, pick sizes that are"
  232.     echo    "multiples of the cylinder size ($cylindersize sectors)."
  233. fi
  234.  
  235. echo -n ""
  236. echo -n "Size of NetBSD portion of disk (in $sizeunit)? "
  237. getresp
  238. partition=$resp
  239. partition_sects=`expr $resp \* $sizemult`
  240. part_offset=0
  241. if [ $partition_sects -lt $disksize ]; then
  242.     echo -n "Offset of NetBSD portion of disk (in $sizeunit)? "
  243.     getresp
  244.     part_offset=$resp
  245. fi
  246. badspacesec=0
  247. if [ "$sect_fwd" = "sf:" ]; then
  248.     badspacecyl=`expr $sects_per_track + 126`
  249.     badspacecyl=`expr $badspacecyl + $cylindersize - 1`
  250.     badspacecyl=`expr $badspacecyl / $cylindersize`
  251.     badspacesec=`expr $badspacecyl \* $cylindersize`
  252.     echo    ""
  253.     echo -n "Using $badspacesec sectors ($badspacecyl cylinders) for the "
  254.     echo    "bad144 bad block table"
  255. fi
  256.  
  257. sects_left=`expr $partition_sects - $badspacesec`
  258. units_left=`expr $sects_left / $sizemult`
  259. echo    ""
  260. echo    "There are $units_left $sizeunit left to allocate."
  261. echo    ""
  262. root=0
  263. while [ $root -eq 0 ]; do
  264.     echo -n "Root partition size (in $sizeunit)? "
  265.     getresp
  266.     case $resp in
  267.         [1-9]*)
  268.             total=$resp
  269.             if [ $total -gt $units_left ]; then
  270.                 echo -n    "Root size is greater than remaining "
  271.                 echo    "free space on disk."
  272.             else
  273.                 root=$resp
  274.             fi
  275.             ;;
  276.     esac
  277. done
  278. root_offset=$part_offset
  279. part_used=`expr $root + $badspacesec / $sizemult`
  280. units_left=`expr $partition - $part_used`
  281. echo    ""
  282.  
  283. swap=0
  284. while [ $swap -eq 0 ]; do 
  285.     echo    "$units_left $sizeunit remaining in NetBSD portion of disk."
  286.     echo -n    "Swap partition size (in $sizeunit)? "
  287.     getresp
  288.     case $resp in
  289.         [1-9]*)
  290.             if [ $swap -gt $units_left ]; then
  291.                 echo -n    "Swap size is greater than remaining "
  292.                 echo    "free space on disk."
  293.             else
  294.                 swap=$resp
  295.             fi
  296.             ;;
  297.     esac
  298. done
  299. swap_offset=`expr $root_offset + $root`
  300. part_used=`expr $part_used + $swap`
  301. echo    ""
  302.  
  303. fragsize=1024
  304. blocksize=8192
  305. $DONTDOIT mount -u /dev/rd0 /
  306. cat /etc/disktab.preinstall > $DT
  307. echo    "" >> $DT
  308. echo    "$labelname|NetBSD installation generated:\\" >> $DT
  309. echo    "    :dt=${type}:ty=winchester:\\" >> $DT
  310. echo -n    "    :nc#${cyls_per_disk}:ns#${sects_per_track}" >> $DT
  311. echo    ":nt#${tracks_per_cyl}:\\" >> $DT
  312. echo    "    :se#${bytes_per_sect}:${sect_fwd}\\" >> $DT
  313. _size=`expr $root \* $sizemult`
  314. _offset=`expr $root_offset \* $sizemult`
  315. echo -n    "    :pa#${_size}:oa#${_offset}" >> $DT
  316. echo    ":ta=4.2BSD:ba#${blocksize}:fa#${fragsize}:\\" >> $DT
  317. _size=`expr $swap \* $sizemult`
  318. _offset=`expr $swap_offset \* $sizemult`
  319. echo    "    :pb#${_size}:ob#${_offset}:tb=swap:\\" >> $DT
  320. _size=`expr $partition \* $sizemult`
  321. echo    "    :pd#${_size}:od#0:\\" >> $DT
  322.  
  323. echo    "You will now have to enter information about any other partitions"
  324. echo    "to be created in the NetBSD portion of the disk.  This process will"
  325. echo    "be complete when you've filled up all remaining space in the NetBSD"
  326. echo    "portion of the disk."
  327.  
  328. while [ $part_used -lt $partition ]; do
  329.     part_size=0
  330.     units_left=`expr $partition - $part_used`
  331.     while [ $part_size -eq 0 ]; do
  332.         echo    ""
  333.         echo -n    "$units_left $sizeunit remaining in NetBSD portion of "
  334.         echo    "the disk"
  335.         echo -n "Next partition size (in $sizeunit)? "
  336.         getresp
  337.         case $resp in
  338.             [1-9]*)
  339.                 total=`expr $part_used + $resp`
  340.                 if [ $total -gt $partition ]; then
  341.                     echo -n    "That would make the parition"
  342.                     echo    "too large to fit!"
  343.                 else
  344.                     part_size=$resp
  345.                     part_used=$total
  346.                     part_name=""
  347.                     while [ "$part_name" = "" ]; do
  348.                         echo -n "Mount point? "
  349.                         getresp
  350.                         part_name=$resp
  351.                     done
  352.                 fi
  353.                 ;;
  354.         esac
  355.     done
  356.     if [ "$ename" = "" ]; then
  357.         ename=$part_name
  358.         offset=`expr $part_offset + $root + $swap`
  359.         _size=`expr $part_size \* $sizemult`
  360.         _offset=`expr $offset \* $sizemult`
  361.         echo -n "    :pe#${_size}:oe#${_offset}" >> $DT
  362.         echo ":te=4.2BSD:be#${blocksize}:fe#${fragsize}:\\" >> $DT
  363.         offset=`expr $offset + $part_size`
  364.     elif [ "$fname" = "" ]; then
  365.         fname=$part_name
  366.         _size=`expr $part_size \* $sizemult`
  367.         _offset=`expr $offset \* $sizemult`
  368.         echo -n "    :pf#${_size}:of#${_offset}" >> $DT
  369.         echo ":tf=4.2BSD:bf#${blocksize}:ff#${fragsize}:\\" >> $DT
  370.         offset=`expr $offset + $part_size`
  371.     elif [ "$gname" = "" ]; then
  372.         gname=$part_name
  373.         _size=`expr $part_size \* $sizemult`
  374.         _offset=`expr $offset \* $sizemult`
  375.         echo -n "    :pg#${_size}:og#${_offset}" >> $DT
  376.         echo ":tg=4.2BSD:bg#${blocksize}:fg#${fragsize}:\\" >> $DT
  377.         offset=`expr $offset + $part_size`
  378.     elif [ "$hname" = "" ]; then
  379.         hname=$part_name
  380.         _size=`expr $part_size \* $sizemult`
  381.         _offset=`expr $offset \* $sizemult`
  382.         echo -n "    :ph#${_size}:oh#${_offset}" >> $DT
  383.         echo ":th=4.2BSD:bh#${blocksize}:fh#${fragsize}:\\" >> $DT
  384.         part_used=$partition
  385.     fi
  386. done
  387. echo    "    :pc#${disksize}:oc#0:" >> $DT
  388. sync
  389.  
  390. echo    ""
  391. echo    "THIS IS YOUR LAST CHANCE!!!"
  392. echo    ""
  393. echo -n    "Are you SURE you want NetBSD installed on your hard drive? (yes/no) "
  394. answer=""
  395. while [ "$answer" = "" ]; do
  396.     getresp
  397.     case $resp in
  398.         yes|YES)
  399.             echo    ""
  400.             echo    "Here we go..."
  401.             answer=yes
  402.             ;;
  403.         no|NO)
  404.             echo    ""
  405.             echo -n    "OK, then.  enter 'halt' to halt the machine.  "
  406.             exit
  407.             ;;
  408.         *)
  409.             echo -n "I want a yes or no answer...  well? "
  410.             ;;
  411.     esac
  412. done
  413.  
  414. echo    ""
  415. echo -n    "Labeling disk $drivename..."
  416. $DONTDOIT disklabel -w -r $drivename $labelname
  417. echo    " done."
  418.  
  419. if [ "$sect_fwd" = "sf:" ]; then
  420.     echo -n "Initializing bad144 badblock table..."
  421.     $DONTDOIT bad144 $drivename 0
  422.     echo " done."
  423. fi
  424.  
  425. echo    "Initializing root filesystem, and mounting..."
  426. $DONTDOIT newfs /dev/r${drivename}a $name
  427. $DONTDOIT mount -v /dev/${drivename}a /mnt
  428. if [ "$ename" != "" ]; then
  429.     echo    ""
  430.     echo    "Initializing $ename filesystem, and mounting..."
  431.     $DONTDOIT newfs /dev/r${drivename}e $name
  432.     $DONTDOIT mkdir -p /mnt/$ename
  433.     $DONTDOIT mount -v /dev/${drivename}e /mnt/$ename
  434. fi
  435. if [ "$fname" != "" ]; then
  436.     echo    ""
  437.     echo    "Initializing $fname filesystem, and mounting..."
  438.     $DONTDOIT newfs /dev/r${drivename}f $name
  439.     $DONTDOIT mkdir -p /mnt/$fname
  440.     $DONTDOIT mount -v /dev/${drivename}f /mnt/$fname
  441. fi
  442. if [ "$gname" != "" ]; then
  443.     echo    ""
  444.     echo    "Initializing $gname filesystem, and mounting..."
  445.     $DONTDOIT newfs /dev/r${drivename}g $name
  446.     $DONTDOIT mkdir -p /mnt/$gname
  447.     $DONTDOIT mount -v /dev/${drivename}g /mnt/$gname
  448. fi
  449. if [ "$hname" != "" ]; then
  450.     echo    ""
  451.     echo    "Initializing $hname filesystem, and mounting..."
  452.     $DONTDOIT newfs /dev/r${drivename}h $name
  453.     $DONTDOIT mkdir -p /mnt/$hname
  454.     $DONTDOIT mount -v /dev/${drivename}h /mnt/$hname
  455. fi
  456.  
  457. echo    ""
  458. echo    "Populating filesystems with bootstrapping binaries and config files"
  459. $DONTDOIT tar --one-file-system -cf - . | (cd /mnt ; tar --unlink -xpf - )
  460. $DONTDOIT cp /tmp/.hdprofile /mnt/.profile
  461.  
  462. echo    ""
  463. echo -n    "Creating an fstab..."
  464. echo /dev/${drivename}a / ffs rw 1 1 | sed -e s,//,/, > $FSTAB
  465. if [ "$ename" != "" ]; then
  466.     echo /dev/${drivename}e /$ename ffs rw 1 2 | sed -e s,//,/, >> $FSTAB
  467. fi
  468. if [ "$fname" != "" ]; then
  469.     echo /dev/${drivename}f /$fname ffs rw 1 3 | sed -e s,//,/, >> $FSTAB
  470. fi
  471. if [ "$gname" != "" ]; then
  472.     echo /dev/${drivename}g /$gname ffs rw 1 4 | sed -e s,//,/, >> $FSTAB
  473. fi
  474. if [ "$hname" != "" ]; then
  475.     echo /dev/${drivename}h /$hname ffs rw 1 5 | sed -e s,//,/, >> $FSTAB
  476. fi
  477. sync
  478. echo    " done."
  479.  
  480. echo    ""
  481. echo    ""
  482. echo    "OK!  The preliminary work of setting up your disk is now complete."
  483. echo     ""
  484. echo    "The remaining tasks are:"
  485. echo    ""
  486. echo    "To copy a NetBSD kernel to the hard drive's root filesystem."
  487. echo    "Once accomplished, you can boot off the hard drive."
  488. echo    ""
  489. echo    "To load and install the NetBSD distribution sets."
  490. echo    "Currently the hard drive's root filesystem is mounted on /mnt"
  491. echo    ""
  492. echo    "Consult the installation notes which will describe how to"
  493. echo    "install the distribution sets and kernel.  Post-installation"
  494. echo    "configuration is also discussed therein."
  495. echo    ""
  496. echo    "GOOD LUCK!"
  497. echo    ""
  498.