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