1 #!/bin/sh 2 # $NetBSD: install.sh,v 1.8 2023/03/26 15:08:24 andvar 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 41 DT=/etc/disktab # /etc/disktab 42 FSTABDIR=/mnt/etc # /mnt/etc 43 #DONTDOIT=echo 44 ASYNC="-o async" 45 46 FSTAB=${FSTABDIR}/fstab 47 48 getresp() { 49 read resp 50 if [ "X$resp" = "X" ]; then 51 resp=$1 52 fi 53 } 54 55 echo "Welcome to the original NetBSD/alpha installation program." 56 echo "" 57 echo "This version of the program has been largely replaced by the new 58 echo "sysinst utility. Both programs are on this installation media set. 59 echo -n "Type the return key to continue..." 60 getresp 61 echo "This program is designed to help you put NetBSD on your hard disk," 62 echo "in a simple and rational way. You'll be asked several questions," 63 echo "and it would probably be useful to have your disk's hardware" 64 echo "manual, the installation notes, and a calculator handy." 65 echo "" 66 echo "In particular, you will need to know some reasonably detailed" 67 echo "information about your disk's geometry, because there is currently" 68 echo "no way this program can figure that information out." 69 echo "" 70 echo "As with anything which modifies your hard drive's contents, this" 71 echo "program can cause SIGNIFICANT data loss, and you are advised" 72 echo "to make sure your hard drive is backed up before beginning the" 73 echo "installation process." 74 echo "" 75 echo "Default answers are displayed in brackets after the questions." 76 echo "You can hit Control-C at any time to quit, but if you do so at a" 77 echo "prompt, you may have to hit return. Also, quitting in the middle of" 78 echo "installation may leave your system in an inconsistent state." 79 echo "" 80 echo -n "Proceed with installation? [n] " 81 getresp "n" 82 case "$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 ;; 93 esac 94 95 echo "" 96 echo "To do the installation, you'll need to provide some information about" 97 echo "your disk." 98 echo "" 99 echo "NetBSD can be installed on ST506, ESDI, IDE, or SCSI disks." 100 echo -n "What kind of disk will you be installing on? [SCSI] " 101 getresp "SCSI" 102 case "$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 ;; 126 esac 127 128 # find out what units are possible for that disk, and query the user. 129 driveunits=`echo /dev/${drivetype}?a | sed -e 's,/dev/\(...\)a,\1,g'` 130 if [ "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 136 fi 137 prefdrive=${drivetype}0 138 139 echo "" 140 echo "The following ${drivetype}-type disks are supported by this" 141 echo "installation procedure:" 142 echo " "${driveunits} 143 echo "Note that they may not exist in _your_ machine; the list of" 144 echo "disks in your machine was printed when the system was booting." 145 echo "" 146 while [ "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 158 done 159 160 echo "" 161 echo "Using disk ${drivename}." 162 echo "" 163 echo -n "What kind of disk is it? (one word please) [my${drivetype}] " 164 getresp "my${drivetype}" 165 labelname=$resp 166 167 echo "" 168 echo "You will now need to provide some information about your disk's" 169 echo "geometry. This should either be in the User's Manual for your disk," 170 echo "or you should have written down what NetBSD printed when booting." 171 echo "(Note that he geometry that's printed at boot time is preferred.)" 172 echo "" 173 echo "You may choose to view the initial boot messages for your system" 174 echo "again right now if you like." 175 echo -n "View the boot messages again? [n] " 176 getresp "n" 177 case "$resp" in 178 y*|Y*) 179 dmesg | more 180 ;; 181 *) 182 echo "" 183 ;; 184 esac 185 186 echo "" 187 echo "You will now enter the disk geometry information" 188 echo "" 189 190 echo -n "Number of bytes per disk sector? [512] " 191 getresp 512 192 bytes_per_sect="$resp" 193 194 echo -n "Number of disk cylinders? " 195 getresp 196 cyls_per_disk="$resp" 197 198 echo -n "Number of disk tracks (heads) per disk cylinder? " 199 getresp 200 tracks_per_cyl="$resp" 201 202 echo -n "Number of disk sectors per disk track? " 203 getresp 204 sects_per_track="$resp" 205 206 cylindersize=$(( $sects_per_track * $tracks_per_cyl )) 207 cylbytes=$(( $cylindersize * $bytes_per_sect )) 208 disksize=$(( $cylindersize * $cyls_per_disk )) 209 210 echo "" 211 echo "Your disk has a total of $disksize $bytes_per_sect byte sectors," 212 echo "arranged as $cyls_per_disk cylinders which contain $cylindersize " 213 echo "sectors ($cylbytes bytes) each." 214 echo "" 215 echo "You can specify partition sizes in cylinders ('c') or sectors ('s')." 216 while [ "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 233 done 234 235 if [ $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)." 240 fi 241 242 partition_sects=$disksize 243 partition=$(( $disksize / $sizemult )) 244 part_offset=0 245 246 badspacesec=0 247 if [ "$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" 255 fi 256 257 sects_left=$(( $partition_sects - $badspacesec )) 258 units_left=$(( $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=$(( $root + $badspacesec / $sizemult )) 280 units_left=$(( $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=$(( $root_offset + $root )) 300 part_used=$(( $part_used + $swap )) 301 echo "" 302 303 fragsize=1024 304 blocksize=8192 305 306 echo "# $DT" > $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=$(( $root * $sizemult )) 314 _offset=$(( $root_offset * $sizemult )) 315 echo -n " :pa#${_size}:oa#${_offset}" >> $DT 316 echo ":ta=4.2BSD:ba#${blocksize}:fa#${fragsize}:\\" >> $DT 317 _size=$(( $swap * $sizemult )) 318 _offset=$(( $swap_offset * $sizemult )) 319 echo " :pb#${_size}:ob#${_offset}:tb=swap:\\" >> $DT 320 _size=$(( $partition * $sizemult )) 321 _offset=$(( $part_offset * $sizemult )) 322 echo " :pc#${_size}:oc#${_offset}:\\" >> $DT 323 324 echo "You will now have to enter information about any other partitions" 325 echo "to be created in the NetBSD portion of the disk. This process will" 326 echo "be complete when you've filled up all remaining space in the NetBSD" 327 echo "portion of the disk." 328 329 while [ $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 partition" 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 394 done 395 echo >> $DT 396 sync 397 398 echo "" 399 echo "THIS IS YOUR LAST CHANCE!!!" 400 echo "" 401 echo -n "Are you SURE you want NetBSD installed on your hard drive? (yes/no) " 402 answer="" 403 while [ "$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 423 done 424 425 echo "" 426 echo -n "Labeling disk $drivename..." 427 $DONTDOIT disklabel -w -r $drivename $labelname 428 echo " done." 429 430 if [ "$sect_fwd" = "sf:" ]; then 431 echo -n "Initializing bad144 badblock table..." 432 $DONTDOIT bad144 $drivename 0 433 echo " done." 434 fi 435 436 echo "Initializing root filesystem, and mounting..." 437 $DONTDOIT newfs /dev/r${drivename}a $name 438 $DONTDOIT mount -v $ASYNC /dev/${drivename}a /mnt 439 if [ "$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 445 fi 446 if [ "$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 452 fi 453 if [ "$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 459 fi 460 if [ "$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 466 fi 467 if [ "$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 473 fi 474 475 echo "" 476 echo "Populating filesystems with bootstrapping binaries and config files" 477 $DONTDOIT pax -Xrwpe . /mnt 478 $DONTDOIT cp /tmp/.hdprofile /mnt/.profile 479 480 echo "" 481 echo -n "Creating an fstab..." 482 echo /dev/${drivename}a / ffs rw 1 1 | sed -e s,//,/, > $FSTAB 483 echo /dev/${drivename}b none swap sw 0 0 | sed -e s,//,/, >> $FSTAB 484 if [ "$dname" != "" ]; then 485 echo /dev/${drivename}d /$dname ffs rw 1 2 | sed -e s,//,/, >> $FSTAB 486 fi 487 if [ "$ename" != "" ]; then 488 echo /dev/${drivename}e /$ename ffs rw 1 2 | sed -e s,//,/, >> $FSTAB 489 fi 490 if [ "$fname" != "" ]; then 491 echo /dev/${drivename}f /$fname ffs rw 1 3 | sed -e s,//,/, >> $FSTAB 492 fi 493 if [ "$gname" != "" ]; then 494 echo /dev/${drivename}g /$gname ffs rw 1 4 | sed -e s,//,/, >> $FSTAB 495 fi 496 if [ "$hname" != "" ]; then 497 echo /dev/${drivename}h /$hname ffs rw 1 5 | sed -e s,//,/, >> $FSTAB 498 fi 499 sync 500 echo " done." 501 502 echo "" 503 echo -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 507 echo " done." 508 509 510 echo "" 511 echo "" 512 echo "OK! The preliminary work of setting up your disk is now complete." 513 echo "" 514 echo "The remaining tasks are:" 515 echo "" 516 echo "To load and install the NetBSD distribution sets." 517 echo "Currently the hard drive's root filesystem is mounted on /mnt" 518 echo "" 519 echo "To copy a NetBSD kernel to the hard drive's root filesystem." 520 echo "Once accomplished, you can boot off the hard drive." 521 echo "" 522 echo "Consult the installation notes which will describe how to" 523 echo "install the distribution sets and kernel. Post-installation" 524 echo "configuration is also discussed therein." 525 echo "" 526 echo "GOOD LUCK!" 527 echo "" 528