install.md revision 1.20 1 # $NetBSD: install.md,v 1.20 2006/02/07 16:52:16 chs Exp $
2 #
3 #
4 # Copyright (c) 1996 The NetBSD Foundation, Inc.
5 # All rights reserved.
6 #
7 # This code is derived from software contributed to The NetBSD Foundation
8 # by Jason R. Thorpe.
9 #
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:
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.
25 #
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
29 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
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.
37 #
38
39 #
40 # machine dependent section of installation/upgrade script.
41 #
42
43 # Machine-dependent install sets
44 MDSETS="kern xbase xcomp xfont xserver"
45
46 if [ "$MODE" = upgrade ]; then
47 RELOCATED_FILES_13="${RELOCATED_FILES_13} /usr/sbin/installboot /usr/mdec/installboot"
48 fi
49
50 md_set_term() {
51 if [ ! -z "$TERM" ]; then
52 return
53 fi
54 echo -n "Specify terminal type [sun]: "
55 getresp "sun"
56 TERM="$resp"
57 export TERM
58 }
59
60 md_makerootwritable() {
61 # Was: do_mfs_mount "/tmp" "2048"
62 # /tmp is the mount point
63 # 2048 is the size in DEV_BIZE blocks
64
65 umount /tmp > /dev/null 2>&1
66 if ! mount_mfs -s 2048 swap /tmp ; then
67 cat << \__mfs_failed_1
68
69 FATAL ERROR: Can't mount the memory filesystem.
70
71 __mfs_failed_1
72 exit
73 fi
74
75 # Bleh. Give mount_mfs a chance to DTRT.
76 sleep 2
77 }
78
79 md_get_diskdevs() {
80 # return available disk devices
81 dmesg | sed -n -e 's/^\(sd[0-9]\) .*/\1/p' -e 's/^\(x[dy][0-9]\) .*/\1/p' | sort -u
82 }
83
84 md_get_cddevs() {
85 # return available CDROM devices
86 dmesg | sed -n -e 's/^\(cd[0-9]\) .*/\1/p' | sort -u
87 }
88
89 md_get_ifdevs() {
90 # return available network devices
91 dmesg | sed -n -e 's/^\(le[0-9]\) .*/\1/p' -e 's/^\(ie[0-9]\) .*/\1/p' | sort -u
92 }
93
94 md_get_partition_range() {
95 # return range of valid partition letters
96 echo "[a-h]"
97 }
98
99 md_installboot() {
100 # $1 is the boot disk
101 echo "Installing boot block..."
102 cp -p /usr/mdec/boot /mnt/boot
103 /usr/sbin/installboot -v /dev/r${1}a /usr/mdec/bootxx /boot
104 }
105
106 md_native_fstype() {
107 }
108
109 md_native_fsopts() {
110 }
111
112 md_checkfordisklabel() {
113 # $1 is the disk to check
114 local rval
115 local cfdl
116
117 cfdl=`disklabel $1 2>&1 > /dev/null | \
118 sed -n -e '/no disk label/{s/.*/ndl/p;q;}; \
119 /disk label corrupted/{s/.*/dlc/p;q;}; \
120 $s/.*/no/p'`
121 if [ x$cfdl = xndl ]; then
122 rval=1
123 elif [ x$cfdl = xdlc ]; then
124 rval=2
125 else
126 rval=0
127 fi
128
129 return $rval
130 }
131
132 md_prep_disklabel()
133 {
134 local _disk
135
136 _disk=$1
137 md_checkfordisklabel $_disk
138 case $? in
139 0)
140 echo -n "Do you wish to edit the disklabel on $_disk? [y]"
141 ;;
142 1)
143 echo "WARNING: Disk $_disk has no label"
144 echo -n "Do you want to create one with the disklabel editor? [y]"
145 ;;
146 2)
147 echo "WARNING: Label on disk $_disk is corrupted"
148 echo -n "Do you want to try and repair the damage using the disklabel editor? [y]"
149 ;;
150 esac
151
152 getresp "y"
153 case "$resp" in
154 y*|Y*) ;;
155 *) return ;;
156 esac
157
158 # display example
159 cat << \__md_prep_disklabel_1
160
161 Here is an example of what the partition information will look like once
162 you have entered the disklabel editor. Disk partition sizes and offsets
163 are in sector (most likely 512 bytes) units. Make sure these size/offset
164 pairs are on cylinder boundaries (the number of sector per cylinder is
165 given in the `sectors/cylinder' entry, which is not shown here).
166
167 Do not change any parameters except the partition layout and the label name.
168 It's probably also wisest not to touch the `8 partitions:' line, even
169 in case you have defined less than eight partitions.
170
171 [Example]
172 8 partitions:
173 # size offset fstype [fsize bsize cpg]
174 a: 50176 0 4.2BSD 1024 8192 16 # (Cyl. 0 - 111)
175 b: 64512 50176 swap # (Cyl. 112 - 255)
176 c: 640192 0 unknown # (Cyl. 0 - 1428)
177 d: 525504 114688 4.2BSD 1024 8192 16 # (Cyl. 256 - 1428)
178 [End of example]
179
180 __md_prep_disklabel_1
181 echo -n "Press [Enter] to continue "
182 getresp ""
183 disklabel -W ${_disk}
184 if [ -f /usr/bin/vi ]; then
185 disklabel -e ${_disk}
186 else
187 disklabel -i ${_disk}
188 fi
189 }
190
191 md_copy_kernel() {
192 if [ ! -f /mnt/netbsd ]; then
193 echo -n "WARNING: No kernel installed; "
194 if [ -f /netbsd ]; then
195 echo -n "copying miniroot kernel... "
196 cp -p /netbsd /mnt/netbsd
197 echo "done."
198 else
199 echo -n "install a kernel manually."
200 fi
201 fi
202 }
203
204 md_welcome_banner() {
205 {
206 if [ "$MODE" = "install" ]; then
207 echo ""
208 echo "Welcome to the NetBSD/sparc ${VERSION} installation program."
209 cat << \__welcome_banner_1
210
211 This program is designed to help you put NetBSD on your disk,
212 in a simple and rational way. You'll be asked several questions,
213 and it would probably be useful to have your disk's hardware
214 manual, the installation notes, and a calculator handy.
215 __welcome_banner_1
216
217 else
218 echo ""
219 echo "Welcome to the NetBSD/sparc ${VERSION} upgrade program."
220 cat << \__welcome_banner_2
221
222 This program is designed to help you upgrade your NetBSD system in a
223 simple and rational way.
224
225 As a reminder, installing the `etc' binary set is NOT recommended.
226 Once the rest of your system has been upgraded, you should manually
227 merge any changes to files in the `etc' set into those files which
228 already exist on your system.
229 __welcome_banner_2
230 fi
231
232 cat << \__welcome_banner_3
233
234 As with anything which modifies your disk's contents, this
235 program can cause SIGNIFICANT data loss, and you are advised
236 to make sure your data is backed up before beginning the
237 installation process.
238
239 Default answers are displayed in brackets after the questions.
240 You can hit Control-C at any time to quit, but if you do so at a
241 prompt, you may have to hit return. Also, quitting in the middle of
242 installation may leave your system in an inconsistent state.
243
244 __welcome_banner_3
245 } | more
246 }
247
248 md_not_going_to_install() {
249 cat << \__not_going_to_install_1
250
251 OK, then. Enter `halt' at the prompt to halt the machine. Once the
252 machine has halted, power-cycle the system to load new boot code.
253
254 __not_going_to_install_1
255 }
256
257 md_congrats() {
258 local what;
259 if [ "$MODE" = "install" ]; then
260 what="installed";
261 else
262 what="upgraded";
263 fi
264 cat << __congratulations_1
265
266 CONGRATULATIONS! You have successfully $what NetBSD!
267 To boot the installed system, enter halt at the command prompt. Once the
268 system has halted, reset the machine and boot from the disk.
269
270 __congratulations_1
271 }
272
273 md_lib_is_aout() {
274 local r
275 test -h $1 && return 1
276 test -f $1 || return 1
277
278 [ "`dd if=$1 bs=1 skip=1 count=3 2> /dev/null`" = "ELF" ] && return 1
279 return 0
280 }
281
282
283 md_mv_usr_lib() {
284 local root
285 root=$1
286 for f in $root/usr/lib/lib*.so.[0-9]*.[0-9]* ; do
287 md_lib_is_aout $f || continue
288 mv -f $f $root/emul/aout/usr/lib || return 1
289 done
290 return 0
291 }
292
293 md_x_shlib_set_14=" \
294 libICE.so.6.3 \
295 libPEX5.so.6.0 \
296 libSM.so.6.0 \
297 libX11.so.6.1 \
298 libXIE.so.6.0 \
299 libXaw.so.6.1 \
300 libXext.so.6.3 \
301 libXi.so.6.0 \
302 libXmu.so.6.0 \
303 libXp.so.6.2 \
304 libXt.so.6.0 \
305 libXtst.so.6.1 \
306 liboldX.so.6.0"
307
308 md_mv_x_lib() {
309 local root xlibdir
310 root=$1
311 xlibdir=$2
312 for f in $md_x_shlib_set_14; do
313 md_lib_is_aout $root/$xlibdir/$f || continue
314 mv -f $root/$xlibdir/$f $root/emul/aout/$xlibdir || return 1
315 done
316 return 0
317 }
318
319 md_mv_aout_libs()
320 {
321 local root xlibdir
322
323 root=/mnt # XXX - should be global
324
325 if [ -d $root/emul/aout/. ]; then
326 echo "Using existing /emul/aout directory"
327 else
328 echo "Creating /emul/aout hierachy"
329 mkdir -p $root/usr/aout || return 1
330
331 if [ ! -d $root/emul ]; then
332 mkdir $root/emul || return 1
333 fi
334
335 if [ -h $root/emul/aout ]; then
336 echo "Preserving existing symbolic link from /emul/aout"
337 mv -f $root/emul/aout $root/emul/aout.old || return 1
338 fi
339
340 ln -s ../usr/aout $root/emul/aout || return 1
341 fi
342
343 # Create /emul/aout/etc and /emul/aout/usr/lib
344 if [ ! -d $root/emul/aout/etc ]; then
345 mkdir $root/emul/aout/etc || return 1
346 fi
347 if [ ! -d $root/emul/aout/usr/lib ]; then
348 mkdir -p $root/emul/aout/usr/lib || return 1
349 fi
350
351 # Move ld.so.conf
352 if [ -f $root/etc/ld.so.conf ]; then
353 mv -f $root/etc/ld.so.conf $root/emul/aout/etc || return 1
354 fi
355
356 # Finally, move the aout shared libraries from /usr/lib
357 md_mv_usr_lib $root || return 1
358
359 # If X11 is installed, move the those libraries as well
360 xlibdir="/usr/X11R6/lib"
361 if [ -d $root/$xlibdir/. ]; then
362 mkdir -p $root/emul/aout/$xlibdir || return 1
363 md_mv_x_lib $root $xlibdir || return 1
364 fi
365
366 echo "a.out emulation environment setup completed."
367 }
368
369 md_prepare_upgrade()
370 {
371 cat << 'EOF'
372 This release uses the ELF binary object format. Existing (a.out) binaries
373 can still be used on your system after it has been upgraded, provided
374 that the shared libraries needed by those binaries are made available
375 in the filesystem hierarchy rooted at /emul/aout.
376
377 This upgrade procedure will now establish this hierarchy by moving all
378 shared libraries in a.out format found in /usr/lib to /emul/aout/usr/lib.
379 It will also move the X11 shared libraries in a.out format from previous
380 NetBSD/sparc X11 installation sets, if they are installed.
381
382 EOF
383 md_mv_aout_libs || {
384 echo "Failed to setup a.out emulation environment"
385 return 1
386 }
387 return 0
388 }
389
390 # Flag to notify upgrade.sh of the existence of md_prepare_upgrade()
391 md_upgrade_prep_needed=1
392