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