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