2 # $NetBSD: install.sh,v 1.24 2008/04/30 13:10:48 martin Exp $
4 # Copyright (c) 1996,1997,1999,2000,2006 The NetBSD Foundation, Inc.
7 # This code is derived from software contributed to The NetBSD Foundation
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
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.
19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
32 # NetBSD installation script.
33 # In a perfect world, this would be a nice C program, with a reasonable
36 FILESYSTEMS
="/tmp/filesystems" # used thoughout
39 trap "umount /tmp > /dev/null 2>&1" 0
43 # include machine-dependent functions
44 # The following functions must be provided:
45 # md_copy_kernel() - copy a kernel to the installed disk
46 # md_get_diskdevs() - return available disk devices
47 # md_get_cddevs() - return available CD-ROM devices
48 # md_get_ifdevs() - return available network interfaces
49 # md_get_partition_range() - return range of valid partition letters
50 # md_installboot() - install boot-blocks on disk
51 # md_labeldisk() - put label on a disk
52 # md_prep_disklabel() - label the root disk
53 # md_welcome_banner() - display friendly message
54 # md_not_going_to_install() - display friendly message
55 # md_congrats() - display friendly message
56 # md_native_fstype() - native filesystem type for disk installs
57 # md_native_fsopts() - native filesystem options for disk installs
58 # md_makerootwritable() - make root writable (at least /tmp)
60 # The following are optional:
61 # md_view_labels_possible - variable: md_view_labels defined
62 # md_view_labels - peek at preexisting disk labels, to
63 # better identify disks
65 # we need to make sure .'s below work if this directory is not in $PATH
66 # dirname may not be available but expr is
67 Mydir
=`expr $0 : '^\(.*\)/[^/]*$'`
68 Mydir
=`cd ${Mydir:-.}; pwd`
70 # this is the most likely place to find the binary sets
71 # so save them having to type it in
72 Default_sets_dir
=$Mydir/..
/..
/binary
/sets
74 # include machine dependent subroutines
77 # include common subroutines
81 THESETS
="$ALLSETS $MDSETS"
83 # Good {morning,afternoon,evening,night}.
85 echo -n "Proceed with installation? [n] "
89 echo "Cool! Let's get to it..."
92 md_not_going_to_install
97 # XXX Work around vnode aliasing bug (thanks for the tip, Chris...)
98 ls -l /dev
> /dev
/null
2>&1
100 # Deal with terminal issues
106 # Make sure we can write files (at least in /tmp)
107 # This might make an MFS mount on /tmp, or it may
108 # just re-mount the root with read-write enabled.
111 # Create a disktab file; lets us write to it for temporary
112 # purposes without mounting the miniroot read-write.
113 echo "# disktab" > /tmp
/disktab.shadow
115 test "$md_view_labels_possible" && md_view_labels
117 while [ "X${ROOTDISK}" = "X" ]; do
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}
126 # Assume partition 'a' of $ROOTDISK is for the root filesystem. Loop and
128 # XXX ASSUMES THAT THE USER DOESN'T PROVIDE BOGUS INPUT.
129 cat << \__get_filesystems_1
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
).
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.
142 echo "The following will be used for the root filesystem:"
143 echo " ${ROOTDISK}a /"
145 echo "${ROOTDISK}a /" > ${FILESYSTEMS}
147 resp
="X" # force at least one iteration
148 while [ "X$resp" != X
"done" ]; do
150 echo -n "Device name? [RETURN if you already entered all devices] "
157 _device_name
=`basename $resp`
159 # force at least one iteration
161 while [ "X${_first_char}" != X
"/" ]; do
162 echo -n "Mount point? "
165 if [ "X${_mount_point}" = X
"/" ]; then
166 # Invalid response; no multiple roots
169 _first_char
=`firstchar ${_mount_point}`
172 echo "${_device_name} ${_mount_point}" >> ${FILESYSTEMS}
173 resp="X
" # force loop to repeat
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?
[] "
185 echo "${ROOTDISK}b swap
" >> ${FILESYSTEMS}
195 echo "You have configured the following devices and mount points
:"
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
] "
204 ${EDITOR} ${FILESYSTEMS}
210 # Loop though the file, place filesystems on each device.
211 echo "Creating filesystems...
"
213 while read _device_name _mp; do
214 if [ "$_mp" != "swap
" ]; then
215 newfs /dev/r${_device_name}
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.
229 Note, enter all symbolic host names WITHOUT the domain name appended.
230 I.e. use 'hostname' NOT 'hostname.domain.name'.
233 echo -n "Configure the network?
[y
] "
237 resp="" # force at least one iteration
238 if [ -f /etc/myname ]; then
239 resp=`cat /etc/myname`
241 echo -n "Enter system hostname
: [$resp] "
242 while [ "X
${resp}" = X"" ]; do
246 echo $resp > /tmp/myname
248 echo -n "Enter DNS domain name
: "
250 if [ "X
${resp}" != X"none
" ]; then
256 echo -n "Enter IP address of default route
: [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
266 if [ X${FQDN} != X ]; then
267 echo -n "Enter IP address of primary nameserver
: [none
] "
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
275 echo -n "Would you like to use the nameserver now?
[y
] "
279 cp /tmp/resolv.conf \
280 /tmp/resolv.conf.shadow
289 echo "The
host table is as follows
:"
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
] "
306 cat << \__network_config_2
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
316 echo <ip_address_of_gateway> > /tmp/mygate
318 where <ip_address_of_gateway> is the IP address of the default router.
321 echo -n "Escape to shell?
[n
] "
325 echo "Type
'exit' to
return to
install.
"
337 # Now that the network has been configured, it is safe to configure the
340 while read _dev _mp; do
341 if [ "$_mp" = "/" ]; then
342 echo /dev/$_dev $_mp ffs rw 1 1
343 elif [ "$_mp" = "swap
" ]; then
344 echo /dev/$_dev none swap sw 0 0
346 echo /dev/$_dev $_mp ffs rw 1 2
349 ) < ${FILESYSTEMS} > /tmp/fstab
351 echo "The fstab is configured as follows
:"
354 cat << \__fstab_config_1
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
363 echo -n "Edit the fstab?
[n
] "
375 munge_fstab /tmp/fstab /tmp/fstab.shadow
376 mount_fs /tmp/fstab.shadow
378 mount | while read line; do
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
] "
396 # Copy in configuration information and make devices in target root.
399 for file in fstab ifconfig.* hosts myname mygate resolv.conf; do
400 if [ -f $file ]; then
401 echo -n "Copying
$file...
"
402 cp $file /mnt/etc/$file
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 \
414 # If no zoneinfo on the installfs, give them a second chance
415 if [ ! -e /usr/share/zoneinfo ]; then
418 if [ ! -e /mnt/usr/share/zoneinfo ]; then
419 echo "Cannot
install timezone link...
"
421 echo -n "Installing timezone link...
"
422 rm -f /mnt/etc/localtime
423 ln -s /usr/share/zoneinfo/$TZ /mnt/etc/localtime
426 if [ ! -x /mnt/dev/MAKEDEV ]; then
427 echo "No
/dev
/MAKEDEV installed
, something is wrong here...
"
429 echo -n "Making devices...
"
438 md_installboot ${ROOTDISK}
441 unmount_fs /tmp/fstab.shadow