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