3 # $NetBSD: install.md,v 1.13 2008/04/30 13:10:48 martin Exp $
5 # Copyright (c) 1996 The NetBSD Foundation, Inc.
8 # This code is derived from software contributed to The NetBSD Foundation
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
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.
20 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
34 # machine dependent section of installation/upgrade script
37 # Machine-dependent install sets
41 if [ ! -z "$TERM" ]; then
44 echo -n "Specify terminal type [hp300h]: "
51 md_makerootwritable
() {
52 # Was: do_mfs_mount "/tmp" "2048"
53 # /tmp is the mount point
54 # 2048 is the size in DEV_BIZE blocks
56 umount
/tmp
> /dev
/null
2>&1
57 if ! mount_mfs
-s 2048 swap
/tmp
; then
58 cat << \__mfs_failed_1
60 FATAL ERROR
: Can
't mount the memory filesystem.
66 # Bleh. Give mount_mfs a chance to DTRT.
71 # return available disk devices
72 dmesg | awk -F : '/^rd
[0-9]*:.
/ { print
$1; }' | sort -u
73 dmesg | awk -F : '/^sd
[0-9]*:.
*sectors
/ { print
$1; }' | sort -u
77 # return available CD-ROM devices
78 dmesg | awk -F : '/^
cd[0-9]*:/ { print
$1; }' | sort -u
82 # return available network interfaces
83 dmesg | awk -F : '/^le
[0-9]*:/ { print
$1; }' | sort -u
89 echo -n "Installing boot block..."
90 /usr/sbin/installboot -v /dev/r${1}c /usr/mdec/uboot.lif
96 awk 'BEGIN
{ es
=1; } /'"$pattern"'/{ es
=0; } END
{ exit es
; }' "$@"
101 awk "/$pattern/"'{ print
; }' "$@"
104 md_checkfordisklabel() {
105 # $1 is the disk to check
107 disklabel -r $1 > /dev/null 2> /tmp/checkfordisklabel
108 if grep_check_q "no disk label" /tmp/checkfordisklabel; then
110 elif grep_check_q "disk label corrupted" /tmp/checkfordisklabel; then
116 rm -f /tmp/checkfordisklabel
119 hp300_init_label_scsi_disk() {
120 # $1 is the disk to label
122 # Name the disks we install in the temporary fstab.
123 if [ "X${_disk_instance}" = "X" ]; then
126 _disk_instance=`expr $_disk_instance + 1`
128 _cur_disk_name="install-disk-${_disk_instance}"
130 # Get geometry information from the user.
131 more << \__scsi_label_1
133 You will need to provide some information about your disk's geometry.
134 Geometry info
for SCSI disks was printed
at boot
time. If that information
135 is not available
, use the information provided
in your disk
's manual.
136 Please note that the geometry printed at boot time is preferred.
138 IMPORTANT NOTE: due to a limitation in the disklabel(8) program, the
139 number of cylinders on the disk will be increased by 1 so that the initial
140 label can be placed on disk for editing. When the disklabel editor appears,
141 make absolutely certain you subtract 1 from the total number of cylinders,
142 and adjust the size of partition 'c
' such that:
144 size = (sectors per track) * (tracks per cyl) * (total cylinders)
146 Note that the disklabel editor will be run twice; once to set the size of
147 partition 'c
' and correct the geometry, and again so that you may correctly
148 edit the partition map. This is to work around the afore mentioned
149 limitation in disklabel(8). Apologies offered in advance.
153 # Give the opportunity to review the boot messages.
154 echo -n "Review boot messages now? [y] "
158 (echo ""; dmesg; echo "") | more
166 echo -n "Number of bytes per disk sector? [512] "
170 resp="" # force one iteration
171 while [ "X${resp}" = "X" ]; do
172 echo -n "Number of cylinders? "
176 _fudge_cyl=`expr $_cylinders + 1`
178 resp="" # force one iteration
179 while [ "X${resp}" = "X" ]; do
180 echo -n "Number of tracks (heads)? "
183 _tracks_per_cyl="$resp"
185 resp="" # force one iteration
186 while [ "X${resp}" = "X" ]; do
187 echo -n "Number of disk sectors (blocks)? "
192 # Calculate some values we need.
193 _sec_per_cyl=`expr $_nsectors / $_cylinders`
194 _sec_per_track=`expr $_sec_per_cyl / $_tracks_per_cyl`
195 _new_c_size=`expr $_sec_per_track \* $_tracks_per_cyl \* $_cylinders`
197 # Emit a disktab entry, suitable for getting started.
198 # What we have is a `c' partition with the total number of
199 # blocks, and an `a' partition with 1 sector; just large enough
200 # to open. Don't ask.
201 echo "" >> /etc
/disktab
202 echo "# Created by install" >> /etc
/disktab
203 echo "${_cur_disk_name}:\\" >> /etc
/disktab
204 echo -n " :ty=winchester:ns#${_sec_per_track}:" >> /etc
/disktab
205 echo "nt#${_tracks_per_cyl}:nc#${_fudge_cyl}:\\" >> /etc
/disktab
206 echo " :pa#1:\\" >> /etc
/disktab
207 echo " :pc#${_nsectors}:" >> /etc
/disktab
209 # Ok, here's what we need to do. First of all, we install
210 # this initial label by opening the `c' partition of the disk
211 # and using the `-r' flag for disklabel(8). However, because
212 # of limitations in disklabel(8), we've had to fudge the number
213 # of cylinders up 1 so that disklabel(8) doesn't complain about
214 # `c' running past the end of the disk, which can be quite
215 # common even with OEM HP drives! So, we've given ourselves
216 # an `a' partition, which is the minimum needed to open the disk
217 # so that we can perform the DIOCWDLABEL ioctl. So, once the
218 # initial label is installed, we open the `a' partition so that
219 # we can fix up the number of cylinders and make the size of
220 # `c' come out to (ncyl * ntracks_per_cyl * nsec_per_track).
221 # After that's done, we re-open `c' and let the user actually
222 # edit the partition table. It's horrible, I know. Bleh.
225 if ! disklabel
-w -r ${1} ${_cur_disk_name}; then
227 echo "ERROR: can't bootstrap disklabel!"
233 echo "The disklabel editor will now start. During this phase, you"
234 echo "must reset the 'cylinders' value to ${_cylinders}, and adjust"
235 echo "the size of partition 'c' to ${_new_c_size}. Do not modify"
236 echo "the partition map at this time. You will have the opportunity"
237 echo "to do so in a moment."
239 echo -n "Press <return> to continue. "
243 if ! disklabel
-e /dev
/r
${1}a
; then
245 echo "ERROR: can't fixup geometry!"
250 cat << \__explain_motives_2
252 Now that you have corrected the geometry of your disk
, you may edit the
253 partition map. Don
't forget to fill in the fsize (frag size), bsize
254 (filesystem block size), and cpg (cylinders per group) values. If you
255 are unsure what these should be, use:
262 echo -n "Press <return> to continue. "
269 hp300_init_label_hpib_disk() {
270 # $1 is the disk to label
272 # We look though the boot messages attempting to find
273 # the model number for the provided disk.
275 if dmesg | grep_check_q "${1}: "; then
276 _hpib_disktype=HP`dmesg | plain_grep "${1}: " | sort -u | \
279 if [ "X${_hpib_disktype}" = "X" ]; then
281 echo "ERROR: $1 doesn't appear to exist?
!"
286 # Peer through /etc/disktab to see if the disk has a "default
"
287 # layout. If it doesn't, we have to treat it like a SCSI disk;
288 # i.e. prompt for geometry, and create a default to place
290 if ! grep_check_q "${_hpib_disktype}[:|
]" /etc/disktab; then
292 echo "WARNING
: can
't find defaults for $1 ($_hpib_disktype)"
294 hp300_init_label_scsi_disk $1
298 # We've found the defaults. Now use them to place an initial
299 # disklabel on the disk.
300 # XXX What kind of ugliness to we have to deal with to get around
301 # XXX stupidity on the part of disklabel semantics?
303 if ! disklabel
-r -w ${1} $_hpib_disktype; then
304 # Error message displayed by disklabel(8)
306 echo "ERROR: can't install default label!"
308 echo -n "Try a different method? [y] "
312 hp300_init_label_scsi_disk
$1
328 # $1 is the disk to label
330 # Check to see if there is a disklabel present on the device.
331 # If so, we can just edit it. If not, we must first install
333 md_checkfordisklabel
$1
336 # Go ahead and just edit the disklabel.
342 echo -n "No disklabel present, installing a default for type: "
346 hp300_init_label_hpib_disk
$1
351 hp300_init_label_scsi_disk
$1
355 # Shouldn't happen, but...
356 echo "unknown?! Giving up."
361 # Check to see if installing the default was
362 # successful. If so, go ahead and pop into the
364 if [ "X${rval}" != X
"0" ]; then
365 echo "Sorry, can't label this disk."
370 # We have some defaults installed. Pop into
371 # the disklabel editor.
373 if ! disklabel
-e $1; then
375 echo "ERROR: couldn't set partition map for $1"
381 md_prep_disklabel
() {
382 # $1 is the root disk
384 # Make sure there's a disklabel there. If there isn't, puke after
385 # disklabel prints the error message.
386 md_checkfordisklabel
$1
389 cat << \__md_prep_disklabel_1
391 FATAL ERROR
: There is no disklabel present on the root disk
! You must
392 label the disk with SYS_INST before continuing.
394 __md_prep_disklabel_1
399 cat << \__md_prep_disklabel_2
401 FATAL ERROR
: The disklabel on the root disk is corrupted
! You must
402 re-label the disk with SYS_INST before continuing.
404 __md_prep_disklabel_2
412 # Give the user the opportinuty to edit the root disklabel.
413 cat << \__md_prep_disklabel_3
415 You have already placed a disklabel onto the target root disk.
416 However
, due to the limitations of the standalone program used
417 you may want to edit that label to change partition
type information.
418 You will be given the opporunity to
do that now. Note that you may
419 not change the size or location of any presently open partition.
421 __md_prep_disklabel_3
422 echo -n "Do you wish to edit the root disklabel? [y] "
434 cat << \__md_prep_disklabel_4
436 You will now be given the opportunity to place disklabels on any additional
437 disks on your system.
438 __md_prep_disklabel_4
440 _DKDEVS
=`rmel ${ROOTDISK} ${_DKDEVS}`
441 resp
="X" # force at least one iteration
442 while [ "X$resp" != X
"done" ]; do
448 if [ ! -f /mnt
/netbsd
]; then
449 echo -n "No kernel set extracted. Copying miniroot kernel..."
450 cp -p /netbsd
/mnt
/netbsd
453 cat << __md_copy_kernel_1
455 The INSTALL kernel from the miniroot has been copied to your root disk.
456 It has minimal facilities enabled. The first thing you should do after
457 installation is install an appropriate kernel for your machine (such as
461 echo -n "Press <return> to continue. "
466 # Note, while they might not seem machine-dependent, the
467 # welcome banner and the punt message may contain information
468 # and/or instructions specific to the type of machine.
470 md_welcome_banner
() {
473 echo "Welcome to the NetBSD/hp300 ${VERSION} installation program."
474 cat << \__welcome_banner_1
476 This program is designed to
help you
install NetBSD on your system
in a
477 simple and rational way. You
'll be asked several questions, and it would
478 probably be useful to have your disk's hardware manual
, the installation
479 notes
, and a calculator handy.
481 In particular
, you will need to know some reasonably detailed
482 information about your disk
's geometry. This program can determine
483 some limited information about certain specific types of HP-IB disks.
484 If you have SCSI disks, however, prior knowledge of disk geometry
485 is absolutely essential. The kernel will attempt to display geometry
486 information for SCSI disks during boot, if possible. If you did not
487 make it note of it before, you may wish to reboot and jot down your
488 disk's geometry before proceeding.
490 As with anything
which modifies your hard disk
's contents, this
491 program can cause SIGNIFICANT data loss, and you are advised
492 to make sure your hard drive is backed up before beginning the
493 installation process.
495 Default answers are displyed in brackets after the questions.
496 You can hit Control-C at any time to quit, but if you do so at a
497 prompt, you may have to hit return. Also, quitting in the middle of
498 installation may leave your system in an inconsistent state.
504 md_not_going_to_install() {
505 cat << \__not_going_to_install_1
507 OK, then. Enter 'halt
' at the prompt to halt the machine. Once the
508 machine has halted, power-cycle the system to load new boot code.
510 __not_going_to_install_1
514 cat << \__congratulations_1
516 CONGRATULATIONS! You have successfully installed NetBSD! To boot the
517 installed system, enter halt at the command prompt. Once the system has
518 halted, power-cycle the machine in order to load new boot code. Make sure
519 you boot from the root disk.