Annotation of src/distrib/miniroot/install.sh, Revision 1.22
1.1 pk 1: #!/bin/sh
1.22 ! pk 2: # $NetBSD: install.sh,v 1.21 1999/10/07 00:07:05 sjg Exp $
1.1 pk 3: #
1.2 thorpej 4: # Copyright (c) 1996 The NetBSD Foundation, Inc.
1.1 pk 5: # All rights reserved.
6: #
1.2 thorpej 7: # This code is derived from software contributed to The NetBSD Foundation
8: # by Jason R. Thorpe.
9: #
1.1 pk 10: # Redistribution and use in source and binary forms, with or without
11: # modification, are permitted provided that the following conditions
12: # are met:
13: # 1. Redistributions of source code must retain the above copyright
14: # notice, this list of conditions and the following disclaimer.
15: # 2. Redistributions in binary form must reproduce the above copyright
16: # notice, this list of conditions and the following disclaimer in the
17: # documentation and/or other materials provided with the distribution.
18: # 3. All advertising materials mentioning features or use of this software
19: # must display the following acknowledgement:
1.2 thorpej 20: # This product includes software developed by the NetBSD
21: # Foundation, Inc. and its contributors.
22: # 4. Neither the name of The NetBSD Foundation nor the names of its
23: # contributors may be used to endorse or promote products derived
24: # from this software without specific prior written permission.
1.1 pk 25: #
1.2 thorpej 26: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1.17 jtc 29: # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1.2 thorpej 31: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36: # POSSIBILITY OF SUCH DAMAGE.
1.1 pk 37: #
38:
39: # NetBSD installation script.
40: # In a perfect world, this would be a nice C program, with a reasonable
41: # user interface.
42:
43: FILESYSTEMS="/tmp/filesystems" # used thoughout
44: FQDN="" # domain name
45:
46: trap "umount /tmp > /dev/null 2>&1" 0
47:
48: MODE="install"
49:
50: # include machine-dependent functions
51: # The following functions must be provided:
1.6 leo 52: # md_copy_kernel() - copy a kernel to the installed disk
1.1 pk 53: # md_get_diskdevs() - return available disk devices
54: # md_get_cddevs() - return available CD-ROM devices
55: # md_get_ifdevs() - return available network interfaces
1.6 leo 56: # md_get_partition_range() - return range of valid partition letters
1.1 pk 57: # md_installboot() - install boot-blocks on disk
1.12 pk 58: # md_labeldisk() - put label on a disk
1.6 leo 59: # md_prep_disklabel() - label the root disk
1.1 pk 60: # md_welcome_banner() - display friendly message
61: # md_not_going_to_install() - display friendly message
62: # md_congrats() - display friendly message
1.5 pk 63: # md_native_fstype() - native filesystem type for disk installs
64: # md_native_fsopts() - native filesystem options for disk installs
1.14 gwr 65: # md_makerootwritable() - make root writable (at least /tmp)
1.6 leo 66:
1.21 sjg 67: # we need to make sure .'s below work if this directory is not in $PATH
68: # dirname may not be available but expr is
69: Mydir=`expr $0 : '^\(.*\)/[^/]*$'`
70: Mydir=`cd ${Mydir:-.}; pwd`
71:
72: # this is the most likely place to find the binary sets
73: # so save them having to type it in
74: Default_sets_dir=$Mydir/../../binary/sets
75:
1.6 leo 76: # include machine dependent subroutines
1.21 sjg 77: . $Mydir/install.md
1.1 pk 78:
79: # include common subroutines
1.21 sjg 80: . $Mydir/install.sub
1.1 pk 81:
1.14 gwr 82: # which sets?
1.20 is 83: THESETS="$ALLSETS $MDSETS"
1.14 gwr 84:
1.1 pk 85: # Good {morning,afternoon,evening,night}.
86: md_welcome_banner
87: echo -n "Proceed with installation? [n] "
88: getresp "n"
89: case "$resp" in
90: y*|Y*)
91: echo "Cool! Let's get to it..."
92: ;;
93: *)
94: md_not_going_to_install
95: exit
96: ;;
97: esac
98:
99: # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
100: ls -l /dev > /dev/null 2>&1
101:
102: # Deal with terminal issues
103: md_set_term
104:
105: # Get timezone info
106: get_timezone
107:
1.14 gwr 108: # Make sure we can write files (at least in /tmp)
109: # This might make an MFS mount on /tmp, or it may
110: # just re-mount the root with read-write enabled.
111: md_makerootwritable
1.1 pk 112:
113: # Install the shadowed disktab file; lets us write to it for temporary
114: # purposes without mounting the miniroot read-write.
115: cp /etc/disktab.shadow /tmp/disktab.shadow
116:
117: while [ "X${ROOTDISK}" = "X" ]; do
118: getrootdisk
119: done
120:
1.9 thorpej 121: # Deal with disklabels, including editing the root disklabel
122: # and labeling additional disks. This is machine-dependent since
123: # some platforms may not be able to provide this functionality.
124: md_prep_disklabel ${ROOTDISK}
1.1 pk 125:
126: # Assume partition 'a' of $ROOTDISK is for the root filesystem. Loop and
127: # get the rest.
128: # XXX ASSUMES THAT THE USER DOESN'T PROVIDE BOGUS INPUT.
129: cat << \__get_filesystems_1
130:
131: You will now have the opportunity to enter filesystem information.
132: You will be prompted for device name and mount point (full path,
133: including the prepending '/' character).
134:
135: Note that these do not have to be in any particular order. You will
136: be given the opportunity to edit the resulting 'fstab' file before
137: any of the filesystems are mounted. At that time you will be able
138: to resolve any filesystem order dependencies.
139:
140: __get_filesystems_1
141:
142: echo "The following will be used for the root filesystem:"
143: echo " ${ROOTDISK}a /"
144:
145: echo "${ROOTDISK}a /" > ${FILESYSTEMS}
146:
147: resp="X" # force at least one iteration
148: while [ "X$resp" != X"done" ]; do
149: echo ""
1.19 is 150: echo -n "Device name? [RETURN if you already entered all devices] "
1.1 pk 151: getresp "done"
152: case "$resp" in
153: done)
154: ;;
155:
156: *)
157: _device_name=`basename $resp`
158:
159: # force at least one iteration
160: _first_char="X"
161: while [ "X${_first_char}" != X"/" ]; do
162: echo -n "Mount point? "
163: getresp ""
164: _mount_point=$resp
165: if [ "X${_mount_point}" = X"/" ]; then
166: # Invalid response; no multiple roots
167: _first_char="X"
168: else
1.3 pk 169: _first_char=`firstchar ${_mount_point}`
1.1 pk 170: fi
171: done
1.4 pk 172: echo "${_device_name} ${_mount_point}" >> ${FILESYSTEMS}
1.1 pk 173: resp="X" # force loop to repeat
174: ;;
175: esac
176: done
177:
1.18 pk 178: # configure swap
179: resp="" # force at least one iteration
180: while [ "X${resp}" = X"" ]; do
181: echo -n "Ok to configure ${ROOTDISK}b as a swap device? [] "
182: getresp ""
183: case "$resp" in
184: y*|Y*)
185: echo "${ROOTDISK}b swap" >> ${FILESYSTEMS}
186: ;;
187: n*|N*)
188: ;;
189: *) ;;
190: esac
191: done
192:
193:
1.1 pk 194: echo ""
195: echo "You have configured the following devices and mount points:"
196: echo ""
197: cat ${FILESYSTEMS}
198: echo ""
199: echo "Filesystems will now be created on these devices. If you made any"
200: echo -n "mistakes, you may edit this now. Edit? [n] "
201: getresp "n"
202: case "$resp" in
203: y*|Y*)
1.5 pk 204: ${EDITOR} ${FILESYSTEMS}
1.1 pk 205: ;;
206: *)
207: ;;
208: esac
209:
210: # Loop though the file, place filesystems on each device.
211: echo "Creating filesystems..."
212: (
1.18 pk 213: while read _device_name _mp; do
214: if [ "$_mp" != "swap" ]; then
215: newfs /dev/r${_device_name}
216: echo ""
217: fi
1.1 pk 218: done
219: ) < ${FILESYSTEMS}
220:
221: # Get network configuration information, and store it for placement in the
222: # root filesystem later.
223: cat << \__network_config_1
224: You will now be given the opportunity to configure the network. This will
225: be useful if you need to transfer the installation sets via FTP or NFS.
226: Even if you choose not to transfer installation sets that way, this
227: information will be preserved and copied into the new root filesystem.
228:
229: Note, enter all symbolic host names WITHOUT the domain name appended.
230: I.e. use 'hostname' NOT 'hostname.domain.name'.
231:
232: __network_config_1
233: echo -n "Configure the network? [y] "
234: getresp "y"
235: case "$resp" in
236: y*|Y*)
237: resp="" # force at least one iteration
1.8 pk 238: if [ -f /etc/myname ]; then
239: resp=`cat /etc/myname`
240: fi
241: echo -n "Enter system hostname: [$resp] "
1.1 pk 242: while [ "X${resp}" = X"" ]; do
1.8 pk 243: getresp "$resp"
1.1 pk 244: done
245: hostname $resp
246: echo $resp > /tmp/myname
247:
248: echo -n "Enter DNS domain name: "
1.22 ! pk 249: getresp "none"
! 250: if [ "X${resp}" != X"none" ]; then
! 251: FQDN=$resp
! 252: fi
1.1 pk 253:
254: configurenetwork
255:
256: echo -n "Enter IP address of default route: [none] "
257: getresp "none"
258: if [ "X${resp}" != X"none" ]; then
259: route delete default > /dev/null 2>&1
260: if route add default $resp > /dev/null ; then
261: echo $resp > /tmp/mygate
262: fi
263: fi
264:
1.22 ! pk 265: resp="none"
! 266: if [ X${FQDN} != X ]; then
! 267: echo -n "Enter IP address of primary nameserver: [none] "
! 268: getresp "none"
! 269: fi
1.1 pk 270: if [ "X${resp}" != X"none" ]; then
271: echo "domain $FQDN" > /tmp/resolv.conf
272: echo "nameserver $resp" >> /tmp/resolv.conf
273: echo "search $FQDN" >> /tmp/resolv.conf
274:
275: echo -n "Would you like to use the nameserver now? [y] "
276: getresp "y"
277: case "$resp" in
278: y*|Y*)
279: cp /tmp/resolv.conf \
280: /tmp/resolv.conf.shadow
281: ;;
282:
283: *)
284: ;;
285: esac
286: fi
287:
288: echo ""
289: echo "The host table is as follows:"
290: echo ""
291: cat /tmp/hosts
292: echo ""
293: echo "You may want to edit the host table in the event that"
294: echo "you need to mount an NFS server."
295: echo -n "Would you like to edit the host table? [n] "
296: getresp "n"
297: case "$resp" in
298: y*|Y*)
1.5 pk 299: ${EDITOR} /tmp/hosts
1.1 pk 300: ;;
301:
302: *)
303: ;;
304: esac
305:
306: cat << \__network_config_2
307:
308: You will now be given the opportunity to escape to the command shell to
309: do any additional network configuration you may need. This may include
310: adding additional routes, if needed. In addition, you might take this
311: opportunity to redo the default route in the event that it failed above.
312: If you do change the default route, and wish for that change to carry over
313: to the installed system, execute the following command at the shell
314: prompt:
315:
316: echo <ip_address_of_gateway> > /tmp/mygate
317:
318: where <ip_address_of_gateway> is the IP address of the default router.
319:
320: __network_config_2
321: echo -n "Escape to shell? [n] "
322: getresp "n"
323: case "$resp" in
324: y*|Y*)
325: echo "Type 'exit' to return to install."
326: sh
327: ;;
328:
329: *)
330: ;;
331: esac
332: ;;
333: *)
334: ;;
335: esac
336:
337: # Now that the network has been configured, it is safe to configure the
338: # fstab.
1.4 pk 339: (
340: while read _dev _mp; do
1.18 pk 341: if [ "$_mp" = "/" ]; then
1.4 pk 342: echo /dev/$_dev $_mp ffs rw 1 1
1.18 pk 343: elif [ "$_mp" = "swap" ]; then
344: echo /dev/$_dev none swap sw 0 0
1.4 pk 345: else
346: echo /dev/$_dev $_mp ffs rw 1 2
347: fi
348: done
349: ) < ${FILESYSTEMS} > /tmp/fstab
1.1 pk 350:
351: echo "The fstab is configured as follows:"
352: echo ""
353: cat /tmp/fstab
354: cat << \__fstab_config_1
355:
356: You may wish to edit the fstab. For example, you may need to resolve
357: dependencies in the order which the filesystems are mounted. You may
358: also wish to take this opportunity to place NFS mounts in the fstab.
359: This would be especially useful if you plan to keep '/usr' on an NFS
360: server.
361:
362: __fstab_config_1
363: echo -n "Edit the fstab? [n] "
364: getresp "n"
365: case "$resp" in
366: y*|Y*)
1.5 pk 367: ${EDITOR} /tmp/fstab
1.1 pk 368: ;;
369:
370: *)
371: ;;
372: esac
373:
374: echo ""
375: munge_fstab /tmp/fstab /tmp/fstab.shadow
376: mount_fs /tmp/fstab.shadow
377:
1.10 pk 378: mount | while read line; do
379: set -- $line
380: if [ "$2" = "/" -a "$3" = "nfs" ]; then
381: echo "You appear to be running diskless."
382: echo -n "Are the install sets on one of your currently mounted filesystems? [n] "
383: getresp "n"
384: case "$resp" in
385: y*|Y*)
386: get_localdir
387: ;;
388: *)
389: ;;
390: esac
391: fi
392: done
393:
1.20 is 394: install_sets
1.1 pk 395:
396: # Copy in configuration information and make devices in target root.
397: (
398: cd /tmp
1.15 pk 399: for file in fstab ifconfig.* hosts myname mygate resolv.conf; do
1.1 pk 400: if [ -f $file ]; then
401: echo -n "Copying $file..."
402: cp $file /mnt/etc/$file
403: echo "done."
404: fi
405: done
1.16 pk 406:
407: # Enable rc.conf
408: if [ -e /mnt/etc/rc.conf ]; then
409: cp /mnt/etc/rc.conf /tmp
410: sed 's/^rc_configured=NO/rc_configured=YES/' /tmp/rc.conf \
411: > /mnt/etc/rc.conf
412: fi
1.1 pk 413:
1.6 leo 414: # If no zoneinfo on the installfs, give them a second chance
415: if [ ! -e /usr/share/zoneinfo ]; then
416: get_timezone
417: fi
418: if [ ! -e /mnt/usr/share/zoneinfo ]; then
419: echo "Cannot install timezone link..."
420: else
421: echo -n "Installing timezone link..."
422: rm -f /mnt/etc/localtime
423: ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
424: echo "done."
425: fi
426: if [ ! -x /mnt/dev/MAKEDEV ]; then
427: echo "No /dev/MAKEDEV installed, something is wrong here..."
428: else
429: echo -n "Making devices..."
430: pid=`twiddle`
431: cd /mnt/dev
432: sh MAKEDEV all
433: kill $pid
434: echo "done."
435: fi
436: md_copy_kernel
1.1 pk 437:
438: md_installboot ${ROOTDISK}
439: )
440:
441: unmount_fs /tmp/fstab.shadow
442:
443: # Pat on the back.
444: md_congrats
445:
446: # ALL DONE!
447: exit 0
CVSweb <webmaster@jp.NetBSD.org>