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