1#!/bin/sh 2# 3# $NetBSD: install.md,v 1.9 2006/06/04 16:52:29 tsutsui Exp $ 4# 5# Copyright (c) 1996 The NetBSD Foundation, Inc. 6# All rights reserved. 7# 8# This code is derived from software contributed to The NetBSD Foundation 9# by Jason R. Thorpe. 10# 11# Redistribution and use in source and binary forms, with or without 12# modification, are permitted provided that the following conditions 13# are met: 14# 1. Redistributions of source code must retain the above copyright 15# notice, this list of conditions and the following disclaimer. 16# 2. Redistributions in binary form must reproduce the above copyright 17# notice, this list of conditions and the following disclaimer in the 18# documentation and/or other materials provided with the distribution. 19# 3. All advertising materials mentioning features or use of this software 20# must display the following acknowledgement: 21# This product includes software developed by the NetBSD 22# Foundation, Inc. and its contributors. 23# 4. Neither the name of The NetBSD Foundation nor the names of its 24# contributors may be used to endorse or promote products derived 25# from this software without specific prior written permission. 26# 27# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37# POSSIBILITY OF SUCH DAMAGE. 38# 39 40# 41# machine dependent section of installation/upgrade script 42# 43 44# Machine-dependent install sets 45MDSETS="" 46 47md_set_term() { 48 if [ ! -z "$TERM" ]; then 49 return 50 fi 51 echo -n "Specify terminal type [hp300h]: " 52 getresp "hp300h" 53 TERM="$resp" 54 export TERM 55 # XXX call tset? 56} 57 58md_makerootwritable() { 59 # Was: do_mfs_mount "/tmp" "2048" 60 # /tmp is the mount point 61 # 2048 is the size in DEV_BIZE blocks 62 63 umount /tmp > /dev/null 2>&1 64 if ! mount_mfs -s 2048 swap /tmp ; then 65 cat << \__mfs_failed_1 66 67FATAL ERROR: Can't mount the memory filesystem. 68 69__mfs_failed_1 70 exit 71 fi 72 73 # Bleh. Give mount_mfs a chance to DTRT. 74 sleep 2 75} 76 77md_get_diskdevs() { 78 # return available disk devices 79 dmesg | awk -F : '/^rd[0-9]*:./ { print $1; }' | sort -u 80 dmesg | awk -F : '/^sd[0-9]*:.*sectors/ { print $1; }' | sort -u 81} 82 83md_get_cddevs() { 84 # return available CD-ROM devices 85 dmesg | awk -F : '/^sd[0-9]*:.*CD-ROM/ { print $1; }' | sort -u 86} 87 88md_get_ifdevs() { 89 # return available network interfaces 90 dmesg | awk -F : '/^le[0-9]*:/ { print $1; }' | sort -u 91} 92 93md_installboot() { 94 # $1 is the root disk 95 96 echo -n "Installing boot block..." 97 disklabel -W ${1} 98 disklabel -B ${1} 99 echo "done." 100} 101 102grep_check_q () { 103 pattern=$1; shift 104 awk 'BEGIN{ es=1; } /'"$pattern"'/{ es=0; } END{ exit es; }' "$@" 105} 106 107plain_grep () { 108 pattern=$1; shift 109 awk "/$pattern/"'{ print; }' "$@" 110} 111 112md_checkfordisklabel() { 113 # $1 is the disk to check 114 115 disklabel -r $1 > /dev/null 2> /tmp/checkfordisklabel 116 if grep_check_q "no disk label" /tmp/checkfordisklabel; then 117 rval="1" 118 elif grep_check_q "disk label corrupted" /tmp/checkfordisklabel; then 119 rval="2" 120 else 121 rval="0" 122 fi 123 124 rm -f /tmp/checkfordisklabel 125} 126 127hp300_init_label_scsi_disk() { 128 # $1 is the disk to label 129 130 # Name the disks we install in the temporary fstab. 131 if [ "X${_disk_instance}" = "X" ]; then 132 _disk_instance="0" 133 else 134 _disk_instance=`expr $_disk_instance + 1` 135 fi 136 _cur_disk_name="install-disk-${_disk_instance}" 137 138 # Get geometry information from the user. 139 more << \__scsi_label_1 140 141You will need to provide some information about your disk's geometry. 142Geometry info for SCSI disks was printed at boot time. If that information 143is not available, use the information provided in your disk's manual. 144Please note that the geometry printed at boot time is preferred. 145 146IMPORTANT NOTE: due to a limitation in the disklabel(8) program, the 147number of cylinders on the disk will be increased by 1 so that the initial 148label can be placed on disk for editing. When the disklabel editor appears, 149make absolutely certain you subtract 1 from the total number of cylinders, 150and adjust the size of partition 'c' such that: 151 152 size = (sectors per track) * (tracks per cyl) * (total cylinders) 153 154Note that the disklabel editor will be run twice; once to set the size of 155partition 'c' and correct the geometry, and again so that you may correctly 156edit the partition map. This is to work around the afore mentioned 157limitation in disklabel(8). Apologies offered in advance. 158 159__scsi_label_1 160 161 # Give the opportunity to review the boot messages. 162 echo -n "Review boot messages now? [y] " 163 getresp "y" 164 case "$resp" in 165 y*|Y*) 166 (echo ""; dmesg; echo "") | more 167 ;; 168 169 *) 170 ;; 171 esac 172 173 echo "" 174 echo -n "Number of bytes per disk sector? [512] " 175 getresp "512" 176 _secsize="$resp" 177 178 resp="" # force one iteration 179 while [ "X${resp}" = "X" ]; do 180 echo -n "Number of cylinders? " 181 getresp "" 182 done 183 _cylinders="$resp" 184 _fudge_cyl=`expr $_cylinders + 1` 185 186 resp="" # force one iteration 187 while [ "X${resp}" = "X" ]; do 188 echo -n "Number of tracks (heads)? " 189 getresp "" 190 done 191 _tracks_per_cyl="$resp" 192 193 resp="" # force one iteration 194 while [ "X${resp}" = "X" ]; do 195 echo -n "Number of disk sectors (blocks)? " 196 getresp "" 197 done 198 _nsectors="$resp" 199 200 # Calculate some values we need. 201 _sec_per_cyl=`expr $_nsectors / $_cylinders` 202 _sec_per_track=`expr $_sec_per_cyl / $_tracks_per_cyl` 203 _new_c_size=`expr $_sec_per_track \* $_tracks_per_cyl \* $_cylinders` 204 205 # Emit a disktab entry, suitable for getting started. 206 # What we have is a `c' partition with the total number of 207 # blocks, and an `a' partition with 1 sector; just large enough 208 # to open. Don't ask. 209 echo "" >> /etc/disktab 210 echo "# Created by install" >> /etc/disktab 211 echo "${_cur_disk_name}:\\" >> /etc/disktab 212 echo -n " :ty=winchester:ns#${_sec_per_track}:" >> /etc/disktab 213 echo "nt#${_tracks_per_cyl}:nc#${_fudge_cyl}:\\" >> /etc/disktab 214 echo " :pa#1:\\" >> /etc/disktab 215 echo " :pc#${_nsectors}:" >> /etc/disktab 216 217 # Ok, here's what we need to do. First of all, we install 218 # this initial label by opening the `c' partition of the disk 219 # and using the `-r' flag for disklabel(8). However, because 220 # of limitations in disklabel(8), we've had to fudge the number 221 # of cylinders up 1 so that disklabel(8) doesn't complain about 222 # `c' running past the end of the disk, which can be quite 223 # common even with OEM HP drives! So, we've given ourselves 224 # an `a' partition, which is the minimum needed to open the disk 225 # so that we can perform the DIOCWDLABEL ioctl. So, once the 226 # initial label is installed, we open the `a' partition so that 227 # we can fix up the number of cylinders and make the size of 228 # `c' come out to (ncyl * ntracks_per_cyl * nsec_per_track). 229 # After that's done, we re-open `c' and let the user actually 230 # edit the partition table. It's horrible, I know. Bleh. 231 232 disklabel -W ${1} 233 if ! disklabel -w -r ${1} ${_cur_disk_name}; then 234 echo "" 235 echo "ERROR: can't bootstrap disklabel!" 236 rval="1" 237 return 238 fi 239 240 echo "" 241 echo "The disklabel editor will now start. During this phase, you" 242 echo "must reset the 'cylinders' value to ${_cylinders}, and adjust" 243 echo "the size of partition 'c' to ${_new_c_size}. Do not modify" 244 echo "the partition map at this time. You will have the opportunity" 245 echo "to do so in a moment." 246 echo "" 247 echo -n "Press <return> to continue. " 248 getresp "" 249 250 disklabel -W ${1} 251 if ! disklabel -e /dev/r${1}a; then 252 echo "" 253 echo "ERROR: can't fixup geometry!" 254 rval="1" 255 return 256 fi 257 258 cat << \__explain_motives_2 259 260Now that you have corrected the geometry of your disk, you may edit the 261partition map. Don't forget to fill in the fsize (frag size), bsize 262(filesystem block size), and cpg (cylinders per group) values. If you 263are unsure what these should be, use: 264 265 fsize: 1024 266 bsize: 4096 267 cpg: 16 268 269__explain_motives_2 270 echo -n "Press <return> to continue. " 271 getresp "" 272 273 rval="0" 274 return 275} 276 277hp300_init_label_hpib_disk() { 278 # $1 is the disk to label 279 280 # We look though the boot messages attempting to find 281 # the model number for the provided disk. 282 _hpib_disktype="" 283 if dmesg | grep_check_q "${1}: "; then 284 _hpib_disktype=HP`dmesg | plain_grep "${1}: " | sort -u | \ 285 awk '{print $2}'` 286 fi 287 if [ "X${_hpib_disktype}" = "X" ]; then 288 echo "" 289 echo "ERROR: $1 doesn't appear to exist?!" 290 rval="1" 291 return 292 fi 293 294 # Peer through /etc/disktab to see if the disk has a "default" 295 # layout. If it doesn't, we have to treat it like a SCSI disk; 296 # i.e. prompt for geometry, and create a default to place 297 # on the disk. 298 if ! grep_check_q "${_hpib_disktype}[:|]" /etc/disktab; then 299 echo "" 300 echo "WARNING: can't find defaults for $1 ($_hpib_disktype)" 301 echo "" 302 hp300_init_label_scsi_disk $1 303 return 304 fi 305 306 # We've found the defaults. Now use them to place an initial 307 # disklabel on the disk. 308 # XXX What kind of ugliness to we have to deal with to get around 309 # XXX stupidity on the part of disklabel semantics? 310 disklabel -W ${1} 311 if ! disklabel -r -w ${1} $_hpib_disktype; then 312 # Error message displayed by disklabel(8) 313 echo "" 314 echo "ERROR: can't install default label!" 315 echo "" 316 echo -n "Try a different method? [y] " 317 getresp "y" 318 case "$resp" in 319 y*|Y*) 320 hp300_init_label_scsi_disk $1 321 return 322 ;; 323 324 *) 325 rval="1" 326 return 327 ;; 328 esac 329 fi 330 331 rval="0" 332 return 333} 334 335md_labeldisk() { 336 # $1 is the disk to label 337 338 # Check to see if there is a disklabel present on the device. 339 # If so, we can just edit it. If not, we must first install 340 # a default label. 341 md_checkfordisklabel $1 342 case "$rval" in 343 0) 344 # Go ahead and just edit the disklabel. 345 disklabel -W $1 346 disklabel -e $1 347 ;; 348 349 *) 350 echo -n "No disklabel present, installing a default for type: " 351 case "$1" in 352 rd*) 353 echo "HP-IB" 354 hp300_init_label_hpib_disk $1 355 ;; 356 357 sd*) 358 echo "SCSI" 359 hp300_init_label_scsi_disk $1 360 ;; 361 362 *) 363 # Shouldn't happen, but... 364 echo "unknown?! Giving up." 365 return; 366 ;; 367 esac 368 369 # Check to see if installing the default was 370 # successful. If so, go ahead and pop into the 371 # disklabel editor. 372 if [ "X${rval}" != X"0" ]; then 373 echo "Sorry, can't label this disk." 374 echo "" 375 return; 376 fi 377 378 # We have some defaults installed. Pop into 379 # the disklabel editor. 380 disklabel -W $1 381 if ! disklabel -e $1; then 382 echo "" 383 echo "ERROR: couldn't set partition map for $1" 384 echo "" 385 fi 386 esac 387} 388 389md_prep_disklabel() { 390 # $1 is the root disk 391 392 # Make sure there's a disklabel there. If there isn't, puke after 393 # disklabel prints the error message. 394 md_checkfordisklabel $1 395 case "$resp" in 396 1) 397 cat << \__md_prep_disklabel_1 398 399FATAL ERROR: There is no disklabel present on the root disk! You must 400label the disk with SYS_INST before continuing. 401 402__md_prep_disklabel_1 403 exit 404 ;; 405 406 2) 407 cat << \__md_prep_disklabel_2 408 409FATAL ERROR: The disklabel on the root disk is corrupted! You must 410re-label the disk with SYS_INST before continuing. 411 412__md_prep_disklabel_2 413 exit 414 ;; 415 416 *) 417 ;; 418 esac 419 420 # Give the user the opportinuty to edit the root disklabel. 421 cat << \__md_prep_disklabel_3 422 423You have already placed a disklabel onto the target root disk. 424However, due to the limitations of the standalone program used 425you may want to edit that label to change partition type information. 426You will be given the opporunity to do that now. Note that you may 427not change the size or location of any presently open partition. 428 429__md_prep_disklabel_3 430 echo -n "Do you wish to edit the root disklabel? [y] " 431 getresp "y" 432 case "$resp" in 433 y*|Y*) 434 disklabel -W $1 435 disklabel -e $1 436 ;; 437 438 *) 439 ;; 440 esac 441 442 cat << \__md_prep_disklabel_4 443 444You will now be given the opportunity to place disklabels on any additional 445disks on your system. 446__md_prep_disklabel_4 447 448 _DKDEVS=`rmel ${ROOTDISK} ${_DKDEVS}` 449 resp="X" # force at least one iteration 450 while [ "X$resp" != X"done" ]; do 451 labelmoredisks 452 done 453} 454 455md_copy_kernel() { 456 echo -n "Copying kernel..." 457 cp -p /netbsd /mnt/netbsd 458 echo "done." 459 460 cat << __md_copy_kernel_1 461 462The INSTALL kernel from the miniroot has been copied to your root disk. 463It has minimal facilities enabled. The first thing you should do after 464installation is install an appropriate kernel for your machine (such as 465the GENERIC kernel). 466 467__md_copy_kernel_1 468 echo -n "Press <return> to continue. " 469 getresp "" 470} 471 472 # Note, while they might not seem machine-dependent, the 473 # welcome banner and the punt message may contain information 474 # and/or instructions specific to the type of machine. 475 476md_welcome_banner() { 477( 478 echo "" 479 echo "Welcome to the NetBSD/hp300 ${VERSION} installation program." 480 cat << \__welcome_banner_1 481 482This program is designed to help you install NetBSD on your system in a 483simple and rational way. You'll be asked several questions, and it would 484probably be useful to have your disk's hardware manual, the installation 485notes, and a calculator handy. 486 487In particular, you will need to know some reasonably detailed 488information about your disk's geometry. This program can determine 489some limited information about certain specific types of HP-IB disks. 490If you have SCSI disks, however, prior knowledge of disk geometry 491is absolutely essential. The kernel will attempt to display geometry 492information for SCSI disks during boot, if possible. If you did not 493make it note of it before, you may wish to reboot and jot down your 494disk's geometry before proceeding. 495 496As with anything which modifies your hard disk's contents, this 497program can cause SIGNIFICANT data loss, and you are advised 498to make sure your hard drive is backed up before beginning the 499installation process. 500 501Default answers are displyed in brackets after the questions. 502You can hit Control-C at any time to quit, but if you do so at a 503prompt, you may have to hit return. Also, quitting in the middle of 504installation may leave your system in an inconsistent state. 505 506__welcome_banner_1 507) | more 508} 509 510md_not_going_to_install() { 511 cat << \__not_going_to_install_1 512 513OK, then. Enter 'halt' at the prompt to halt the machine. Once the 514machine has halted, power-cycle the system to load new boot code. 515 516__not_going_to_install_1 517} 518 519md_congrats() { 520 cat << \__congratulations_1 521 522CONGRATULATIONS! You have successfully installed NetBSD! To boot the 523installed system, enter halt at the command prompt. Once the system has 524halted, power-cycle the machine in order to load new boot code. Make sure 525you boot from the root disk. 526 527__congratulations_1 528} 529 530md_native_fstype() { 531 # Nothing to do. 532} 533 534md_native_fsopts() { 535 # Nothing to do. 536} 537